Reputation: 6748
I have this CloudFormation configuration:
Resources:
DevoSnsTopic:
Type: AWS::SNS::Topic
Condition: UseDevoTopic
...
SnsTopic:
Type: AWS::SNS::Topic
...
QueuePolicy:
Properties:
Condition:
'ForAnyValue:ArnEquals':
'aws:SourceArn':
- Ref: SnsTopic
- Ref: DevoSnsTopic
Will it break if UseDevoTopic
equals false
? Or it will simply skip reference for DevoSnsTopic
?
UPD: Yes missing resource breaks the changeset!
Upvotes: 0
Views: 1782
Reputation: 6876
If you're concerned with an invalid reference if the UseDevoTopic
is false and DevoSnsTopic
hasn't been created, you could use the Fn::If
condition and provide the AWS::NoValue
Pseudo Parmater if false
Resources:
DevoSnsTopic:
Type: AWS::SNS::Topic
Condition: UseDevoTopic
...
SnsTopic:
Type: AWS::SNS::Topic
...
QueuePolicy:
Properties:
Condition:
'ForAnyValue:ArnEquals':
'aws:SourceArn':
- Ref: SnsTopic
- !If [UseDevoTopic, !Ref DevoSnsTopic, AWS::NoValue]
Upvotes: 2
Reputation: 269540
A resource is only created if the Condition
evaluates to true. It it is not true, then the resource will not be created.
This is a great way to deploy different resources (or resources with different attributes) between Dev/Test/Prod systems, or to do some if/then logic for specifying values.
Here's some snippets from a CloudFormation template that deploys differently based upon the region in which it is deployed:
"Conditions": {
"InUsEast1": {
"Fn::Equals": [
{
"Ref": "AWS::Region"
},
"us-east-1"
]
},
Upvotes: 0