Terraformで管理されたIAMポリシーを持つユーザーがリソースを使用する場合、それぞれのリソースを一覧表示する権限が必要となります。
今回はS3とLambdaの例で説明します。
S3の場合は使用したいバケットのみの権限、 Lambdaでは使いたいLambda関数のみの権限では足らず、それぞれ一覧表示する権限も付与する必要があります。
具体的にS3とLambdaの例だと以下の通り。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_iam_policy" "test_policy" { | |
name = "test_policy" | |
path = "/" | |
policy = "${data.aws_iam_policy_document.test_policy_document.json}" | |
} | |
data "aws_iam_policy_document" "test_policy_document" { | |
# S3 | |
statement { | |
effect = "Allow" | |
actions = [ | |
"s3:*", | |
] | |
resources = [ | |
"許可したいバケットのリソース" | |
] | |
} | |
statement { | |
effect = "Allow" | |
actions = [ | |
"s3:ListAllMyBuckets", #こいつが必要!!! | |
] | |
resources = [ | |
"*", | |
] | |
} | |
# Lambda | |
statement { | |
effect = "Allow" | |
actions = [ | |
"Lambda:*", | |
] | |
resources = [ | |
"許可したいLambda関数のリソース" | |
] | |
} | |
statement { | |
effect = "Allow" | |
actions = [ | |
"lambda:ListFunctions", # こいつが必要!!! | |
"lambda:GetAccountSettings", # こいつが必要!!! | |
] | |
resources = [ | |
"*", | |
] | |
} | |
} |
S3には、「s3:ListAllMyBuckets」が Lambdaには、「lambda:ListFunctions」と「lambda:GetAccountSettings」が必要となります!
コンソールを使わない場合はこういった権限追加は不要なのでちょっと詰まりました。