How do you reference the VPC Id of an existing VPC (which has been created before in a separate CloudFormation script) in CloudFormation script in order to create subnets in the VPC?
In the template defining the VPC, include the VPC ID in the outputs section:
"Outputs" : {
"VPC" : {
"Value" : {"Ref":"VPC"},
"Description" : "VPC ID"
},
...
}
In the template for the stack using the VPC, define a parameter for the VPC ID:
"Parameters" : {
"VPC" : {
"Type" : "String",
},
...
}
When creating this stack, call describe-stack
on the VPC-defining stack to get the ID from outputs, and pass it as the VPC
parameter to create-stack
.
Or get vpc id from input, such as
"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."
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With