计数Terraform资源aws_iam_policy中未正确工作



我已经为给定作业名称列表的log_group创建了资源

resource "aws_cloudwatch_log_group" "logGroups" {
count             = length(var.jobnames)
name              = format("/aws/lambda/%s", format(local.function_name_format, var.jobnames[count.index]))
retention_in_days = 7
}
and now for the each log resource i am creating an iam policy
resource "aws_iam_policy" "base_iam_policy" {
count = length(var.jobnames)
name = format(local.base_iam_policy_name_format, var.jobnames[count.index])
path = "/"
description = "Base IAM policy for creating a lambda"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
"${element(aws_cloudwatch_log_group.logGroups.*.arn, count.index)}*"
]
},
{
"Action": [
"cloudwatch:PutMetricData",
"cloudwatch:GetMetricData",
"cloudwatch:GetMetricStatistics",
"cloudwatch:ListMetrics"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Effect": "Allow",
"Action": [
"ec2:CreateNetworkInterface",
"ec2:DescribeNetworkInterfaces",
"ec2:DeleteNetworkInterface"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:RequestedRegion": "${var.region}"
}
}
}
]
}
EOF
}

问题是,对于每个BASE_IAM_POLICY,CreateLogStream的资源是相同的。看起来像在该"${element(aws_cloudwatch_log_group.logGroups.*.arn, count.index)}*"中,计数是否不递增?

老实说,这似乎是地形中的一个bug。同时,我建议直接对元素进行索引,比如下面的

"${aws_cloudwatch_log_group.logGroups[count.index].arn}*"

相关内容

  • 没有找到相关文章

最新更新