I am trying to create a re-usable company module for creating S3 buckets. I want to set a condition if a given resource will be created or not (lifecycle rules for example) per bucket. So I am using the following variable and for_each in every resource.
But can I use for_each with a if statement based on the “enable_lifecycle” key status (true/false) and create the lifecycle rules only for the bucket(s) I want?
Hi again,
I managed to solve the problem above, but want to go a bit deeper. Think it is not possible (yet), but still. What I am trying to achieve is the following. Now some buckets may have lifecycle rule set, some may not.
My new var:
variable "bucket_details" {
type = map(object({
bucket_name = string
enable_lifecycle = bool
glacier_ir_days = number
glacier_days = number
}))
}
How I go through the map on the lifecycle resource: