I have a tf code to create folders via aws_s3_object resource and am trying to modify the current code:
variable "s3_bucket_folders" {
type = set(string)
default = []
}
resource "aws_s3_object" "folders" {
for_each = var.s3_bucket_folders
bucket = aws_s3_bucket.bucket.id
acl = "private"
key = each.key
}
I also want the bucket to be using a for_each so that in every bucket I specify the folders mentioned should be created. I tried using a map with dynamic but am running into errors, can anyone specify the best solution for this
Trying to find the best possible solution to create all these folders withing buckets from one resource block
2
Answers
use count instead of for_each
Transform your list to a set for the foreach to iterate over