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
.