I know that it is possible via the use of Conditions to conditionally (what else?) create resources.
I am trying to find a way though to conditionally create properties of resources;
in my case I am creating several EC2
instances in a subnet with default public ip assignment = false
.
Sometimes though for debugging purposes I want my instances to get public IPs.
Now I have to comment in/out the SG/Subnet and the NetworkInterfaces
properties below (those do not go together)
myEC2:
Type: AWS::EC2::Instance
Metadata:
Comment: My EC2 Instance
AWS::CloudFormation::Init:
config:
commands:
01_provision:
command:
!Sub |
sed -i "s/somestring/${somevar}/" /some/path/
CreationPolicy:
ResourceSignal:
Timeout: PT4M
Properties:
ImageId: !FindInMap [ MyAamiMap, 'myami', amiid ]
InstanceType: "t2.2xlarge"
# SubnetId: !Ref SBNDemo1
# SecurityGroupIds: [!Ref SGInternalDemo]
NetworkInterfaces:
- AssociatePublicIpAddress: "true"
DeviceIndex: "0"
GroupSet:
- Ref: "SGInternalDemo"
SubnetId:
Ref: "SBNDemo1"
UserData:
"Fn::Base64":
!Sub |
#!/bin/bash -xe
# Start cfn-init
/usr/local/bin/cfn-init -s ${AWS::StackId} -r myEC2 --region ${AWS::Region} || echo 'Failed to run cfn-init'
# All done so signal success
/usr/local/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource myEC2 --region ${AWS::Region}
Any suggestions?