【发布时间】:2020-10-27 00:32:17
【问题描述】:
我正在努力将 kms 密钥导入 terraform,不幸的是,每个 sid 都有大量的 Principal 资源,每个 sid 的这个 principal 都是相同的。所以我正在尝试使用模板来制定政策。
我试过了:
policy.json.tpl
{
"Version": "2012-10-17",
"Id": "key-policy-1",
"Statement": [{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": ${allowed_resources}
},
"Action": "kms:*",
"Resource": "*"
},
{
"Sid": "Allow use of the key",
"Effect": "Allow",
"Principal": {
"AWS": ${allowed_resources}
},
"Action": [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
],
"Resource": "*"
}
]
}
main.tf
data "template_file" "key_policy" {
template = file("${path.module}/policy.json.tpl")
vars = {
allowed_resources = var.allowed_resources
}
}
resource "aws_kms_key" "key" {
description = ""
tags = local.common_tags
policy = data.template_file.amp_key_policy.rendered
}
变量.tf
variable "allowed_resources" {
description = "list of all principal resources"
type = list(string)
default = [
"arn:aws:iam::xxxxxxxxxxxx:user/a",
"arn:aws:iam::xxxxxxxxxxxxx:user/b",
"arn:aws:iam::xxxxxxxxxx:user/c",
"arn:aws:iam::xxxxxxxxxx:role/abc,
]
}
错误:
在 main.tf 第 11 行,数据“template_file”“key_policy”:11: vars = { 12: allowed_resources = var.allowed_resources 13: }
属性“vars”的值不合适:元素“allowed_resources”: 需要字符串。
使用 Terraform 0.12.20
我尝试将我的 arn 传递给 {vars = } 仍然出现错误。有人可以指出我错在哪里。
【问题讨论】:
-
我用的 Terraform 不多,但是看看AWS::Include Transform
-
你能完全扩展第二个语句吗?目前尚不清楚您在该部分做什么。
-
@ydaetskcoR 我已经更新了代码,当我尝试使用模板时出现错误
标签: amazon-web-services terraform amazon-iam