在我当前的 terraform 配置中,我使用静态 JSON 文件并使用 file 函数导入到 terraform 以创建 AWS IAM 策略。
地形代码:
resource "aws_iam_policy" "example" {
policy = "${file("policy.json")}"
}
Run Code Online (Sandbox Code Playgroud)
JSON 文件 (policy.json) 中的 AWS IAM 策略定义:
{
"Version": "2012-10-17",
"Id": "key-consolepolicy-2",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111122223333:root"
},
"Action": "kms:*",
"Resource": "*"
},
{
"Sid": "Allow use of the key",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::777788889999:root"
]
},
"Action": [
"kms:Decrypt"
],
"Resource": "*"
},
{
"Sid": "Allow use …Run Code Online (Sandbox Code Playgroud) json amazon-web-services amazon-iam terraform infrastructure-as-code