Skip to content

Instantly share code, notes, and snippets.

@mirhec
Created May 19, 2018 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirhec/dce96ace5b2df48f26a57af1f51f9893 to your computer and use it in GitHub Desktop.
Save mirhec/dce96ace5b2df48f26a57af1f51f9893 to your computer and use it in GitHub Desktop.
###################################################################################################
#### Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
####
#### Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file
#### except in compliance with the License. A copy of the License is located at
####
#### http://aws.amazon.com/apache2.0/
####
#### or in the "license" file accompanying this file. This file is distributed on an "AS IS"
#### BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#### License for the specific language governing permissions and limitations under the License.
###################################################################################################
###################################################################################################
#### By default, Elastic Beanstalk creates all of your application's compute and networking
#### resources in the default VPC. Use this template to create a custom VPC to isolate your
#### environment's resources in a private subnet with customizable security.
####
#### This template creates the following resources-
#### - A VPC with the IP range 172.31.0.0/16
#### - 2 public subnets
#### - An Internet gateway, and route table to allow environment resources to connect to each
#### other and the Internet.
####
###################################################################################################
Resources:
PublicVPC:
Type: 'AWS::EC2::VPC'
Properties:
CidrBlock: 172.31.0.0/16
Tags:
- Key: Name
Value: !Join [_, [!Ref 'AWS::StackName']]
PublicSubnet1:
Type: 'AWS::EC2::Subnet'
Properties:
VpcId: !Ref PublicVPC
AvailabilityZone:
Fn::Select:
- 0
- Fn::GetAZs: ""
CidrBlock: 172.31.0.0/24
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Join [_, [!Ref 'AWS::StackName',Public]]
PublicSubnet2:
Type: 'AWS::EC2::Subnet'
Properties:
AvailabilityZone:
Fn::Select:
- 1
- Fn::GetAZs: ""
VpcId: !Ref PublicVPC
CidrBlock: 172.31.1.0/24
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Join [_, [!Ref 'AWS::StackName',Public]]
InternetGateway:
Type: 'AWS::EC2::InternetGateway'
Properties:
Tags:
- Key: Name
Value: !Join [_, [!Ref 'AWS::StackName']]
GatewayToInternet:
Type: 'AWS::EC2::VPCGatewayAttachment'
Properties:
VpcId: !Ref PublicVPC
InternetGatewayId: !Ref InternetGateway
PublicRouteTable:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref PublicVPC
PublicRoute:
Type: 'AWS::EC2::Route'
DependsOn: GatewayToInternet
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
PublicSubnet1RouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
SubnetId: !Ref PublicSubnet1
RouteTableId: !Ref PublicRouteTable
PublicSubnet2RouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
SubnetId: !Ref PublicSubnet2
RouteTableId: !Ref PublicRouteTable
Outputs:
PublicVPCID:
Description: VPC ID
Value: !Ref "PublicVPC"
Export:
Name: BeanstalkPublicVPCID
PublicSubnet1ID:
Description: Public Subnet A ID
Value: !Ref "PublicSubnet1"
Export:
Name: BeanstalkPublicVPCSubnet1ID
PublicSubnet2ID:
Description: Public Subnet B ID
Value: !Ref "PublicSubnet2"
Export:
Name: BeanstalkPublicVPCSubnet2ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment