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

S3 buckets created with versioning #76

Closed
imunhatep opened this issue Feb 16, 2021 · 10 comments
Closed

S3 buckets created with versioning #76

imunhatep opened this issue Feb 16, 2021 · 10 comments
Labels
bug 🐛 An issue with the system

Comments

@imunhatep
Copy link

imunhatep commented Feb 16, 2021

Describe the Bug

It's related to aws_s3_bucket resource bug or feature: hashicorp/terraform-provider-aws#4494

In short setting versioning to false, actually creates versioned bucket with suspended versioning:

resource "aws_s3_bucket" "default" {
  versioning {
    enabled = false 
  }
 ...
}

Expected Behavior

Bucket with versioning actually disabled

Steps to Reproduce

Try to create unversioned bucket

@imunhatep imunhatep added the bug 🐛 An issue with the system label Feb 16, 2021
@imunhatep
Copy link
Author

imunhatep commented Feb 16, 2021

Correct me if i'm wrong, but it gets worse with disabled lifecycle rules, as now we get an ever growing bucket, as delete object request actually do not delete objects for buckets with suspended versioning.

@grimm26
Copy link

grimm26 commented Oct 5, 2021

@ekristen
Copy link

ekristen commented Nov 4, 2021

This is a pretty nasty bug, any chance of getting a fix anytime soon?

@nnsense
Copy link
Contributor

nnsense commented Nov 12, 2021

I did some testing and it seems that this isn't related the module, but it's related terraform and what versioning attribute means into that module.

Apparently, versioning is a setting on its own, regardless of its value (which is what we can set with a var), just mention it, it will turn on versioning, leaving it in suspended mode, it's equivalent to setting enabled = false.

  versioning {}

This will turn it on and enable:

  versioning {
    enabled = true
  }

I really don't know how this can be sorted out, if just by mentioning an attribute will enable it (suspended), the only thing to do would be to remove it entirely based on a variable, but I'm not aware that's possible in terraform

@aknysh
Copy link
Member

aknysh commented Nov 12, 2021

dynamic "versioning" {
    for_each = var.versioning_enabled ? [true] : []
    content {
      enabled = true
    }
  }

https://www.terraform.io/docs/language/expressions/dynamic-blocks.html

@nnsense ^

@nnsense
Copy link
Contributor

nnsense commented Nov 12, 2021

Hey, that worked! Why you didn't add it into the module? If you don't have time I can create a PR :)

@nnsense
Copy link
Contributor

nnsense commented Nov 12, 2021

...there's already a PR.. Open from February.. :'(

@aknysh
Copy link
Member

aknysh commented Nov 12, 2021

@nnsense the PR is very old and convoluted.
Please open a new PR with just this feature

@nnsense
Copy link
Contributor

nnsense commented Nov 12, 2021

I'm doing just that :) Question: there's a comment:

#bridgecrew:skip=BC_AWS_S3_16:Skipping `Ensure S3 bucket versioning is enabled` because dynamic blocks are not supported by checkov

But now I see that some basic handling for dynamic blocks has been added in checkov
bridgecrewio/checkov#836

So if you're using checkov it would be interesting to remove the comment and see if it works now

@korenyoni
Copy link
Member

Closing this because #118 is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue with the system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants