简体   繁体   中英

Terraform to create ec2 instance error even though instance is created

I am having trouble creating ec2 instances with my IAM role. The permissions I gave are

List DescribeInstances DescribeKeyPairs

Read DescribeTags

Tagging CreateTags

Write CreateKeyPair DeleteKeyPair ImportKeyPair RunInstances TerminateInstances

The error is

error while describing instance(...) attribute (instanceInitiatedShutdownBehaviour): UnnauthorizedOperation: You are no authorized to perform this operation.

However, on the AWS console, the ec2 instance is created. I am unable to terraform destroy it due to the same error.

It works if I give full ec2 access (ec2:*) so it has nothing to do with my terraform code.

Thank you.

I went through the same error and it is because of lack of permission. In the error:

error while describing instance(...) attribute (instanceInitiatedShutdownBehaviour): UnnauthorizedOperation: You are no authorized to perform this operation.

the UnnauthorizedOperation is trying to describe an instance attribute since you do not have the ec2:DescribeInstanceAttribute permission.

Depending on how your terraform config looks like for the instances, you may require more permissions. You can enable debug logs in your apply command to get more information:

TF_LOG=DEBUG terraform apply

Use the visual policy editor to add permissions to your IAM role and look out for Action Warnings . It will tell you if you are missing any permissions required by the existing permission.

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