-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathbbb-on-aws-network.template.yaml
139 lines (119 loc) · 4.11 KB
/
bbb-on-aws-network.template.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
AWSTemplateFormatVersion: '2010-09-09'
Description: >
This Cloudformation Template deploys the network for the application infrastructure.
Disclaimer: Not for production use. Demo and testing purposes only.
Parameters:
BBBVPCDEF:
Description: IP range (CIDR notation) for the VPC
Type: String
Default: 10.1.0.0/16
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$
BBBNumberOfAZs:
Description: Amount of Availability Zones to utilize
Type: Number
AllowedValues: [1, 2, 3]
Default: 3
Conditions:
BBBBuild2AZs: !Not [!Equals [!Ref BBBNumberOfAZs, 1]]
BBBBuild3AZs: !Equals [!Ref BBBNumberOfAZs, 3]
Resources:
BBBVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref BBBVPCDEF
EnableDnsSupport: true
EnableDnsHostnames: true
BBBIGW:
Type: AWS::EC2::InternetGateway
BBBIGWAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref BBBIGW
VpcId: !Ref BBBVPC
# Dynamic Application Subnets
BBBApplicationSubnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref BBBVPC
AvailabilityZone: !Select [0, !GetAZs '']
MapPublicIpOnLaunch: true
CidrBlock: !Select [0, !Cidr [!Ref BBBVPCDEF, 9, 8]]
BBBApplicationSubnet2:
Type: AWS::EC2::Subnet
Condition: BBBBuild2AZs
Properties:
VpcId: !Ref BBBVPC
AvailabilityZone: !Select [1, !GetAZs '']
MapPublicIpOnLaunch: true
CidrBlock: !Select [1, !Cidr [!Ref BBBVPCDEF, 9, 8]]
BBBApplicationSubnet3:
Type: AWS::EC2::Subnet
Condition: BBBBuild3AZs
Properties:
VpcId: !Ref BBBVPC
AvailabilityZone: !Select [2, !GetAZs '']
MapPublicIpOnLaunch: true
CidrBlock: !Select [2, !Cidr [!Ref BBBVPCDEF, 9, 8]]
# Dynamic Private Datastore Subnets
BBBDatastoreSubnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref BBBVPC
AvailabilityZone: !Select [0, !GetAZs '']
MapPublicIpOnLaunch: false
CidrBlock: !Select [6, !Cidr [!Ref BBBVPCDEF, 9, 8]]
BBBDatastoreSubnet2:
Type: AWS::EC2::Subnet
Condition: BBBBuild2AZs
Properties:
VpcId: !Ref BBBVPC
AvailabilityZone: !Select [1, !GetAZs '']
MapPublicIpOnLaunch: false
CidrBlock: !Select [7, !Cidr [!Ref BBBVPCDEF, 9, 8]]
BBBDatastoreSubnet3:
Type: AWS::EC2::Subnet
Condition: BBBBuild3AZs
Properties:
VpcId: !Ref BBBVPC
AvailabilityZone: !Select [2, !GetAZs '']
MapPublicIpOnLaunch: false
CidrBlock: !Select [8, !Cidr [!Ref BBBVPCDEF, 9, 8]]
# Route Tables
BBBRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref BBBVPC
BBBDefaultRoute:
Type: AWS::EC2::Route
DependsOn: BBBIGWAttachment
Properties:
RouteTableId: !Ref BBBRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref BBBIGW
BBBApplicationSubnet1RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref BBBRouteTable
SubnetId: !Ref BBBApplicationSubnet1
BBBApplicationSubnet2RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Condition: BBBBuild2AZs
Properties:
RouteTableId: !Ref BBBRouteTable
SubnetId: !Ref BBBApplicationSubnet2
BBBApplicationSubnet3RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Condition: BBBBuild3AZs
Properties:
RouteTableId: !Ref BBBRouteTable
SubnetId: !Ref BBBApplicationSubnet3
Outputs:
BBBVPC:
Description: VPC ID
Value: !Ref BBBVPC
BBBApplicationSubnets:
Description: A list of the application subnets
Value: !Join [ ",", [ !Ref BBBApplicationSubnet1, !If [ BBBBuild2AZs, !Ref BBBApplicationSubnet2, !Ref "AWS::NoValue"], !If [ BBBBuild3AZs, !Ref BBBApplicationSubnet3, !Ref "AWS::NoValue"]]]
BBBDatastoreSubnets:
Description: A list of the database subnets
Value: !Join [ ",", [ !Ref BBBDatastoreSubnet1, !If [ BBBBuild2AZs, !Ref BBBDatastoreSubnet2, !Ref "AWS::NoValue"], !If [ BBBBuild3AZs, !Ref BBBDatastoreSubnet3, !Ref "AWS::NoValue"]]]