ciinabox-ecs 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/templates/vpc.rb ADDED
@@ -0,0 +1,290 @@
1
+ require 'cfndsl'
2
+ require_relative '../ext/helper.rb'
3
+
4
+ CloudFormation {
5
+
6
+ # Template metadata
7
+ AWSTemplateFormatVersion "2010-09-09"
8
+ Description "ciinabox - VPC v#{ciinabox_version}"
9
+
10
+ # Global mappings
11
+ Mapping('EnvironmentType', Mappings['EnvironmentType'])
12
+ Mapping('NatAMI', natAMI)
13
+
14
+ # Resources
15
+ Resource("VPC") {
16
+ Type 'AWS::EC2::VPC'
17
+ Property('CidrBlock', FnJoin( "", [ FnFindInMap('EnvironmentType','ciinabox','NetworkPrefix'),".", FnFindInMap('EnvironmentType','ciinabox','StackOctet'), ".0.0/", FnFindInMap('EnvironmentType','ciinabox','StackMask') ] ))
18
+ Property('EnableDnsSupport', true)
19
+ Property('EnableDnsHostnames', true)
20
+ Property('Tags',[ {Key: 'Name', Value: stack_name }])
21
+ }
22
+
23
+ Resource("DHCPOptionSet") {
24
+ Type 'AWS::EC2::DHCPOptions'
25
+ Property('DomainName', dns_domain)
26
+ Property('DomainNameServers', ['AmazonProvidedDNS'])
27
+ }
28
+
29
+ Resource("DHCPOptionsAssociation") {
30
+ Type 'AWS::EC2::VPCDHCPOptionsAssociation'
31
+ Property('VpcId', Ref('VPC'))
32
+ Property('DhcpOptionsId', Ref('DHCPOptionSet'))
33
+ }
34
+
35
+ availability_zones.each do |az|
36
+ Resource("SubnetPublic#{az}") {
37
+ Type 'AWS::EC2::Subnet'
38
+ Property('VpcId', Ref('VPC'))
39
+ Property('CidrBlock', FnJoin( "", [ FnFindInMap('EnvironmentType','ciinabox','NetworkPrefix'), ".", FnFindInMap('EnvironmentType','ciinabox','StackOctet'), ".", vpc["SubnetOctet#{az}"], ".0/", FnFindInMap('EnvironmentType','ciinabox','SubnetMask') ] ))
40
+ Property('AvailabilityZone', FnSelect(azId[az], FnGetAZs(Ref( "AWS::Region" )) ))
41
+ Property('Tags',[
42
+ {
43
+ Key: 'Name', Value: FnJoin( "", [ "ciinabox-public#{az}"])
44
+ }
45
+ ])
46
+ }
47
+ end
48
+
49
+ Resource("InternetGateway") {
50
+ Type 'AWS::EC2::InternetGateway'
51
+ }
52
+
53
+ Resource("AttachGateway") {
54
+ Type 'AWS::EC2::VPCGatewayAttachment'
55
+ Property('VpcId', Ref('VPC'))
56
+ Property('InternetGatewayId', Ref('InternetGateway'))
57
+ }
58
+
59
+ Resource("NatGatewayEIP") {
60
+ Type 'AWS::EC2::EIP'
61
+ Property('Domain', 'vpc')
62
+ }
63
+
64
+ Resource("NatGateway") {
65
+ DependsOn 'AttachGateway'
66
+ Type 'AWS::EC2::NatGateway'
67
+ Property('AllocationId', FnGetAtt("NatGatewayEIP",'AllocationId'))
68
+ Property('SubnetId', Ref("SubnetPublic#{availability_zones[0]}"))
69
+ }
70
+
71
+ Resource("RouteTablePublic") {
72
+ Type 'AWS::EC2::RouteTable'
73
+ Property('VpcId', Ref('VPC'))
74
+ }
75
+
76
+ availability_zones.each do |az|
77
+ Resource("RouteTablePrivate#{az}") {
78
+ Type 'AWS::EC2::RouteTable'
79
+ Property('VpcId', Ref('VPC'))
80
+ }
81
+ end
82
+
83
+ availability_zones.each do |az|
84
+ Resource("SubnetRouteTableAssociationPublic#{az}") {
85
+ Type 'AWS::EC2::SubnetRouteTableAssociation'
86
+ Property('SubnetId', Ref("SubnetPublic#{az}"))
87
+ Property('RouteTableId', Ref('RouteTablePublic'))
88
+ }
89
+ end
90
+
91
+ Resource("PublicRouteOutToInternet") {
92
+ Type 'AWS::EC2::Route'
93
+ Property('RouteTableId', Ref("RouteTablePublic"))
94
+ Property('DestinationCidrBlock', '0.0.0.0/0')
95
+ Property('GatewayId',Ref("InternetGateway"))
96
+ }
97
+
98
+ availability_zones.each do |az|
99
+ Resource("RouteOutToInternet#{az}") {
100
+ Type 'AWS::EC2::Route'
101
+ Property('RouteTableId', Ref("RouteTablePrivate#{az}"))
102
+ Property('DestinationCidrBlock', '0.0.0.0/0')
103
+ Property('NatGatewayId',Ref("NatGateway"))
104
+ }
105
+ end
106
+
107
+ Resource("PublicNetworkAcl") {
108
+ Type 'AWS::EC2::NetworkAcl'
109
+ Property('VpcId', Ref('VPC'))
110
+ }
111
+
112
+ # Name => RuleNumber, Protocol, RuleAction, Egress, CidrBlock, PortRange From, PortRange To
113
+ acls = {
114
+ # Inbound
115
+ InboundTCPEphemeralPublicNetworkAclEntry: ['1001','6','allow','false','0.0.0.0/0','1024','65535'],
116
+ InboundUDPEphemeralPublicNetworkAclEntry: ['1002','17','allow','false','0.0.0.0/0','1024','65535'],
117
+ InboundSSHPublicNetworkAclEntry: ['1003','6','allow','false','0.0.0.0/0','22','22'],
118
+ InboundHTTPPublicNetworkAclEntry: ['1004','6','allow','false','0.0.0.0/0','80','80'],
119
+ InboundHTTPSPublicNetworkAclEntry: ['1005','6','allow','false','0.0.0.0/0','443','443'],
120
+ InboundNTPPublicNetworkAclEntry: ['1006','17','allow','false','0.0.0.0/0','123','123'],
121
+ InboundRDPPublicNetworkAclEntry: ['1007','6','allow','false','0.0.0.0/0','3389','3389'],
122
+
123
+ # Outbound
124
+ OutboundNetworkAclEntry: ['1001','-1','allow','true','0.0.0.0/0','0','65535']
125
+ }
126
+
127
+ # merges acls defined in config with acls in vpc template incrementing the RuleNumber by 1
128
+ if defined? customAcl
129
+ rule_number = 2000
130
+ customAcl.each do |acl|
131
+ rule_number += 1
132
+ acls.merge!((acl['Egress'] ? 'Outbound' : 'Inbound') + acl['Name'] + 'PublicNetworkAclEntry' =>
133
+ [rule_number,acl['Protocol'],'allow',acl['Egress'],acl['CidrBlock'] ? acl['CidrBlock'] : '0.0.0.0/0',acl['Port'],acl['Port']])
134
+ end
135
+ end
136
+
137
+ acls.each do |alcName,alcProperties|
138
+ Resource(alcName) {
139
+ Type 'AWS::EC2::NetworkAclEntry'
140
+ Property('NetworkAclId', Ref('PublicNetworkAcl'))
141
+ Property('RuleNumber', alcProperties[0])
142
+ Property('Protocol', alcProperties[1])
143
+ Property('RuleAction', alcProperties[2])
144
+ Property('Egress', alcProperties[3])
145
+ Property('CidrBlock', alcProperties[4])
146
+ Property('PortRange',{
147
+ From: alcProperties[5],
148
+ To: alcProperties[6]
149
+ })
150
+ }
151
+ end
152
+
153
+ availability_zones.each do |az|
154
+ Resource("SubnetNetworkAclAssociationPublic#{az}") {
155
+ Type 'AWS::EC2::SubnetNetworkAclAssociation'
156
+ Property('SubnetId', Ref("SubnetPublic#{az}"))
157
+ Property('NetworkAclId', Ref('PublicNetworkAcl'))
158
+ }
159
+ end
160
+
161
+ rules = []
162
+ opsAccess.each do |ip|
163
+ rules << { IpProtocol: 'tcp', FromPort: '22', ToPort: '22', CidrIp: ip }
164
+ rules << { IpProtocol: 'tcp', FromPort: '80', ToPort: '80', CidrIp: ip }
165
+ rules << { IpProtocol: 'tcp', FromPort: '443', ToPort: '443', CidrIp: ip }
166
+ rules << { IpProtocol: 'tcp', FromPort: '3389', ToPort: '3389', CidrIp: ip }
167
+ rules << { IpProtocol: 'tcp', FromPort: '5665', ToPort: '5665', CidrIp: ip }
168
+ rules << { IpProtocol: 'tcp', FromPort: '50000', ToPort: '50000', CidrIp: ip }
169
+ end
170
+
171
+ Resource("SecurityGroupOps") {
172
+ Type 'AWS::EC2::SecurityGroup'
173
+ Property('VpcId', Ref('VPC'))
174
+ Property('GroupDescription', 'Ops External Access')
175
+ Property('SecurityGroupIngress', rules)
176
+ }
177
+
178
+ rules = []
179
+ devAccess.each do |ip|
180
+ rules << { IpProtocol: 'tcp', FromPort: '22', ToPort: '22', CidrIp: ip }
181
+ rules << { IpProtocol: 'tcp', FromPort: '80', ToPort: '80', CidrIp: ip }
182
+ rules << { IpProtocol: 'tcp', FromPort: '443', ToPort: '443', CidrIp: ip }
183
+ rules << { IpProtocol: 'tcp', FromPort: '3389', ToPort: '3389', CidrIp: ip }
184
+ rules << { IpProtocol: 'tcp', FromPort: '5665', ToPort: '5665', CidrIp: ip }
185
+ rules << { IpProtocol: 'tcp', FromPort: '50000', ToPort: '50000', CidrIp: ip }
186
+ end
187
+
188
+ Resource("SecurityGroupDev") {
189
+ Type 'AWS::EC2::SecurityGroup'
190
+ Property('VpcId', Ref('VPC'))
191
+ Property('GroupDescription', 'Dev Team Access')
192
+ Property('SecurityGroupIngress', rules)
193
+ }
194
+
195
+
196
+ nat_allow_sg_ingress = [
197
+ {IpProtocol: 'tcp', FromPort: '22', ToPort: '22', CidrIp: FnJoin('', [Ref('NatGatewayEIP'), '/32'])},
198
+ {IpProtocol: 'tcp', FromPort: '80', ToPort: '80', CidrIp: FnJoin('', [Ref('NatGatewayEIP'), '/32'])},
199
+ {IpProtocol: 'tcp', FromPort: '443', ToPort: '443', CidrIp: FnJoin('', [Ref('NatGatewayEIP'), '/32'])},
200
+ {IpProtocol: 'tcp', FromPort: '8080', ToPort: '8080', CidrIp: FnJoin('', [Ref('NatGatewayEIP'), '/32'])},
201
+ {IpProtocol: 'tcp', FromPort: '50000', ToPort: '50000', CidrIp: FnJoin('', [Ref('NatGatewayEIP'), '/32'])},
202
+ {IpProtocol: 'tcp', FromPort: '3389', ToPort: '3389', CidrIp: FnJoin('', [Ref('NatGatewayEIP'), '/32'])},
203
+ {IpProtocol: 'tcp', FromPort: '5665', ToPort: '5665', CidrIp: FnJoin('', [Ref('NatGatewayEIP'), '/32'])},
204
+ {IpProtocol: 'tcp', FromPort: '5666', ToPort: '5666', CidrIp: FnJoin('', [Ref('NatGatewayEIP'), '/32'])},
205
+ {IpProtocol: 'tcp', FromPort: '5985', ToPort: '5985', CidrIp: FnJoin('', [Ref('NatGatewayEIP'), '/32'])},
206
+ ]
207
+
208
+ allow_sg_ingress = [
209
+ { IpProtocol: 'tcp', FromPort: '22', ToPort: '22', CidrIp: FnJoin( "", [ FnFindInMap('EnvironmentType','ciinabox','NetworkPrefix'),".", FnFindInMap('EnvironmentType','ciinabox','StackOctet'), ".0.0/",FnFindInMap('EnvironmentType','ciinabox','StackMask') ] ) },
210
+ { IpProtocol: 'tcp', FromPort: '80', ToPort: '80', CidrIp: FnJoin( "", [ FnFindInMap('EnvironmentType','ciinabox','NetworkPrefix'),".", FnFindInMap('EnvironmentType','ciinabox','StackOctet'), ".0.0/",FnFindInMap('EnvironmentType','ciinabox','StackMask') ] ) },
211
+ { IpProtocol: 'tcp', FromPort: '443', ToPort: '443', CidrIp: FnJoin( "", [ FnFindInMap('EnvironmentType','ciinabox','NetworkPrefix'),".", FnFindInMap('EnvironmentType','ciinabox','StackOctet'), ".0.0/",FnFindInMap('EnvironmentType','ciinabox','StackMask') ] ) },
212
+ { IpProtocol: 'tcp', FromPort: '3000', ToPort: '3000', CidrIp: FnJoin( "", [ FnFindInMap('EnvironmentType','ciinabox','NetworkPrefix'),".", FnFindInMap('EnvironmentType','ciinabox','StackOctet'), ".0.0/",FnFindInMap('EnvironmentType','ciinabox','StackMask') ] ) },
213
+ { IpProtocol: 'tcp', FromPort: '8000', ToPort: '8000', CidrIp: FnJoin( "", [ FnFindInMap('EnvironmentType','ciinabox','NetworkPrefix'),".", FnFindInMap('EnvironmentType','ciinabox','StackOctet'), ".0.0/",FnFindInMap('EnvironmentType','ciinabox','StackMask') ] ) },
214
+ { IpProtocol: 'tcp', FromPort: '8080', ToPort: '8080', CidrIp: FnJoin( "", [ FnFindInMap('EnvironmentType','ciinabox','NetworkPrefix'),".", FnFindInMap('EnvironmentType','ciinabox','StackOctet'), ".0.0/",FnFindInMap('EnvironmentType','ciinabox','StackMask') ] ) },
215
+ { IpProtocol: 'tcp', FromPort: '9000', ToPort: '9000', CidrIp: FnJoin( "", [ FnFindInMap('EnvironmentType','ciinabox','NetworkPrefix'),".", FnFindInMap('EnvironmentType','ciinabox','StackOctet'), ".0.0/",FnFindInMap('EnvironmentType','ciinabox','StackMask') ] ) },
216
+ { IpProtocol: 'tcp', FromPort: '50000', ToPort: '50000', CidrIp: FnJoin( "", [ FnFindInMap('EnvironmentType','ciinabox','NetworkPrefix'),".", FnFindInMap('EnvironmentType','ciinabox','StackOctet'), ".0.0/",FnFindInMap('EnvironmentType','ciinabox','StackMask') ] ) },
217
+ { IpProtocol: 'tcp', FromPort: '3389', ToPort: '3389', CidrIp: FnJoin( "", [ FnFindInMap('EnvironmentType','ciinabox','NetworkPrefix'),".", FnFindInMap('EnvironmentType','ciinabox','StackOctet'), ".0.0/",FnFindInMap('EnvironmentType','ciinabox','StackMask') ] ) },
218
+ { IpProtocol: 'tcp', FromPort: '5665', ToPort: '5665', CidrIp: FnJoin( "", [ FnFindInMap('EnvironmentType','ciinabox','NetworkPrefix'),".", FnFindInMap('EnvironmentType','ciinabox','StackOctet'), ".0.0/",FnFindInMap('EnvironmentType','ciinabox','StackMask') ] ) },
219
+ { IpProtocol: 'tcp', FromPort: '5666', ToPort: '5666', CidrIp: FnJoin( "", [ FnFindInMap('EnvironmentType','ciinabox','NetworkPrefix'),".", FnFindInMap('EnvironmentType','ciinabox','StackOctet'), ".0.0/",FnFindInMap('EnvironmentType','ciinabox','StackMask') ] ) },
220
+ { IpProtocol: 'tcp', FromPort: '5985', ToPort: '5985', CidrIp: FnJoin( "", [ FnFindInMap('EnvironmentType','ciinabox','NetworkPrefix'),".", FnFindInMap('EnvironmentType','ciinabox','StackOctet'), ".0.0/",FnFindInMap('EnvironmentType','ciinabox','StackMask') ] ) },
221
+ ]
222
+
223
+ Resource('SecurityGroupNatGateway'){
224
+ Type 'AWS::EC2::SecurityGroup'
225
+ Property('VpcId', Ref('VPC'))
226
+ Property('GroupDescription', 'Nat Gateway SG')
227
+ Property('SecurityGroupIngress', nat_allow_sg_ingress)
228
+ }
229
+
230
+ Resource("SecurityGroupBackplane") {
231
+ Type 'AWS::EC2::SecurityGroup'
232
+ Property('VpcId', Ref('VPC'))
233
+ Property('GroupDescription', 'Backplane SG')
234
+ Property('SecurityGroupIngress', allow_sg_ingress)
235
+ }
236
+
237
+ route_tables = []
238
+ availability_zones.each do |az|
239
+ route_tables << Ref("RouteTablePrivate#{az}")
240
+ end
241
+ Resource("S3VPCEndpoint") {
242
+ Type "AWS::EC2::VPCEndpoint"
243
+ Property("PolicyDocument", {
244
+ Version:"2012-10-17",
245
+ Statement:[{
246
+ Effect:"Allow",
247
+ Principal: "*",
248
+ Action:["*"],
249
+ Resource:["arn:aws:s3:::*"]
250
+ }]
251
+ })
252
+ Property("RouteTableIds", route_tables)
253
+ Property("ServiceName", FnJoin("", [ "com.amazonaws.", Ref("AWS::Region"), ".s3"]))
254
+ Property("VpcId", Ref('VPC'))
255
+ }
256
+
257
+
258
+ Output("VPCId") {
259
+ Value(Ref('VPC'))
260
+ }
261
+
262
+ availability_zones.each do |az|
263
+ Output("RouteTablePrivate#{az}") {
264
+ Value(Ref("RouteTablePrivate#{az}"))
265
+ }
266
+ end
267
+
268
+ availability_zones.each do |az|
269
+ Output("SubnetPublic#{az}") {
270
+ Value(Ref("SubnetPublic#{az}"))
271
+ }
272
+ end
273
+
274
+ Output('SecurityGroupNatGateway') {
275
+ Value(Ref('SecurityGroupNatGateway'))
276
+ }
277
+
278
+ Output("SecurityGroupBackplane") {
279
+ Value(Ref('SecurityGroupBackplane'))
280
+ }
281
+
282
+ Output("SecurityGroupOps") {
283
+ Value(Ref('SecurityGroupOps'))
284
+ }
285
+
286
+ Output("SecurityGroupDev") {
287
+ Value(Ref('SecurityGroupDev'))
288
+ }
289
+
290
+ }
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ciinabox-ecs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
+ platform: ruby
6
+ authors:
7
+ - Base2Services
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cfndsl
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.15.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.15.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: cfn_manage
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.7
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.7
55
+ - !ruby/object:Gem::Dependency
56
+ name: deep_merge
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubyzip
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.2'
83
+ description: ''
84
+ email: itsupport@base2services.com
85
+ executables:
86
+ - ciinabox-ecs
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - Gemfile
91
+ - LICENSE.txt
92
+ - README.md
93
+ - Rakefile
94
+ - bin/Rakefile
95
+ - bin/ciinabox-ecs
96
+ - bin/ciinabox-ecs.rb
97
+ - config/ciinabox_params.yml.erb
98
+ - config/default_lambdas.yml
99
+ - config/default_params.yml
100
+ - config/default_params.yml.example
101
+ - config/default_services.yml
102
+ - ext/common_helper.rb
103
+ - ext/config/managed_policies.yml
104
+ - ext/helper.rb
105
+ - ext/policies.rb
106
+ - ext/zip_helper.rb
107
+ - lambdas/acm_issuer_validator/lib/install.sh
108
+ - templates/bastion.rb
109
+ - templates/ciinabox.rb
110
+ - templates/ecs-cluster.rb
111
+ - templates/ecs-services.rb
112
+ - templates/lambdas.rb
113
+ - templates/services/bitbucket.rb
114
+ - templates/services/drone.rb
115
+ - templates/services/hawtio.rb
116
+ - templates/services/icinga2.rb
117
+ - templates/services/jenkins.rb
118
+ - templates/services/nexus.rb
119
+ - templates/vpc.rb
120
+ homepage: https://github.com/base2Services/ciinabox-ecs
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.6.12
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Manage ciinabox on Aws Ecs
144
+ test_files: []