CloudFormation Inside VPC?

deitch picture deitch · Jun 13, 2014 · Viewed 9.7k times · Source

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?

Answer

TravellingGuy picture TravellingGuy · Dec 6, 2014

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