Reputation: 1014
I have a use case where I want to create a resource only in test environment using cloud formation. I'm trying to use conditionals to achieve this but it fails.
Resources:
TestClientRole:
Type: AWS::IAM::Role
Condition: NotProdStage
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: <>
Effect: Allow
<>
Version: '2012-10-17'
RoleName:
"some-test-role"
It works fine in non-prod stages, but fails with "Unresolved resource dependencies [TestClientRole] in the Resources block of the template"
How to make cloud formation ignore resources for prod stages?
Upvotes: 0
Views: 1111
Reputation: 269370
The error message is indicating that there is a dependency on TestClientRole
elsewhere in your CloudFormation template.
The problem is that the Role is not being created in a Prod environment, yet the other resource is saying that it is dependent on the role being created.
Solution: Remove the dependency elsewhere in your template that refers to TestClientRole
.
In fact, it is very rare to actually require dependencies because CloudFormation figures out the correct build order based upon references between resources. The only time you need a dependency is when you specifically want one thing to finish building before another starts, such as having an app server wait until a database server is ready. Typically, leave them out unless you have a particular need that is non-obvious.
Upvotes: 2