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 个月前269 查看次数
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.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则