<p>I just found a solution, I've created &quot;count&quot; for every resource:</p>
<pre><code>resource &quot;aws_s3_bucket&quot; &quot;this&quot; {
    count = length(var.s3_bucket_names)
    bucket = var.s3_bucket_names[count.index]
    tags = var.tags
}

resource &quot;aws_s3_bucket_acl&quot; &quot;this_acl&quot; {
    count = length(aws_s3_bucket.this)
    bucket = aws_s3_bucket.this[count.index].id
    acl = var.acl
}
</code></pre>

CC BY-SA 4.0
2022-05-11T16:54:22.073Z
2022-05-11T16:54:22.073Z
Hendrick
<p>I have a terraform file set to create a list of S3 buckets, and I was assigning acl to each bucket the old way:</p>
<pre><code>resource &quot;aws_s3_bucket&quot; &quot;this&quot; {
    count = length(var.s3_bucket_names)
    bucket = var.s3_bucket_names[count.index]
    acl = var.acl
    tags = var.tags
}
</code></pre>
<p>However, I want to know how to do it using <code>aws_s3_bucket_acl</code> 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.</p>
<p>This is what I want to do:</p>
<pre><code>resource &quot;aws_s3_bucket_acl&quot; &quot;this_acl&quot; {
    bucket = HERE I DON'T KNOW HOW TO REFERENCE A TUPLE OR LIST
    acl = var.acl
}
</code></pre>
<p>What should I do to reference a tuple since <code>aws_s3_bucket.this.*.id</code> doesn't work with a tuple/list?</p>
<p>Thank you in advance.</p>

<terraform><amazon-s3>
How to assign an ACL for each S3 Bucket in a tuple/list using Terraform?
Hendrick
# How to assign an ACL for each S3 Bucket in a tuple/list using Terraform?

(Asked by: username_0 on 2022-05-11)

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.

**Tags:** terraform, amazon-s3


---

## 1 answers

### Answer by username_0 on 2022-05-11. Score: 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
}


---

