JeyJ
JeyJ

Reputation: 4070

Cloudformation access a resource that was already created

Is there a way to get the profileInstance of a role that wasnt created in the current stack ? Lets say I got in my cloudformation the role`s name (passed as a parameter), is there a way to get its profileinstance ?

Something like :

{"Fn::GetAtt" : ["MyRoleName", "ArnOfProfileInstance"] }

a more general question, can we access a resource that wasnt created in the current stack or through cloudformation at all?

Upvotes: 1

Views: 124

Answers (1)

Marcin
Marcin

Reputation: 238199

Yes, if you know the arn of role, the profile has known format. For example:

# role
arn:aws:iam::xxxxxx:role/my-role-name

# profile 
arn:aws:iam::xxxxxx:instance-profile/my-role-name

Therefore, you can create the profile arn from the role arn. For instance:

ProflieArn:
  Fn::Sub:
    - "arn:${AWS::Partition}:iam::${AWS::AccountId}:instance-profile/${rolename}"
    - rolename: !Select [1, !Split ['/', !GetAtt MyInstanceRole.Arn] ]

Upvotes: 1

Related Questions