terraform-aws-modules / terraform-aws-s3-bucket

Terraform module to create AWS S3 resources 🇺🇦

Home Page:https://registry.terraform.io/modules/terraform-aws-modules/s3-bucket/aws

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to set versioning to "Disabled"

tadejsv opened this issue · comments

This is a copy of #196, which was closed automatically. @antonbabenko


Same issue as in #61.

For some reason, this module prevents me from setting bucket versioning to "Disabled"

# Valid values: "Enabled" or "Suspended"
status = try(var.versioning["enabled"] ? "Enabled" : "Suspended", tobool(var.versioning["status"]) ? "Enabled" : "Suspended", title(lower(var.versioning["status"])))

Even though that is a valid value for the versioning configuration, see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_versioning#status

I agree this seems like unusual behavior to write into the module, but I see where @antonbabenko was coming from. It looks like if you simply do not provide a value for the versioning variable, the aws_s3_bucket_versioning resource will not be created. In that case, a brand new bucket will effectively be versioning=disabled.

As @bryantbiggs has mentioned, once you set a value (Enabled or Suspended), you can't go back to Disabled. So the current logic in this module attempts to avoid an invalid configuration: Create a bucket with versioning=Enabled, then change it to Disabled will cause an error on apply.

I agree with @jgard and I don't think that we can do anything about it in the module. This is mirroring the behavior of AWS API as described in the Terraform docs versioning_configuration.

I'm going to lock this issue because it has been closed for 30 days . This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.