Reputation:
Hello I have the following policy definition in my terraform, but it keeps returning as malformed
resource "aws_iam_role_policy" "task-policy" {
name = "docker-flowcell-restore-task-policy"
role = "${aws_iam_role.task-role.id}"
policy = "${file("${path.module}/policies/role-docker-flowcell-restore-${var.environment}-ecs-policy.json")}"
}
Been struggling with trying to find the error in this for awhile.
here is the error
aws_iam_role_policy.task-policy: Error putting IAM role policy docker-flowcell-restore-task-policy: MalformedPolicyDocument: Syntax errors in policy.
Here is the policy that is failing
{
"Version": "2012-10-17",
"Statement": [
{
"Sid":"AllowWritesS3",
"Action": [
"s3:GetObject",
"s3:RestoreObject"
],
"Effect": "Allow",
"Resource": [
"Temp_name_for_post",
"Temp_name_for_post"
]
},
{
"SID": "Allow for user for upload S3 bucket",
"Action": [
"s3:PutObject",
"s3:AbortMultipartUpload"
],
"Resource":[
"temp_name_for_post",
"temp_name_for_post"
]
}
]
}
Upvotes: 1
Views: 617
Reputation: 3534
Unfortunately AWS doesn't tell you exactly what the syntax errors are, so you have to find them yourself. Sometimes you can do this by eye; other times you may just want to use the AWS Console as Jeffrey suggested - and perhaps take out each statement one-by-one then re-validate, to see where the error lies (it's a lot quicker than waiting for Terraform to finish).
In your case, you need to:
SID
to Sid
in your second statementSid
value in that second statement so it has no spaces in it (eg. "AllowForUserForUploadS3Bucket"
)"temp_name_for_post"
, such as "arn:aws:s3:::my-bucket/*"
to refer to all objects in a bucket named my-bucket
After changing these items, the policy now validates for me via the AWS Console.
Upvotes: 3
Reputation: 983
It looks like your iam policy is malformed. Here are docs on iam syntax and grammar. Another option to see what is wrong with the policy would be to copy the contents of that file into the iam policy validator in the aws console. The Sid field is not required, but if present it must be unique in the policy, and it cannot contain spaces.
Upvotes: 0