Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudFormation Inside VPC?

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?

like image 586
deitch Avatar asked Jun 13 '14 08:06

deitch


People also ask

Can I create a VPC with CloudFormation?

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.

How do I reference a VPC ID in CloudFormation?

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", }, ... }

What is the use of CloudFormation in AWS?

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.


1 Answers

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

like image 58
TravellingGuy Avatar answered Oct 16 '22 14:10

TravellingGuy