Geekdocs
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

09. CF Conditions

Table of contents

Conditions are used to control the creation of resources or outputs based on a condition, allowing to create different resources or properties depending on the environment for example.

To define a condition we do:

Conditions:
  CreatesProdResources: !Equal [ !Ref EnvType, prod ]

Here, the logical ID is for you to choose, where we name our condition. The intrinsic function can be:

  • Fn::And
  • Fn::Equals
  • Fn::If
  • Fn::Not
  • Fn::Or

We can use it like this, to create a resource conditionally:

Resources:
  MountPoint:
    Type: AWS::EC2::VolumeAttachment
    Condition: CreateProdResources

If this condition is false, it won’t be created.