creating duplicate resources in the same Account using Cloudformation


BuildEnvironment: Type: String AllowedValues: - dev - prod - qa - qa3

InstanceSGFullAccess: Type: AWS::EC2::SecurityGroup Properties: GroupName: "Allow full access from local" GroupDescription: Allows full inbout and outbound access to local private address range VpcId: Fn::ImportValue: !Sub "${AWSEnvironment}-VPCID" SecurityGroupIngress: - IpProtocol: -1 CidrIp:
SecurityGroupEgress: - IpProtocol: -1 CidrIp: Tags: - Key: "keyname1" Value: "value1"

InstanceSGOutBoundAccess: Type: AWS::EC2::SecurityGroup Properties: GroupName: "Allow outbound" GroupDescription: Allow full outbound access VpcId: Fn::ImportValue: !Sub "${AWSEnvironment}-VPCID" SecurityGroupEgress: - IpProtocol: -1 CidrIp: - IpProtocol: -1 CidrIpv6: ::/0

MHCLaunchTemplate: Type: AWS::EC2::LaunchTemplate Properties: LaunchTemplateName: !Sub MRxAssist-${AWSEnvironment} LaunchTemplateData: IamInstanceProfile: Arn: !Ref IAMInstanceProfile DisableApiTermination: true ImageId: !Ref AmiId InstanceType: !Ref InstanceType KeyName: !Ref SSHKey SecurityGroupIds: - !Ref InstanceSGFullAccess - !Ref InstanceSGOutBoundAccess - !ImportValue 'Fn::Sub': '${AWSEnvironment}-OracleAccessSecurityGroup' UserData: ......

i want to make -> InstanceSGFullAccess and InstanceSGOutBoundAccess dynamic by appending the environment parameters i.e. QA or QA3 in the same account. and referring them into the MHCLaunchTemplate, so that i don't get "Resource already exists error" when running QA first and QA3 second using the same cloudformation script.

asked 9 months ago215 views
1 Answer
Accepted Answer

You can use the !Sub command to append QA or QA3 to the GroupName.

profile pictureAWS
answered 9 months ago
profile picture
reviewed 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions