Show / Hide Table of Contents

Condition

The Condition declaration specifies a statement that defines the circumstances under which entities are created or configured.

Syntax

Condition: String
Description: String
Value: Expression

Properties

Condition

The Condition attribute specifies the item name. The name must start with a letter and followed only by letters or digits. Punctuation marks are not allowed. All names are case-sensitive.

Required: Yes

Type: String

Description

The Description attribute specifies the condition description.

Required: No

Type: String

Value

The Value attribute specifies a boolean expression using the intrinsic functions !And, !Equals, !Not, and !Or. The !Ref function is used to access module parameters. The !Condition function is used to reference other conditions.

Required: Yes

Type: Key-Value Pair Mapping

Examples

Conditional resources

- Parameter: EnvType
  Description: Environment type.
  Default: test
  Type: String
  AllowedValues:
    - prod
    - test
  ConstraintDescription: must specify prod or test.

- Resource: EC2Instance
  Type: "AWS::EC2::Instance"
  Properties:
    ImageId: ami-0ff8a91507f77f867

- Group: ProductionResources
  Items:

    - Condition: Create
      Value: !Equals [ !Ref EnvType, prod ]

    - Resource: MountPoint
      Type: AWS::EC2::VolumeAttachment
      If: ProductionResources::Create
      Properties:
        InstanceId: !Ref EC2Instance
        VolumeId: !Ref ProductionResources::NewVolume
        Device: /dev/sdh

    - Resource: NewVolume
      Type: AWS::EC2::Volume
      If: ProductionResources::Create
      Properties:
        Size: 100
        AvailabilityZone: !GetAtt EC2Instance.AvailabilityZone
In This Article
Back to top Generated by DocFX