skip to Main Content

I want to list out the subnets only from specific VPC in my cloudformation parameters section:

VPC:
    Description: VPC Id
    Type: AWS::EC2::VPC::Id 

Subnets:
    Description: Select Subnets (Minimum 2)
    Type: List<AWS::EC2::Subnet::Id>

The above displays all subnets (from other subnets also) but I want to show only subnets from selected VPC.

Is it possible? What is the workaround for the same?

2

Answers


  1. Is it possible?

    No.

    What is the workaround for the same?

    There is none, unless you develop your own frotnend for deployment of templates.

    Login or Signup to reply.
  2. You can’t list them that way, but you can prevent deployment if the chosen subnets are not in the VPC by using a CloudFormation rule:

    {
      "Rules": {
        "IsSubnetInsideVPC": {
          "Assertions": [
            {
              "Assert": {
                "Fn::EachMemberEquals" : [
                  {
                    "Fn::ValueOfAll": [
                      "AWS::EC2::Subnet::Id",
                      "VpcId"
                    ]
                  },
                  {
                    "Ref": "VPC"
                  }
                ]
              },
              "AssertDescription": "One or more subnets you selected are not in the VPC"
            }
          ]
        }
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search