Terraform - attach policy to s3 bucket

后端 未结 1 641
走了就别回头了
走了就别回头了 2021-01-29 05:38

I created an earlier post to resolve an issue for creating multiple s3 buckets without trying to duplicate code. It worked well!

Terraform - creating multiple buckets

1条回答
  •  情书的邮戳
    2021-01-29 06:37

    I don't think you can inline variables inside the policy like that. Instead you need to create a template_file, and feed the result of the template through to the policy.

    This will create a policy for each bucket (names taken from the previous question)

    • UserPolicy-prod_bucket
    • UserPolicy-stage-bucket
    • UserPolicy-qa-bucket

    You then need to attach each of the policies to the aws_iam_user.user.name by using count again. Like so

    data "template_file" "policy" {
      count = "${length(var.s3_bucket_name)}"
    
      template = <

    0 讨论(0)
提交回复
热议问题