LoginSignup
0
0

More than 1 year has passed since last update.

Cloudformationで条件の真偽値を反転する

Last updated at Posted at 2022-10-07

記述方法

AWS Cloudformationで条件の真偽値を反転する方法を記述します。

!Not [ Condition: <Conditionの論理ID> ]
または
!Not [ !Condition <Conditionの論理ID> ]

Fn::Not関数の引数をリストCondition:または!Conditionを付けて論理IDを記述します。

サンプル

template.yaml
AWSTemplateFormatVersion: 2010-09-09
Description: sample template

Parameters:
  EnvType:
    Type: String
    Default: stg

Conditions:
  IsStaging: !Equals [ !Ref EnvType, stg ]
  IsProduct: !Not [ Condition: IsStaging ]
  IsProduct2: !Not [ !Condition IsStaging ]

Resources:
  SampleTopic:
    Type: AWS::SNS::Topic
    Properties:
      TopicName: !Sub ${EnvType}-sample-topic

Outputs:
  IsStaging:
    Value: [ Condition: IsStaging ]
  IsProduct:
    Value: [ Condition: IsProduct ]
  IsProduct2:
    Value: !Condition IsProduct2
$ aws cloudformation describe-stacks
...
            "Outputs": [
                {
                    "OutputKey": "IsStaging",
                    "OutputValue": "[True]"
                },
                {
                    "OutputKey": "IsProduct",
                    "OutputValue": "[False]"
                },
                {
                    "OutputKey": "IsProduct2",
                    "OutputValue": "False"
                }
            ],
...

参照

これがわかるまで結構時間が掛かったのですが、公式のドキュメントに条件の参照方法がありました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0