I get that I can create resources using CloudFormation, and that I can also create a VPC using CloudFormation, along with the resources inside it.
Can I create a stack, using a CloudFormation template, inside a pre-existing VPC? For example, let's say that I have a VPC for my company, and there is a Services segment, some production segments (private and public), and maybe some Development segments.
I want to define each set of services - Services, production environment, Development environments - with its own CloudFormation template inside the VPC.
Can I do that?
Infrastructure as Code: CloudFormation allows us to create a "stack" of "resources" in one step. Resources are the things we create (EC2 Instances, VPCs, subnets, etc.), a set of these is called a stack. We can write a template that can easily stand up a network stack exactly as we like it in one step.
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", }, ... }
AWS CloudFormation is a service that gives developers and businesses an easy way to create a collection of related AWS and third-party resources, and provision and manage them in an orderly and predictable fashion.
Since this isn't documented very well, and all the examples I've seen (including Julio's) just use a string field prompting for manual entry of the VPC ID, here is the best way.
You can have your template prompt you with a drop-down showing all existing VPCs, allowing you to select one.
Use the AWS::EC2::VPC::Id property in your template:
{
"Parameters" : {
"VpcId" : {
"Type" : "AWS::EC2::VPC::Id",
"Description" : "VpcId of your existing Virtual Private Cloud (VPC)"
}
}
}
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html
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