Get started with Snyk IaC Describe on AWS
The
snyk iac describe
command requires authentication to your cloud provider in order to run properly. It requires only the lowest read-only access rights possible. You can use use the built-in AWS "ReadOnlyAccess" IAM policy for that IAM user as a good default to get started.snyk iac describe
can reuse standard authentication methods for AWS, like the AWS_ACCESS_KEY_ID
, AWS_SECRET_ACCESS_KEY
, and AWS_REGION
environment variables. When those are set, the Snyk CLI will automatically pick them up to authenticate on AWS.Another option is to configure the AWS profile in
~/.aws/credentials
and use the AWS_PROFILE
environment variable.Snyk IaC can report two types of drifted resources: managed and unmanaged.
- Unmanaged resources - resources that are present on your cloud provider but not on your Terraform state. You probably want to import those resources into Terraform, or delete them from your IaaS account.
- Managed resources - identified resources from your infrastructure that are listed both in your Terraform state and on your cloud provider.
To understand the drift that happens in your cloud environment, compare the state of your environment to one or multiple Terraform state file(s) (
.tfstate
).The state file can be located locally or in an S3 bucket. Terraform Cloud is also available, but out of scope for this getting started document.
The
--from
option helps Snyk to determine the path of the .tfstate
file.For a single local Terraform state file use the command:
$ snyk iac describe --from="tfstate://path/to/terraform.tfstate" --only-unmanaged
To load all the Terraform states found in a given directory automatically, you can use glob patterns like this:
$ snyk iac describe --from="tfstate://path/to/**/*.tfstate" --only-unmanaged
For a single Terraform state stored on an S3 backend:
$ snyk iac describe --from="tfstate+s3://my-bucket/path/to/state.tfstate" --only-unmanaged
You can also aggregate multiple Terraform state files by listing them in the
--from
option. You can scan your local directory for different files, or use different paths from different sources. To choose two specific Terraform states, execute the following:$ snyk iac describe --from="tfstate://path/to/terraform_S3.tfstate,tfstate://path/to/terraform_VPC.tfstate" --only-unmanaged
You ran
snyk iac describe
once and got a report of the current IaC coverage of your cloud infrastructure. When you are done fixing all the issues you identified and are left with known differences you are not planning to change, you can create a baseline so those differences will not be displayed in your next scan.There are two options: ignore a specific resource or ignore multiple resources.
Ignore multiple resources
Use the output of the
describe
command and extract its results to update the .snyk excluded policies:$ snyk iac describe --json --all | snyk iac update-exclude-policy
Ignore a specific resource
To ignore a specific resource, you must exclude it manually by editing the
.snyk
file and adding the resource details to the exclude
list. For more information, see Ignore resources.You are now ready to add
snyk iac describe
as a recurring cronjob to get alerts when a new resource is created or modified outside of your IaC deployment.Last modified 3mo ago