Documentation
¶
Overview ¶
A package that will parse a Terraform plan file and execute a set of functions against the underlying resources that can be used to gate or control how Terraform resources are being provisioned into your environment.
This package can be utilized to build your own infrastructure scanning rules with the ability to leverage the capabilities of a full language instead of being limited by Domain Specific Languages (DSLs).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( Severity = struct { Minor string Major string Critical string }{ Minor: "Minor", Major: "Major", Critical: "Critical", } )
Some default values for Severities that can be easily leveraged if desired, if not, users can provide their own severity values/structures based on their own needs.
Functions ¶
This section is empty.
Types ¶
type Deployment ¶
type Deployment struct {
PlanFile string
ModulesFile string
Resources []tfresources.Resource
Rules []Rule
Results []Result
ResultsStdOut string
ResultsJson []byte
DisableStdOut bool
Debug bool
Logger *logrus.Logger
}
A Deployment contains all the relevant attributes for a given Terraform plan execution. It contains references to Plan and Modules files, as well as the list of Rules to be evaluated against each resource, as lastly the results of the evaluation both in string-based StdOut format and JSON (to alloow for programmatic parsing).
func (*Deployment) Scan ¶
func (d *Deployment) Scan()
The primary Scan function intakes the specified Plan and Modules file paths and utilizes the tfresources project to parse out the underlying Terraform resources and link them to any declared modules.
Once parsed, the resources are fed into the rule engine to begin the execution of each rule onto each resource and the results aggregated into StdOut and JSON formatting.
Debug logging can be enabled if desired to assist with writing Rules. Additionall the default StdOut text can be disabled if using the JSON output for programmatic control over the results.
type Result ¶
type Result struct {
Name string
Valid bool
Severity string
Resource tfresources.Resource
NotApplicable bool
}
Result is a data structure used to hold the evaluation results for a Rule (as defined above). A Rule type function must return a valid Result.
type Rule ¶
type Rule func(tfresources.Resource) Result
A Rule function definition - this function type must be satisfied in order for it to be executed against the planned resources.
The input is a Resource type that extends the terraform-json project's StateResource struct by linking any resources created from modules back to their parent and children addresses. The output is a Result struct as defined below.
Check out the [terraform-json](https://github.com/hashicorp/terraform-json/blob/main/state.go#L124) project for more details on how you can access different resource values.