'CloudFormation Cyclic dependency

I am creating a KMS key using a CloudFormation template which is then used to create an IAM role in another template since it references the KMS key. The stack that creates the KMS key needs to be updated to add the IAM role to the KMS key policy. The KMS policy cannot be set on creation since the IAM role doesnt exist. Is there a way to reference an existing resource in CF templates without manually updating the stack?



Solution 1:[1]

You can make use of Fn:ImportValue to get required data from another cloud formation template.

Your template A will create KMS key and outputs the ARN of the KMS Key.

Your template B, which creates IAM Role, will take the KMS Key as input using the Fn::ImportValue.

Hope this helps.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pablissimo