variable "lifecycle_rule_60_days" {  type = "map"
  default = {    id      = "whole-bucket"    prefix  = ""    enabled = true
    expiration = [{      days = 60    }]  }}
resource "aws_s3_bucket" "bucket_a" {  bucket = "bucket_a"  lifecycle_rule = ["${var.lifecycle_rule_60_days}"]}
resource "aws_s3_bucket" "bucket_b" {  bucket   = "bucket_b"  lifecycle_rule = ["${var.lifecycle_rule_60_days}"]}variable "lifecycle_rule_60_days" {  type = object({    id      = string    prefix  = string    enabled = bool    expiration = list(object({      days = number    }))  })
  default = {    id      = "whole-bucket"    prefix  = ""    enabled = true
    expiration = [{      days = 60    }]  }}
resource "aws_s3_bucket" "bucket_a" {  bucket = "bucket_a"
  dynamic "lifecycle_rule" {    for_each = [var.lifecycle_rule_60_days]    content {      prefix  = lifecycle_rule.value.prefix      enabled = lifecycle_rule.value.enabled      dynamic "expiration" {        for_each = lifecycle_rule.value.expiration        content {          days = expiration.value.days        }      }    }  }}
resource "aws_s3_bucket" "bucket_b" {  bucket = "bucket_b"  dynamic "lifecycle_rule" {    for_each = [var.lifecycle_rule_60_days]    content {      prefix  = lifecycle_rule.value.prefix      enabled = lifecycle_rule.value.enabled      dynamic "expiration" {        for_each = lifecycle_rule.value.expiration        content {          days = expiration.value.days        }      }    }  }}variable "lifecycle_rule_60_days" {  type = object({    id      = string    prefix  = string    enabled = bool    expiration = list(object({      days = number    }))  })
  default = {    id      = "whole-bucket"    prefix  = ""    enabled = true
    expiration = [{      days = 60    }]  }}
resource "aws_s3_bucket" "bucket_a" {  bucket = "bucket_a"
  lifecycle_rule = var.lifecycle_rule_60_days}
resource "aws_s3_bucket" "bucket_b" {  bucket = "bucket_b"  lifecycle_rule = var.lifecycle_rule_60_days}--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/c2984491-4bd5-447c-9cef-a0805f18e4d5%40googlegroups.com.
What if you flip the logic and instead loop over a list of bucket names using count/length? Then specify the lifecycle block just once.
To unsubscribe from this group and stop receiving emails from it, send an email to terrafo...@googlegroups.com.
locals {
  lifecycle_rule = [{    id      = "whole-bucket"    prefix  = ""    enabled = true
    expiration = [      {        days = 60    }]  }]  buckets = {    bucket_a = {      lifecycle_rule = local.lifecycle_rule    },    bucket_b = {      lifecycle_rule = local.lifecycle_rule    }  }}
resource "aws_s3_bucket" "buckets" {  for_each = toset(keys(local.buckets))  bucket   = each.key  dynamic "lifecycle_rule" {    for_each = local.buckets[each.value].lifecycle_rule    content {      prefix  = lifecycle_rule.value.prefix      enabled = lifecycle_rule.value.enabled      dynamic "expiration" {        for_each = lifecycle_rule.value.expiration        content {          days = expiration.value.days        }      }    }  }}>> To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/afd71d69-259e-40af-bdf8-48687cd82c24%40googlegroups.com.
--
Stuart Clark