LoginSignup
0
0

More than 1 year has passed since last update.

CloudFormationでEC2ユーザデータを環境別に指定する

Last updated at Posted at 2023-04-28

AWS::EC2::InstanceAWS::EC2::LaunchTemplateで指定するプロパティUserDataを環境別に指定するにはどう書けばいいか悩み、ググっても出てこなかったのでメモ。
今回は「本番環境」と「それ以外の環境」で分けたい場合について記載する。

Parameters:
  env:
    AllowedValues:
      - 'prod'
      - 'stg'
      - 'dev'
    Type: String

Conditions:
  IsProduction: !Equals [!Ref env, 'prod']

Resources:
  EC2:
    Type: AWS::EC2::Instance
    Properties:
      UserData:
        Fn::If:
          - IsProduction
          - Fn::Base64: !Sub |
            {{本番環境用の処理}}
          - Fn::Base64: !Sub |
            {{それ以外の環境用の処理}}
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