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

asked 10 months ago250 views
1 Answer
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
EXPERT
Kallu
answered 10 months ago
  • 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.

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