Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run terraform-compliance for only new (create) resources, via an additional -new CLI filter ? #408

Closed
mdesmarest opened this issue Nov 9, 2020 · 7 comments

Comments

@mdesmarest
Copy link

Feature Request

The ability to flag within the resource_changes block for resources, the same way we can interact with specific values for address, module address ,etc in the actual resource block. The ability to conditionally flag on create vs update allows for flagging on new infrastructure being created to be flagged for non use of a module, while ignoring updates to existing resources that were created previous to a module's creation or use.

We are in the midst of standardizing our configurations and directing our devs to use modules, since these will help enforce the same best practices we are flagging for in features. For a Feature or Scenario to flag on Given this, When this, Then that we can't flag on existing resources that may come into the plan as update for say a tag, but then fail a feature because we are trying to advise users to create all s3 resources using our module since using the module on already created resources is not feasible due to state files already mapping resources.

we also can't restrict s3 resources by saying Given aws_s3_bucket defined, Then the scenario should fail use the module please.

This is a feature in hashicorp Sentinel and we were advised that this is a must have if we are to flag for module use while not flagging infrastructure created pre module

We need a way to account for the Terraform json block for resource_changes below to screen for what is being created vs updated.

Block below:

"resource_changes":[
{},
{},
{},
{
"address":"aws_s3_bucket.missing_Server_side_encryption_apply_sever_side",
"mode":"managed",
"type":"aws_s3_bucket",
"name":"missing_Server_side_encryption_apply_sever_side",
"provider_name":"aws",
"change":{
"actions":[
"create"
],
"before":null,
"after":{},
"after_unknown":{}
}
},
{
"address":"aws_s3_bucket.pagerduty_s3",
"mode":"managed",
"type":"aws_s3_bucket",
"name":"pagerduty_s3",
"provider_name":"aws",
"change":{
"actions":[
"update"
],
@mdesmarest mdesmarest changed the title Filter on "resource_changes" change.actions for "create" or "update" Run terraform-compliance for only new (create) resources, via an additional -new CLI filter running alternate modify extensions/terraform.py ? Nov 17, 2020
@mdesmarest mdesmarest changed the title Run terraform-compliance for only new (create) resources, via an additional -new CLI filter running alternate modify extensions/terraform.py ? Run terraform-compliance for only new (create) resources, via an additional -new CLI filter ? Nov 17, 2020
@mdesmarest
Copy link
Author

additionally, there are certain tests we would want to run on resources that are labeled as create since those can be fixed within the terraform code itself and then replanned to pass for deployment, also run certain features/scenarios on update and ignore resources that are in the state but not seeing new changes. The flexibility to run only on create lets us fix 100% of the compliance issues we are looking for. many of our features would not apply to resources that are update since flagging and resolving via plan/apply is problematic. Essentially we are looking to "stop the bleeding" and prevent new non compliant configurations, while we address the existing infrastructure in a safe manner. Many times this will be outside of terraform and will be adjusted via CLI/console, for import to state later.

We love the tool but it is hard to deploy to prevent, when many of the same compliance violations already exist

@Kudbettin
Copy link
Member

Kudbettin commented Jan 15, 2021

Hi @mdesmarest,

This's an excellent feature request! I have built a preliminary solution on #447.
What do you think about it? Does that help with issues on integrating terraform-compliance?

I'm sorry this took months to look into :)

@mdesmarest
Copy link
Author

mdesmarest commented Jan 15, 2021 via email

@mdesmarest
Copy link
Author

@Kudbettin Thanks so much!!! This looks exactly like what we were looking for as well as opening up the metadata to a lot more filters and flags.

I can't wait to spin this up and try it out! Looking forward to the merge 🤞

Looking through the code this will be very helpful on our Atlantis PR scans for the reasons below, as well as open us up to create our state based compliance engine for long term cleanup of compliance failures on already existing resources

1.Filter tuned features that apply to full fixes for create action
2.Create secondary features to flag on same resource type but only for update that do not cause resource destruction
3.Tune down noise on resources that are no-op since on PR it creates difficulty having a feature flag on a resource that was not changed, and inhibits protected branch enforcement.
4. This also now allows us to enforce module use, since moving forward we are enforcing modules on certain resource types and need to account for resources created before the inception of the module while also preventing new resources to be created without the module.

@Kudbettin
Copy link
Member

Awesome! Glad this’s useful.

It seems you will have a number of interesting and creative use cases of terraform-compliance. If you would like to share any of those with the community, we recently released this repository to document some use cases.

As always, feel absolutely free to open issues if something comes up.

@eerkunt
Copy link
Member

eerkunt commented Jan 18, 2021

@mdesmarest just released 1.3.12 :)

@mdesmarest
Copy link
Author

mdesmarest commented Jan 18, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants