次の terraform ファイルを初めて実行するたびに、エラーが発生します。
IAM ロール SecurityMonkey の作成中にエラーが発生しました: MalformedPolicyDocument: ポリシーの無効なプリンシパル: "AWS"。
ただし、コードを実行すると、2 回目の実行が成功し、役割を引き受けるオブジェクトが作成されます。私には、ロール A とロール B の間の依存関係に問題があるように見えます。解決策として、ロール A に depends_on ステートメントを追加しましたが、うまくいきませんでした。
SecurityMonkeyInstanceProfile
ここで私のTFコードを確認できます。
resource "aws_iam_role" "SecurityMonkey" {
name = "SecurityMonkey"
depends_on = ["aws_iam_role.SecurityMonkeyInstanceProfile"]
path = "/"
assume_role_policy = <<POLICY
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<AccountID>:role/SecurityMonkeyInstanceProfile"
},
"Action": "sts:AssumeRole"
}
]
}
POLICY
}
resource "aws_iam_role" "SecurityMonkeyInstanceProfile" {
name = "SecurityMonkeyInstanceProfile"
path = "/"
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
POLICY
}
エラーで最初の実行。
aws_iam_role.SecurityMonkey: Error creating IAM Role SecurityMonkey: MalformedPolicyDocument: Invalid principal in policy: "AWS":"arn:aws:iam::<AccountID>:role/SecurityMonkeyInstanceProfile"
status code: 400, request id: 0810c923-28dd-11e6-af5d-47689d50861a
2回目の実行はエラーなし。
terraform apply -var-file=../../aws.tfvars
aws_iam_role.SecurityMonkeyInstanceProfile: Refreshing state... (ID: SecurityMonkeyInstanceProfile)
aws_iam_role.SecurityMonkey: Creating...
arn: "" => "<computed>"
assume_role_policy: "" => "{\n \"Version\": \"2008-10-17\",\n \"Statement\": [\n {\n \"Sid\": \"\",\n \"Effect\": \"Allow\",\n \"Principal\": {\n \"AWS\": \"arn:aws:iam::<AccountID>:role/SecurityMonkeyInstanceProfile\"\n },\n \"Action\": \"sts:AssumeRole\"\n }\n ]\n}\n"
name: "" => "SecurityMonkey"
path: "" => "/"
unique_id: "" => "<computed>"
aws_iam_role.SecurityMonkey: Creation complete
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
SecurityMonkeyInstanceProfile明らかに、リソースは正しい順序で作成されますが、ロールごとにロールを検出できないようにするある種のタイムアウトがあるようですSecurityMonkey。かなりニワトリが先か卵が先かの問題。
ヒントはありますか?