How to find out aws policy attachment id for terraform import?

by Anthony Kong   Last Updated September 12, 2019 04:00 AM

I want to import some existing resource into my state file.

One of them is a policy attachement.

Since the attachment is absent in the state file, if I run terraform plan I will see this output:

  # aws_iam_role_policy_attachment.ec2_adhoc_instance_sqs_policy_attachment will be created
  + resource "aws_iam_role_policy_attachment" "ec2_adhoc_instance_sqs_policy_attachment" {
      + id         = (known after apply)
      + policy_arn = "arn:aws:iam::141225792464:policy/import-sqs-read-write-policy"
      + role       = "import-sqs-user"
    }

If I want to import it, I need to find out the ID of the attachment:

tf -f dev import  aws_iam_role_policy_attachment.ec2_adhoc_instance_sqs_policy_attachmen <ID?>

However I can't find it from the console:

enter image description here

And I have trouble running the aws cli,

$ aws clouddirectory list-policy-attachments --directory-arn 999999999 --policy-reference import-sqs-read-write-policy

Error parsing parameter '--policy-reference': Expected: '=', received: 'EOF' for input:
import-sqs-read-write-policy

How can I find out the id of a policy attachment?



Related Questions




Terraform expand VPC CIDR in AWS

Updated August 30, 2017 18:00 PM


Terraform safeguards

Updated February 22, 2018 21:00 PM