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

aws_s3_bucket: lifecycle_rule and count does not work #1402

Closed
joscha opened this issue Aug 14, 2017 · 3 comments
Closed

aws_s3_bucket: lifecycle_rule and count does not work #1402

joscha opened this issue Aug 14, 2017 · 3 comments
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/s3 Issues and PRs that pertain to the s3 service.

Comments

@joscha
Copy link
Contributor

joscha commented Aug 14, 2017

Terraform Version

terraform -v
Terraform v0.10.0

Affected Resource(s)

  • aws_s3_bucket (lifecycle_rule option)

Terraform Configuration Files

variable "lifecycled_prefixes" {
    default = ["a", "b", "c"]
}

resource "aws_s3_bucket" "bucket" {
  bucket = "foo"

  lifecycle_rule {
    count = "${length(var.lifecycled_prefixes)}"
    prefix = "${element(var.lifecycled_prefixes, count.index)}/"
    enabled = true

    expiration {
      days = 10
    }
  }
}

Debug Output

https://gist.github.com/joscha/a18add0d7b1b0fad265e96ded20bf927

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

Expected Behavior

An S3 bucked with three lifecycle_rule parts of a, b, c should have been planned.

Actual Behavior

1 error(s) occurred:

* aws_s3_bucket.bucket: lifecycle_rule.0: invalid or unknown key: count

Steps to Reproduce

  1. terraform plan

References

Potentially hashicorp/terraform#3116, however it is not about the S3 bucket resource.

@radeksimko radeksimko added the question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. label Oct 23, 2017
@radeksimko radeksimko added the service/s3 Issues and PRs that pertain to the s3 service. label Jan 28, 2018
@mildwonkey mildwonkey added the enhancement Requests to existing resources that expand the functionality or scope. label Jun 21, 2018
@mildwonkey
Copy link
Contributor

At this point in time, lifecycle_rule still does not support count.
I've updated the tag on this ticket to indicate that it is a feature request.

@bflad bflad added terraform-0.12 and removed question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. labels Sep 12, 2018
@bflad
Copy link
Contributor

bflad commented Jul 24, 2019

Hi folks 👋 This issue is resolved in Terraform 0.12, which supports new functionality in the configuration language aimed at solving this issue. The new dynamic block syntax can be used to dynamically generate configuration blocks and their arguments.

Given this configuration:

terraform {
  required_providers {
    aws = "2.20.0"
  }
  required_version = "0.12.5"
}

provider "aws" {
  region = "us-east-1"
}

resource "aws_s3_bucket" "test" {
  bucket = "tf-dynamic-test-1402"

  dynamic "lifecycle_rule" {
    # The for_each argument is a hardcoded list in this illustrative example,
    # however it can be sourced from a variable or local value as well as
    # support multiple argument values as a map.
    for_each = ["a", "b", "c"]

    content {
      enabled = true
      id      = lifecycle_rule.value
      prefix  = "${lifecycle_rule.value}/"

      expiration {
        days = 10
      }
    }
  }
}

Produces the following apply output:

$ terraform apply

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_s3_bucket.test will be created
  + resource "aws_s3_bucket" "test" {
      + acceleration_status         = (known after apply)
      + acl                         = "private"
      + arn                         = (known after apply)
      + bucket                      = "tf-dynamic-test-1402"
      + bucket_domain_name          = (known after apply)
      + bucket_regional_domain_name = (known after apply)
      + force_destroy               = false
      + hosted_zone_id              = (known after apply)
      + id                          = (known after apply)
      + region                      = (known after apply)
      + request_payer               = (known after apply)
      + website_domain              = (known after apply)
      + website_endpoint            = (known after apply)

      + lifecycle_rule {
          + enabled = true
          + id      = "a"
          + prefix  = "a/"

          + expiration {
              + days = 10
            }
        }
      + lifecycle_rule {
          + enabled = true
          + id      = "b"
          + prefix  = "b/"

          + expiration {
              + days = 10
            }
        }
      + lifecycle_rule {
          + enabled = true
          + id      = "c"
          + prefix  = "c/"

          + expiration {
              + days = 10
            }
        }

      + versioning {
          + enabled    = (known after apply)
          + mfa_delete = (known after apply)
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_s3_bucket.test: Creating...
aws_s3_bucket.test: Creation complete after 2s [id=tf-dynamic-test-1402]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Enjoy! 🚀

@bflad bflad closed this as completed Jul 24, 2019
@ghost
Copy link

ghost commented Nov 2, 2019

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Nov 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/s3 Issues and PRs that pertain to the s3 service.
Projects
None yet
Development

No branches or pull requests

4 participants