Link to existing AWS VPC ID in CloudFormation script when creating subnets

How do you reference the VPC ID of an existing VPC (which was created earlier in a separate CloudFormation script) in a CloudFormation script to create subnets in a VPC?

+4
source share
3 answers

In the template defining the VPC, specify the VPC ID in the output section:

"Outputs" : {
    "VPC" : {
        "Value" : {"Ref":"VPC"},
        "Description" : "VPC ID"
    },
    ...
}

In the template for the stack using VPC, define the parameter for the VPC ID:

"Parameters" : {
    "VPC" : {
        "Type" : "String",
    },
    ...
}

When creating this stack, call describe-stackon the stack defining the VPC to get the identifier from the outputs and pass it as a parameter VPCto create-stack.

+7
source

vpc ,

 "VpcId" : {
      "Type" : "AWS::EC2::VPC::Id",
      "Description" : "VpcId of your existing Virtual Private Cloud (VPC)",
      "ConstraintDescription" : "must be the VPC Id of an existing Virtual Private Cloud."
    },
+2

Link to it by name that is. "VpcId" : { "Ref" : "myVPC" }, In something like:

    {
   "Type" : "AWS::EC2::Subnet",
   "Properties" : {
      "AvailabilityZone" : String,
      "CidrBlock" : String,
      "Tags" : [ Resource Tag, ... ],
      "VpcId" : { "Ref" : String }
      }
    }  

Documentation here: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet.html

-2
source

All Articles