Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix MalformedPolicyDocument in terraform

I am learning to deploy AWS infrastructure using terraform. I have written below code to create IAM policy-

    resource "aws_iam_role_policy" "s3_access_policy" 
{
  name = "s3_access_policy"
  role = aws_iam_role.s3_access_role.id

  policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "s3.*",
      "Resource": "*"
    }
  ]
}
EOF
}

When I run terraform apply I am getting below error-

Error: Error putting IAM role policy s3_access_policy: MalformedPolicyDocument: Actions/Conditions must be prefaced by a vendor, e.g., iam, sdb, ec2, etc.
        status code: 400, request id: cdd4d629-4f43-450c-a4f1-b6d475e363f0

  on main.tf line 14, in resource "aws_iam_role_policy" "s3_access_policy":
  14: resource "aws_iam_role_policy" "s3_access_policy" {

Not able to resolve this and would greatly appreciate your help

like image 698
rp123409 Avatar asked Sep 18 '25 15:09

rp123409


1 Answers

I think you need a colon (not a period) in your Action so s3:* rather than s3.*.

like image 168
mjgpy3 Avatar answered Sep 21 '25 04:09

mjgpy3