【发布时间】:2019-05-15 03:53:02
【问题描述】:
我创建了一个较早的帖子来解决在不尝试复制代码的情况下创建多个 s3 存储桶的问题。效果很好!
Terraform - creating multiple buckets
aws_iam_policy 如下所示:
resource "aws_iam_policy" "user_policy" {
count = "${length(var.s3_bucket_name)}"
name = "UserPolicy"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:ListBucket",
"s3:GetLifecycleConfiguration",
"s3:PutLifecycleConfiguration",
"s3:PutObjectTagging",
"s3:GetObjectTagging",
"s3:DeleteObjectTagging"
],
"Resource": [
"arn:aws:s3:::${var.s3_bucket_name[count.index]}",
"arn:aws:s3:::${var.s3_bucket_name[count.index]}/*"
]
}
]
}
EOF
}
这是我附加政策的方式:
resource "aws_iam_user_policy_attachment" "user_policy_attach" {
user = "${aws_iam_user.user.name}"
policy_arn = "${aws_iam_policy.user_policy.arn}"
}
不幸的是,附加 IAM 用户策略会给我一个错误,因为它必须遍历索引:
Resource 'aws_iam_policy.user_policy' not found for variable 'aws_iam_policy.user_policy.arn'
【问题讨论】:
标签: amazon-web-services amazon-s3 terraform