parsers

package module
v1.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2023 License: MPL-2.0 Imports: 9 Imported by: 1

README

snyk-iac-parsers


CircleCI Regression Tests

Latest release version Latest release date

Golang Version

This project includes parsers that are used for Snyk Infrastructure As Code product. Parsers convert the files they take as input into JSON.

Supported formats

The following file formats are supported:

  • HCL2: Terraform's default configuration format, parser's source can be found here.
  • Terraform Plan(JSON): Terraform plan output in json is parsed and resource_changes element is extracted. Parser's source can be found here.
  • YAML: Parser's source can be found here.

All the formats above are transformed into JSON so that they can be used as input into tools such as Open Policy Agent.

Development

Tests can be run using the go test command:

% go test ./...

Before committing code should be formatted with go fmt and linted with golangci-lint run. The CircleCI runner will enforce this for each opened pull request.

Contributing

This project is developed in open as a dependency of the snyk/snyk-iac-rules project. Should you wish to make a contribution please open a pull request against this repository with a clear description of the change with tests demonstrating the functionality. You will also need to agree to the Contributor Agreement before the code can be accepted and merged.

License

Available under the Mozilla Public License 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseHCL2

func ParseHCL2(p []byte, v interface{}) (err error)

ParseHCL2 unmarshals HCL files that are written using version 2 of the HCL language and return parsed file content.

func ParseTerraformPlan

func ParseTerraformPlan(p []byte, v *interface{}) error

func ParseYAML

func ParseYAML(p []byte, v interface{}) error

ParseYAML unmarshals YAML files and return parsed file content.

Types

type ResourceActions

type ResourceActions []string

type TerraformPlanConfiguration added in v0.5.0

type TerraformPlanConfiguration struct {
	RootModule TerraformPlanModule `json:"root_module"`
}

type TerraformPlanJson

type TerraformPlanJson struct {
	ResourceChanges []TerraformPlanResourceChange `json:"resource_changes"`
	Configuration   TerraformPlanConfiguration    `json:"configuration"`
}

type TerraformPlanModule added in v0.5.0

type TerraformPlanModule struct {
	Resources []TerraformPlanResourceChange `json:"resources"`
}

type TerraformPlanResource

type TerraformPlanResource struct {
	Address string      // "aws_cloudwatch_log_group.terra_ci",
	Mode    string      // "managed",
	Type    string      // "aws_cloudwatch_log_group",
	Name    string      // "terra_ci",
	Index   interface{} // Can be either an integer or a string (e.g. 1, "10.0.101.0/24", "rtb-00cf8381520103cfb")
}

type TerraformPlanResourceChange

type TerraformPlanResourceChange struct {
	TerraformPlanResource
	Change struct {
		Actions ResourceActions
		Before  map[string]interface{} // will be null when the action is `create`
		After   map[string]interface{} // will be null when then action is `delete`
	}
	Expressions interface{} `json:"expressions"`
}

type TerraformScanInput

type TerraformScanInput map[string]map[string]map[string]interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL