【问题标题】:how to use IAM policy variables in terraform code如何在 terraform 代码中使用 IAM 策略变量
【发布时间】:2021-09-08 07:40:22
【问题描述】:
{
  "Sid": "Allow bucket write",
  "Effect": "Allow",
  "Principal": {
    "Service": [
      "cloudtrail.amazonaws.com"
    ]
  },
  "Action": "s3:PutObject",
  "Resource": "${aws_s3_bucket.log-dev-test-bucket-test.arn}/AWSLogs/${var.organization_id}/${aws:PrincipalAccount}/*",
  "Condition": {"StringEquals": {"s3:x-amz-acl": "bucket-owner-full-control"}}
},

我在我的资源部分收到这条关于 ${aws:PrincipalAccount} 的消息:

“插值表达式后的额外字符:模板插值不希望在此位置出现冒号。您是否打算将其作为文字序列作为另一种语言的一部分进行处理?如果是这样,您可以通过以下方式对其进行转义"$${" 而不仅仅是 "${".HCL"

错误消息建议使用 $${aws:PrincipalAccount} 来逃避它。我不知道这会对它做什么,因为我需要在策略语句资源部分中有这个 IAM 策略变量来实现我的目标。能否解释一下如果我在 {aws:PrincipalAccount} 之前使用 $$ 而不是 $ 会发生什么转义。谢谢

【问题讨论】:

    标签: amazon-web-services terraform


    【解决方案1】:

    没有像 aws:PrincipalAccount 这样的 IAM 变量Request information that you can use for policy variables 中列出了可用的 IAM 变量。

    【讨论】:

      猜你喜欢
      • 2020-08-12
      • 2018-01-11
      • 2021-06-04
      • 2021-05-21
      • 2020-04-25
      • 2020-11-11
      • 1970-01-01
      • 2022-01-19
      • 2020-01-09
      相关资源
      最近更新 更多