I am new to writing AWS Cloudformation templates. I am trying to use If Else conditions on my CF template. How can I use if else statements with resources?
If AWS::Region == eu-central-1 ==> create resource , else continue.
Fn::If. Returns one value if the specified condition evaluates to true and another value if the specified condition evaluates to false .
According to the docs, Conditions should be used at the top level of the resource you want to conditionally create. Putting a Condition inside the Instance UserData section isn't supported. To use Conditions in your situation, you'd want separate Resources conditionally created based on the Parameter.
The Fn::GetAtt intrinsic function returns the value of an attribute from a resource in the template. For more information about GetAtt return values for a particular resource, refer to the documentation for that resource in the Resource and property reference.
Pseudo parameters are parameters that are predefined by AWS CloudFormation. You don't declare them in your template. Use them the same way as you would a parameter, as the argument for the Ref function.
Define a condition in the conditions sections
Conditions:
createResource: !Equals [ !Ref 'AWS::Region', 'eu-central-1']
Then on your resources
Resources:
MyResourcesOnlyCreatedSometime:
Condition: createResource
Type: AWS::Blah::Blah
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With