我正在尝试将一个变量设置为一个字符串,该字符串稍后将与另一个字符串连接以用于 aws s3 存储桶策略。我试图通过定义一个局部变量来做到这一点,但我还需要指定一个我想要使用它的条件。我正在使用 terraform 11。
例如:
- 如果 set_bucket_policy 为 false 则将变量设为空字符串 ""
- 否则使用heredoc设置变量的字符串值
例如,不工作的代码:
locals {
my_bucket_policy = var.set_bucket_policy == "false" ? "" : <<EOF
{
"Action": "s3:Get*",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/myrole"
},
"Resource": [
"arn:aws:s3:::mybucket",
"arn:aws:s3:::mybucket/*"
],
"Sid": ""
}
EOF
}