简体   繁体   中英

Policy not imported using terraform import

I created a role manually using aws console called demo_role. I attached a policy to this role. I ran

terraform import aws_iam_role.demo_role demo_role

and it successfully imported it in the state file. However, terraform show doesn't display the policy I attached to it. What did I miss?

output of terraform show

aws_iam_role.demo_role:
id = demo_role
arn = arn:aws:iam::***********:role/demo_role
assume_role_policy = {"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"},"Action":"sts:AssumeRole"}]}
create_date = 2020-01-08T20:39:26Z
description = Allows Lambda functions to call AWS services on your behalf.
force_detach_policies = false
max_session_duration = 3600
name = demo_role
path = /
tags.% = 0
unique_id = *******************

Terraform won't import the attached policy automatically due to the fact that it's a separate resource. You need to also import the policy to an aws_iam_role_policy resource. The assume role policy is defined directly on the role itself, which is why it is included.

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