Slide 19
Slide 19 text
外部のJSONテンプレートを読み込みます。
特徴
● Policyをtfファイルの外でJSONテンプレートを定義
● Policy定義を外部化できるのでリソース定義の見
通しがよくなる
● 変数が使用可能
ユースケース
● 扱うPolicyが多いとき
Copyright © 3-shake, Inc. All Rights Reserved.
templatefile()
19
// files/policy.json.tpl (テンプレートファイル )
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowS3Read",
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "${bucket_arn}/*"
}
]
}
// main.tf
resource "aws_iam_policy" "example" {
name = "example-policy"
policy = templatefile(
"${path.module}/files/policy.json.tpl",
{
bucket_arn = aws_s3_bucket.my_bucket.arn
}
)
}