CloudFormation allowing users to use existing vs create new resources.

0

Hi, I have a scenario where I am developing a CloudFormation template for my users. So, I want to give my users the choice of using their existing VPS,Subnet,Security Group or they want to create a new one from the template. So, Is it possible to do this using the parameters where all the existing VPC ID would be listed along with the "create new" option in the same dropdown?

Thanks

질문됨 10달 전262회 조회
1개 답변
0

You can do this, but it can get quickly rather complex. I have done it like this Have parameters for everything. If you already have the resource, input your resource ID, and if you want to create a new one, leave it empty. For example NAT GW Elastic IP parameter

EipA:
    Type: String
    Description: Pre-allocated EIP ID for AZ-A (optional)
    Default: ''

Then in Conditions block, check if parameters has a value or if it is left empty

CreateEipA: !Equals [!Ref EipA, "" ] 

Then use the condition when creating (or not) creating the resource

  NatEipA:
    Type: AWS::EC2::EIP
    Condition: CreateEipA
    Properties:
      Domain: vpc

And finally when creating the NAT GW select if you want to use parameter value or reference to resource that was created.

  NatGwA:
    Type: AWS::EC2::NatGateway
    Properties:
      ConnectivityType: public
      SubnetId: !Ref PubSubnetA
      AllocationId: !If [ CreateEipA, !GetAtt NatEipA.AllocationId, !Ref EipA ]
profile picture
전문가
Kallu
답변함 10달 전
  • I got your point, but I was looking for something like infusing a "create new" option in the dropdown where it dynamically gather all the existing resources. VpcId: Type: AWS::EC2::VPC::Id Description: Select an existing VPC

  • Yes, it would be nice if you could input an empty value (or even better, insert your own values to list) when using parameter types like VPC::Id. Unfortunately that is not supported. I guess the closest thing you can get is to add an extra "yes/no" paramater to select if given resource should be used or create a new, but this isn't very intuitive for user.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠