2

I have a terraform file set to create a list of S3 buckets, and I was assigning acl to each bucket the old way:

resource "aws_s3_bucket" "this" {
    count = length(var.s3_bucket_names)
    bucket = var.s3_bucket_names[count.index]
    acl = var.acl
    tags = var.tags
}

However, I want to know how to do it using aws_s3_bucket_acl but I can't reference the bucket because it is a tuple and not a string. I've tried a lot of things but I've got nothing so far.

This is what I want to do:

resource "aws_s3_bucket_acl" "this_acl" {
    bucket = HERE I DON'T KNOW HOW TO REFERENCE A TUPLE OR LIST
    acl = var.acl
}

What should I do to reference a tuple since aws_s3_bucket.this.*.id doesn't work with a tuple/list?

Thank you in advance.

0

1 Answer 1

2

I just found a solution, I've created "count" for every resource:

resource "aws_s3_bucket" "this" {
    count = length(var.s3_bucket_names)
    bucket = var.s3_bucket_names[count.index]
    tags = var.tags
}

resource "aws_s3_bucket_acl" "this_acl" {
    count = length(aws_s3_bucket.this)
    bucket = aws_s3_bucket.this[count.index].id
    acl = var.acl
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.