简体   繁体   中英

Terraform plan command failing

I am trying to use a different user along with a custom policy to execute my Terraform plan command but I am not able to figure out what policy action I am missing to run this command. I don't want to allow ec2:* .

The resources are already running, we are just trying to move the code to a different project.

When I run the plan with ec2:* permissions it's working correctly.

Error:

Error refreshing state: 2 error(s) occurred:

    * module.mesos.aws_instance.master: 3 error(s) occurred:      
    * module.mesos.aws_instance.master[2]: aws_instance.master.2: UnauthorizedOperation: You are not authorized to perform this operation.
        status code: 403, request id: 484574e1-0dd0-4c43-b829-42c034763bad
    * module.mesos.aws_instance.master[1]: aws_instance.master.1: UnauthorizedOperation: You are not authorized to perform this operation.
        status code: 403, request id: e0499d28-d55c-46e8-af1a-91262427b422
    * module.mesos.aws_instance.master[0]: aws_instance.master.0: UnauthorizedOperation: You are not authorized to perform this operation.
        status code: 403, request id: f1fb50ac-7bb5-47d6-b1b4-b24b38a61fdd
    * module.mesos.data.aws_ami.agent: 1 error(s) occurred:    
    * module.mesos.data.aws_ami.agent: data.aws_ami.agent: UnauthorizedOperation: You are not authorized to perform this operation.
        status code: 403, request id: a7dcf75b-30d1-4c74-8c30-a002644db313

Code:

{
       "Sid": "gitec2",
       "Effect": "Allow",
       "Action": [
           "ec2:DescribeInstances",
           "ec2:DescribeVolumeStatus",
           "ec2:StartInstances",
           "ec2:DescribeVolumes",
           "ec2:RunInstances",
           "ec2:StopInstances",
           "ec2:AssignPrivateIpAddresses",
           "ec2:DescribeVolumeAttribute",
           "ec2:DescribeSubnets",
           "ec2:AttachVolume",
           "ec2:DescribeRegions",
           "ec2:DescribeVpcAttribute",
           "ec2:DescribeAvailabilityZones",
           "ec2:DescribeInstanceStatus",
           "ec2:DescribeSecurityGroups",
           "ec2:DescribeVpcs",
           "ec2:DescribeNetworkAcls",
           "ec2:DescribeRouteTables",
           "ec2:DescribeLaunchTemplates",
           "ec2:DescribeAddresses",
           "ec2:DescribeInstanceAttributes",
           "ec2:DescribeNetworkInterfaces",
           "ec2:CreateSecurityGroup",
           "ec2:TerminateInstances",
           "ec2:DescribeIamInstanceProfileAssociations",
           "ec2:DescribeTags",
           "ec2:DescribeImageAttribute",
           "ec2:DescribeSecurityGroupReferences",
           "ec2:AssociateIamInstanceProfile",
           "ec2:AttachInternetGateway",
           "ec2:AttachNetworkGateway",
           "ec2:AssociateIamInstanceProfile",
           "ec2:DeleteSecurityGroup"
          ],
       "Resource": "*"
 }

The aws_instance resource read method (called when refreshing state) calls the DescribeInstances , DescribeInstanceAttribute , DescribeIamInstanceProfileAssociations endpoints which need the ec2:DescribeInstances , ec2:DescribeInstanceAttribute and ec2:DescribeIamInstanceProfileAssociations respectively.

The aws_ami data source calls the DescribeImages endpoint which needs the ec2:DescribeImages IAM action.

As such you are missing the ec2:DescribeInstanceAttribute (you have ec2:DescribeInstanceAttributes which isn't a valid action) and ec2:DescribeImages .

The calls that Terraform makes can be discovered by looking at the source code ( aws_instance and aws_ami ) while the relevant IAM actions can be found in the AM docs for EC2 .

I'd be surprised if there's a good reason not to allow ec2:Describe* though as these are just read only actions and shouldn't expose anything sensitive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM