【发布时间】:2017-11-26 07:40:47
【问题描述】:
我能够成功运行包含以下 sn-p 的 cloudformation 堆栈,现在我的最终目标是将其移植到 Terraform,但是..
即使在 AWS 控制台中,我也会收到格式错误的语法错误。我尝试使用 AWS 控制台的“策略编辑器”进行调试,然后单击“验证”按钮,但错误不是特定的。有人知道我在做什么错吗?这很奇怪,因为当我部署 cloudformation 堆栈模板时,这个策略似乎起作用了。 (顺便说一句,如果有帮助,这来自 GorillaStack 的 AutoTagging 项目)
此政策包含以下错误:政策中的语法错误。有关 IAM 策略语法的更多信息,请参阅 AWS IAM 策略。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"*"
]
},
{
"Effect": "Allow",
"Action": [
"cloudformation:DescribeStackResource"
],
"Resource": [
{ "Fn::Join": [ "", [ "arn:aws:cloudformation:", { "Ref" : "AWS::Region" }, ":", { "Ref" : "AWS::AccountId" }, ":stack/autotag/*" ] ] }
]
},
{
"Effect": "Allow",
"Action": [
"sts:*"
],
"Resource": [
{ "Fn::GetAtt" : [ "AutoTagMasterRole", "Arn" ] }
]
}
]
}
我的 terraform 配置有以下资源(包括上面的 sn-p)
resource "aws_iam_role_policy" "AutoTagExecutionPolicy" {
name = "AutoTagExecutionPolicy"
role = "${aws_iam_role.AutoTagExecutionRole.id}"
policy = <<EOF
<-THE POLICY ABOVE GOES HERE->
EOF
}
【问题讨论】:
-
当您将策略移至 terraform 时,您是否删除了 Cloudformation 功能,如 ref 的?
-
不,我没有。你能推断出来吗?例如,我是否需要在 terraform config 中为 cloudformation 模板中的此类条目插入值?:{“Ref”:“AWS::AccountId”}
-
这些函数中的每一个都是 cloudformation 的原生函数,您需要将它们转换为 terraform 脚本中的变量。
-
该死,我明白了。这并不像我想象的那么简单。我在文档中没有看到类似的东西。如果你对这个答案有信心,那我就指明了正确的方向。
-
我需要转换这一整行: { "Fn::Join": [ "", [ "arn:aws:cloudformation:", { "Ref" : "AWS::Region" }, ":", { "Ref" : "AWS::AccountId" }, ":stack/autotag/*" ] ] } 我不知道那会是什么样子。新手在这里
标签: amazon-cloudformation amazon-iam terraform