Skip to content

Instantly share code, notes, and snippets.

@wjordan
Last active May 28, 2019 22:50
Show Gist options
  • Save wjordan/105da42b33667fdf3007f6dc4833208c to your computer and use it in GitHub Desktop.
Save wjordan/105da42b33667fdf3007f6dc4833208c to your computer and use it in GitHub Desktop.
10 variable EC2 instances - https://stackoverflow.com/a/41539208/2518355
Description: Create a variable number of EC2 instance resources.
Parameters:
InstanceCount:
Description: Number of EC2 instances (must be between 1 and 10).
Type: Number
Default: 1
MinValue: 1
MaxValue: 10
ConstraintDescription: Must be a number between 1 and 10.
ImageId:
Description: Image ID to launch EC2 instances.
Type: AWS::EC2::Image::Id
# amzn-ami-hvm-2016.09.1.20161221-x86_64-gp2
Default: ami-9be6f38c
InstanceType:
Description: Instance type to launch EC2 instances.
Type: String
Default: m3.medium
AllowedValues: [ m3.medium, m3.large, m3.xlarge, m3.2xlarge ]
Conditions:
Launch1: !Equals [1, 1]
Launch2: !Not [!Equals [1, !Ref InstanceCount]]
Launch3: !And
- !Not [!Equals [1, !Ref InstanceCount]]
- !Not [!Equals [2, !Ref InstanceCount]]
Launch4: !And
- !Not [!Equals [1, !Ref InstanceCount]]
- !Not [!Equals [2, !Ref InstanceCount]]
- !Not [!Equals [3, !Ref InstanceCount]]
Launch5: !And
- !Not [!Equals [1, !Ref InstanceCount]]
- !Not [!Equals [2, !Ref InstanceCount]]
- !Not [!Equals [3, !Ref InstanceCount]]
- !Not [!Equals [4, !Ref InstanceCount]]
Launch6: !Or
- !Equals [6, !Ref InstanceCount]
- !Equals [7, !Ref InstanceCount]
- !Equals [8, !Ref InstanceCount]
- !Equals [9, !Ref InstanceCount]
- !Equals [10, !Ref InstanceCount]
Launch7: !Or
- !Equals [7, !Ref InstanceCount]
- !Equals [8, !Ref InstanceCount]
- !Equals [9, !Ref InstanceCount]
- !Equals [10, !Ref InstanceCount]
Launch8: !Or
- !Equals [8, !Ref InstanceCount]
- !Equals [9, !Ref InstanceCount]
- !Equals [10, !Ref InstanceCount]
Launch9: !Or
- !Equals [9, !Ref InstanceCount]
- !Equals [10, !Ref InstanceCount]
Launch10: !Equals [10, !Ref InstanceCount]
Resources:
Instance1:
Condition: Launch1
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref ImageId
InstanceType: !Ref InstanceType
Instance2:
Condition: Launch2
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref ImageId
InstanceType: !Ref InstanceType
Instance3:
Condition: Launch3
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref ImageId
InstanceType: !Ref InstanceType
Instance4:
Condition: Launch4
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref ImageId
InstanceType: !Ref InstanceType
Instance5:
Condition: Launch5
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref ImageId
InstanceType: !Ref InstanceType
Instance6:
Condition: Launch6
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref ImageId
InstanceType: !Ref InstanceType
Instance7:
Condition: Launch7
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref ImageId
InstanceType: !Ref InstanceType
Instance8:
Condition: Launch8
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref ImageId
InstanceType: !Ref InstanceType
Instance9:
Condition: Launch9
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref ImageId
InstanceType: !Ref InstanceType
Instance10:
Condition: Launch10
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref ImageId
InstanceType: !Ref InstanceType
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment