rubycfn 0.4.10 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/Gemfile.lock +1 -1
- data/README.md +43 -67
- data/bin/rubycfn +17 -73
- data/lib/cli_methods.rb +2 -2
- data/lib/rubycfn/version.rb +1 -1
- data/templates/.env +2 -0
- data/templates/.env.acceptance +1 -0
- data/templates/.env.dependencies.rspec +6 -0
- data/templates/.env.development +1 -0
- data/templates/.env.production +1 -0
- data/templates/.env.rspec +1 -0
- data/templates/.env.test +1 -0
- data/templates/{.gitignore.erb → .gitignore} +3 -0
- data/templates/{.rubocop.yml.erb → .rubocop.yml} +14 -1
- data/templates/{Gemfile.erb → Gemfile} +0 -1
- data/templates/README.md +57 -0
- data/templates/{Rakefile.erb → Rakefile} +15 -8
- data/templates/bootstrap/dependency_stack.rb +49 -0
- data/templates/config.yaml +65 -0
- data/templates/lib/aws_helper/aws_sdk.rb +30 -0
- data/templates/{compiler.rb.erb → lib/aws_helper/compiler.rb} +15 -9
- data/templates/{dependencies.rb.erb → lib/aws_helper/dependencies.rb} +5 -3
- data/templates/{deploy.rb.erb → lib/aws_helper/deploy.rb} +6 -4
- data/templates/lib/aws_helper/helpers.rb +3 -0
- data/templates/{main_aws_helper.rb.erb → lib/aws_helper/main.rb} +0 -0
- data/templates/{upload_stack.rb.erb → lib/aws_helper/upload_stack.rb} +15 -6
- data/templates/lib/core/applications.rb +479 -0
- data/templates/lib/core/assume_role.rb +40 -0
- data/templates/lib/core/classes.rb +25 -0
- data/templates/{core_compile.rb.erb → lib/core/compile.rb} +1 -0
- data/templates/lib/core/dependencies.rb +22 -0
- data/templates/{core_deploy.rb.erb → lib/core/deploy.rb} +20 -10
- data/templates/lib/core/git.rb +15 -0
- data/templates/lib/core/init.rb +173 -0
- data/templates/{core_upload.rb.erb → lib/core/upload.rb} +0 -0
- data/templates/{main.rb.erb → lib/main.rb} +8 -6
- data/templates/lib/shared_concerns/global_variables.rb +56 -0
- data/templates/{helper_methods.rb.erb → lib/shared_concerns/helper_functions.rb} +0 -0
- data/templates/lib/shared_concerns/helper_methods.rb +3 -0
- data/templates/{shared_methods.rb.erb → lib/shared_concerns/shared_methods.rb} +9 -0
- data/templates/lib/stacks/acm_stack/certificate_manager.rb +79 -0
- data/templates/{new_stack.rb.erb → lib/stacks/acm_stack/main.rb} +3 -4
- data/templates/lib/stacks/ecs_stack/ecs_cluster.rb +344 -0
- data/templates/lib/stacks/ecs_stack/lifecycle_hook.rb +188 -0
- data/templates/lib/stacks/ecs_stack/load_balancer.rb +68 -0
- data/templates/{ecs_stack.rb.erb → lib/stacks/ecs_stack/main.rb} +2 -1
- data/templates/{project_stack.rb.erb → lib/stacks/parent_stack/main.rb} +2 -2
- data/templates/lib/stacks/parent_stack/parent.rb +18 -0
- data/templates/lib/stacks/vpc_stack/infra_vpc.rb +193 -0
- data/templates/{vpc_stack.rb.erb → lib/stacks/vpc_stack/main.rb} +1 -2
- data/templates/{parent_stack_spec.rb.erb → spec/lib/parent_spec.rb} +2 -5
- data/templates/{spec_helper.rb.erb → spec/spec_helper.rb} +2 -2
- metadata +54 -44
- data/format.vim +0 -3
- data/templates/.env.erb +0 -4
- data/templates/.env.production.erb +0 -6
- data/templates/.env.rspec.erb +0 -6
- data/templates/.env.test.erb +0 -6
- data/templates/.gitlab-ci.yml.erb +0 -75
- data/templates/aws_sdk.rb.erb +0 -18
- data/templates/core_diff.rb.erb +0 -59
- data/templates/ecs_stack_concern.rb.erb +0 -20
- data/templates/global_variables.rb.erb +0 -16
- data/templates/helpers.rb.erb +0 -7
- data/templates/new_concern.rb.erb +0 -10
- data/templates/project_concern.rb.erb +0 -26
- data/templates/subnets.rb.erb +0 -18
- data/templates/vpc_concerns.rb.erb +0 -87
- data/templates/vpc_spec.rb.erb +0 -39
@@ -0,0 +1,193 @@
|
|
1
|
+
module VpcStack
|
2
|
+
module InfraVpc
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
included do
|
5
|
+
vpc_subnets = infra_config["subnets"]
|
6
|
+
|
7
|
+
variable :cidr_block,
|
8
|
+
default: "10.0.0.0/16",
|
9
|
+
value: infra_config["environments"][environment]["vpc_cidr"]
|
10
|
+
|
11
|
+
resource :infra_vpc,
|
12
|
+
type: "AWS::EC2::VPC" do |r|
|
13
|
+
r.property(:cidr_block) { cidr_block }
|
14
|
+
r.property(:enable_dns_support) { true }
|
15
|
+
r.property(:enable_dns_hostnames) { true }
|
16
|
+
r.property(:tags) do
|
17
|
+
[
|
18
|
+
{
|
19
|
+
"Key": "Name",
|
20
|
+
"Value": "infra_#{environment}_vpc"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"Key": "Environment",
|
24
|
+
"Value": environment.to_s
|
25
|
+
}
|
26
|
+
]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
resource :infra_internet_gateway,
|
31
|
+
type: "AWS::EC2::InternetGateway"
|
32
|
+
|
33
|
+
resource :infra_route,
|
34
|
+
type: "AWS::EC2::Route" do |r|
|
35
|
+
r.property(:destination_cidr_block) { "0.0.0.0/0" }
|
36
|
+
r.property(:gateway_id) { :infra_internet_gateway.ref }
|
37
|
+
r.property(:route_table_id) { :infra_route_table.ref }
|
38
|
+
end
|
39
|
+
|
40
|
+
resource :infra_route_table,
|
41
|
+
type: "AWS::EC2::RouteTable" do |r|
|
42
|
+
r.property(:vpc_id) { :infra_vpc.ref }
|
43
|
+
r.property(:tags) do
|
44
|
+
[
|
45
|
+
{
|
46
|
+
"Key": "Name",
|
47
|
+
"Value": "Infra #{environment} Public Route Table"
|
48
|
+
},
|
49
|
+
{
|
50
|
+
"Key": "Environment",
|
51
|
+
"Value": environment.to_s
|
52
|
+
}
|
53
|
+
]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
resource :infra_private_route_table,
|
58
|
+
amount: 3,
|
59
|
+
type: "AWS::EC2::RouteTable" do |r, index|
|
60
|
+
r.property(:vpc_id) { :infra_vpc.ref }
|
61
|
+
r.property(:tags) do
|
62
|
+
[
|
63
|
+
{
|
64
|
+
"Key": "Name",
|
65
|
+
"Value": "Infra #{environment} Private Route Table #{index.zero? && "" || index + 1}"
|
66
|
+
},
|
67
|
+
{
|
68
|
+
"Key": "Environment",
|
69
|
+
"Value": environment.to_s
|
70
|
+
}
|
71
|
+
]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
resource :infra_vpc_gateway_attachment,
|
76
|
+
type: "AWS::EC2::VPCGatewayAttachment" do |r|
|
77
|
+
r.property(:internet_gateway_id) { :infra_internet_gateway.ref }
|
78
|
+
r.property(:vpc_id) { :infra_vpc.ref }
|
79
|
+
end
|
80
|
+
|
81
|
+
vpc_subnets.each_with_index do |subnet, _subnet_count|
|
82
|
+
subnet.each do |subnet_name, arguments|
|
83
|
+
resource "infra_#{subnet_name}_subnet".cfnize,
|
84
|
+
type: "AWS::EC2::Subnet",
|
85
|
+
amount: 3 do |r, index|
|
86
|
+
subnet_cidr = [
|
87
|
+
:infra_vpc.ref(:cidr_block),
|
88
|
+
(3 * arguments["offset"]).to_s,
|
89
|
+
(Math.log(256) / Math.log(2)).floor.to_s
|
90
|
+
].fncidr.fnselect(index + (3 * arguments["offset"]) - 3)
|
91
|
+
|
92
|
+
r.property(:availability_zone) do
|
93
|
+
{
|
94
|
+
"Fn::GetAZs": ""
|
95
|
+
}.fnselect(index)
|
96
|
+
end
|
97
|
+
r.property(:cidr_block) { subnet_cidr }
|
98
|
+
r.property(:map_public_ip_on_launch) { arguments["public"] }
|
99
|
+
r.property(:tags) do
|
100
|
+
[
|
101
|
+
{
|
102
|
+
"Key": "Name",
|
103
|
+
"Value": "#{environment}_#{subnet_name}_#{index + 1}".cfnize
|
104
|
+
},
|
105
|
+
{
|
106
|
+
"Key": "Team",
|
107
|
+
"Value": arguments["owner"]
|
108
|
+
},
|
109
|
+
{
|
110
|
+
"Key": "resource_type",
|
111
|
+
"Value": subnet_name.to_s.cfnize
|
112
|
+
}
|
113
|
+
]
|
114
|
+
end
|
115
|
+
r.property(:vpc_id) { :infra_vpc.ref }
|
116
|
+
|
117
|
+
if arguments["output_cidr"]
|
118
|
+
cidr_output_name = "#{subnet_name}_subnet#{index.positive? ? (index + 1) : ""}_cidr".cfnize
|
119
|
+
|
120
|
+
output cidr_output_name,
|
121
|
+
value: subnet_cidr
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
if arguments["public"]
|
126
|
+
resource "infra_#{subnet_name}_subnet_route_table_association".cfnize,
|
127
|
+
amount: 3,
|
128
|
+
type: "AWS::EC2::SubnetRouteTableAssociation" do |r, index|
|
129
|
+
r.property(:route_table_id) { :infra_route_table.ref }
|
130
|
+
r.property(:subnet_id) { "infra_#{subnet_name}_subnet#{index.zero? && "" || index + 1}".cfnize.ref }
|
131
|
+
end
|
132
|
+
else
|
133
|
+
resource "infra_#{subnet_name}_subnet_route_table_association".cfnize,
|
134
|
+
amount: 3,
|
135
|
+
type: "AWS::EC2::SubnetRouteTableAssociation" do |r, index|
|
136
|
+
r.property(:route_table_id) { "infra_private_route_table#{index.zero? && "" || index + 1}".cfnize.ref }
|
137
|
+
r.property(:subnet_id) { "infra_#{subnet_name}_subnet#{index.zero? && "" || index + 1}".cfnize.ref }
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
# Generate outputs for these subnets
|
142
|
+
3.times do |i|
|
143
|
+
output_name = "#{subnet_name}_subnet#{i.positive? ? (i + 1) : ""}_name".cfnize
|
144
|
+
|
145
|
+
output output_name,
|
146
|
+
value: "infra_#{subnet_name}_subnet#{i.positive? ? (i + 1) : ""}".cfnize.ref
|
147
|
+
end
|
148
|
+
|
149
|
+
# Deploy NAT Gateway in subnet marked with "deploy_nat": true
|
150
|
+
if arguments["deploy_nat"]
|
151
|
+
resource "infra_#{subnet_name}_elastic_ip".cfnize,
|
152
|
+
amount: 3,
|
153
|
+
type: "AWS::EC2::EIP" do |r, _|
|
154
|
+
r.property(:domain) { "vpc" }
|
155
|
+
end
|
156
|
+
|
157
|
+
resource "infra_#{subnet_name}_nat_gateway".cfnize,
|
158
|
+
amount: 3,
|
159
|
+
type: "AWS::EC2::NatGateway" do |r, index|
|
160
|
+
r.property(:allocation_id) { "infra_#{subnet_name}_elastic_ip#{index.zero? && "" || index + 1}".cfnize.ref(:allocation_id) }
|
161
|
+
r.property(:subnet_id) { "infra_#{subnet_name}_subnet#{index.zero? && "" || index + 1}".cfnize.ref }
|
162
|
+
end
|
163
|
+
|
164
|
+
resource :infra_nat_gateway_route,
|
165
|
+
depends_on: :infra_vpc_gateway_attachment,
|
166
|
+
amount: 3,
|
167
|
+
type: "AWS::EC2::Route" do |r, index|
|
168
|
+
r.depends_on [
|
169
|
+
"InfraEc2PublicNatGateway#{index.zero? && "" || index + 1}"
|
170
|
+
]
|
171
|
+
r.property(:destination_cidr_block) { "0.0.0.0/0" }
|
172
|
+
r.property(:nat_gateway_id) { "infra_#{subnet_name}_nat_gateway#{index.zero? && "" || index + 1}".cfnize.ref }
|
173
|
+
r.property(:route_table_id) { "infra_private_route_table#{index.zero? && "" || index + 1}".cfnize.ref }
|
174
|
+
end
|
175
|
+
|
176
|
+
# Generate outputs for NAT gateway
|
177
|
+
3.times do |i|
|
178
|
+
output_name = "nat_gateway_#{subnet_name}#{i.positive? ? (i + 1) : ""}"
|
179
|
+
|
180
|
+
output output_name,
|
181
|
+
value: "infra_#{subnet_name}_nat_gateway#{i.positive? ? (i + 1) : ""}".cfnize.ref
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
output :vpc_cidr,
|
188
|
+
value: :infra_vpc.ref(:cidr_block)
|
189
|
+
output :vpc_id,
|
190
|
+
value: :infra_vpc.ref
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module VpcStack
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
include Rubycfn
|
4
|
-
|
5
4
|
included do
|
6
5
|
include Concerns::GlobalVariables
|
7
6
|
include Concerns::SharedMethods
|
8
|
-
include VpcStack::
|
7
|
+
include VpcStack::InfraVpc
|
9
8
|
|
10
9
|
description generate_stack_description("VpcStack")
|
11
10
|
end
|
@@ -8,10 +8,10 @@ module ParentSpec
|
|
8
8
|
include Rubycfn
|
9
9
|
|
10
10
|
included do
|
11
|
-
description "
|
11
|
+
description "Infra Stack RSpec"
|
12
12
|
include Concerns::GlobalVariables
|
13
13
|
include Concerns::SharedMethods
|
14
|
-
include
|
14
|
+
include InfraStack::Parent
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -23,15 +23,12 @@ describe ParentSpec do
|
|
23
23
|
|
24
24
|
context "Renders template" do
|
25
25
|
subject { template }
|
26
|
-
|
27
26
|
it { should have_key "Resources" }
|
28
27
|
|
29
28
|
context "Has Required Resources" do
|
30
29
|
let(:resources) { template["Resources"] }
|
31
30
|
subject { resources }
|
32
31
|
|
33
|
-
it { should have_key "VpcStack" }
|
34
|
-
it { should have_key "EcsStack" }
|
35
32
|
end
|
36
33
|
end
|
37
34
|
end
|
@@ -22,7 +22,7 @@ RSpec.configure do |config|
|
|
22
22
|
config.filter_run_excluding broken: true
|
23
23
|
config.filter_run_excluding turn_off: true
|
24
24
|
config.filter_run focus: true
|
25
|
-
config.run_all_when_everything_filtered = true
|
26
25
|
config.filter_run_excluding :slow unless ENV["SLOW_SPECS"]
|
27
26
|
config.filter_run_excluding :debug unless ENV["DEBUG_SPECS"]
|
28
|
-
|
27
|
+
config.run_all_when_everything_filtered = true
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubycfn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis Vink
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: neatjson
|
@@ -265,7 +265,6 @@ files:
|
|
265
265
|
- README.md
|
266
266
|
- Rakefile
|
267
267
|
- bin/rubycfn
|
268
|
-
- format.vim
|
269
268
|
- lib/cli_methods.rb
|
270
269
|
- lib/monkeypatch.rb
|
271
270
|
- lib/rubycfn.rb
|
@@ -273,42 +272,53 @@ files:
|
|
273
272
|
- rubycfn.gemspec
|
274
273
|
- spec/lib/rubycfn_spec.rb
|
275
274
|
- spec/spec_helper.rb
|
276
|
-
- templates/.env
|
277
|
-
- templates/.env.
|
278
|
-
- templates/.env.rspec
|
279
|
-
- templates/.env.
|
280
|
-
- templates/.
|
281
|
-
- templates/.
|
282
|
-
- templates/.
|
283
|
-
- templates
|
284
|
-
- templates
|
285
|
-
- templates/
|
286
|
-
- templates/
|
287
|
-
- templates/
|
288
|
-
- templates/
|
289
|
-
- templates/
|
290
|
-
- templates/
|
291
|
-
- templates/
|
292
|
-
- templates/
|
293
|
-
- templates/
|
294
|
-
- templates/
|
295
|
-
- templates/
|
296
|
-
- templates/
|
297
|
-
- templates/
|
298
|
-
- templates/
|
299
|
-
- templates/
|
300
|
-
- templates/
|
301
|
-
- templates/
|
302
|
-
- templates/
|
303
|
-
- templates/
|
304
|
-
- templates/
|
305
|
-
- templates/
|
306
|
-
- templates/
|
307
|
-
- templates/
|
308
|
-
- templates/
|
309
|
-
- templates/
|
310
|
-
- templates/
|
311
|
-
- templates/
|
275
|
+
- templates/.env
|
276
|
+
- templates/.env.acceptance
|
277
|
+
- templates/.env.dependencies.rspec
|
278
|
+
- templates/.env.development
|
279
|
+
- templates/.env.production
|
280
|
+
- templates/.env.rspec
|
281
|
+
- templates/.env.test
|
282
|
+
- templates/.gitignore
|
283
|
+
- templates/.rubocop.yml
|
284
|
+
- templates/Gemfile
|
285
|
+
- templates/README.md
|
286
|
+
- templates/Rakefile
|
287
|
+
- templates/bootstrap/dependency_stack.rb
|
288
|
+
- templates/config.yaml
|
289
|
+
- templates/lib/aws_helper/aws_sdk.rb
|
290
|
+
- templates/lib/aws_helper/compiler.rb
|
291
|
+
- templates/lib/aws_helper/dependencies.rb
|
292
|
+
- templates/lib/aws_helper/deploy.rb
|
293
|
+
- templates/lib/aws_helper/helpers.rb
|
294
|
+
- templates/lib/aws_helper/main.rb
|
295
|
+
- templates/lib/aws_helper/upload_stack.rb
|
296
|
+
- templates/lib/core/applications.rb
|
297
|
+
- templates/lib/core/assume_role.rb
|
298
|
+
- templates/lib/core/classes.rb
|
299
|
+
- templates/lib/core/compile.rb
|
300
|
+
- templates/lib/core/dependencies.rb
|
301
|
+
- templates/lib/core/deploy.rb
|
302
|
+
- templates/lib/core/git.rb
|
303
|
+
- templates/lib/core/init.rb
|
304
|
+
- templates/lib/core/upload.rb
|
305
|
+
- templates/lib/main.rb
|
306
|
+
- templates/lib/shared_concerns/global_variables.rb
|
307
|
+
- templates/lib/shared_concerns/helper_functions.rb
|
308
|
+
- templates/lib/shared_concerns/helper_methods.rb
|
309
|
+
- templates/lib/shared_concerns/shared_methods.rb
|
310
|
+
- templates/lib/stacks/acm_stack/certificate_manager.rb
|
311
|
+
- templates/lib/stacks/acm_stack/main.rb
|
312
|
+
- templates/lib/stacks/ecs_stack/ecs_cluster.rb
|
313
|
+
- templates/lib/stacks/ecs_stack/lifecycle_hook.rb
|
314
|
+
- templates/lib/stacks/ecs_stack/load_balancer.rb
|
315
|
+
- templates/lib/stacks/ecs_stack/main.rb
|
316
|
+
- templates/lib/stacks/parent_stack/main.rb
|
317
|
+
- templates/lib/stacks/parent_stack/parent.rb
|
318
|
+
- templates/lib/stacks/vpc_stack/infra_vpc.rb
|
319
|
+
- templates/lib/stacks/vpc_stack/main.rb
|
320
|
+
- templates/spec/lib/parent_spec.rb
|
321
|
+
- templates/spec/spec_helper.rb
|
312
322
|
homepage: https://github.com/dennisvink/rubycfn
|
313
323
|
licenses:
|
314
324
|
- MIT
|
@@ -337,8 +347,8 @@ test_files:
|
|
337
347
|
- rubycfn.gemspec
|
338
348
|
- spec/lib/rubycfn_spec.rb
|
339
349
|
- spec/spec_helper.rb
|
340
|
-
- templates/.env.rspec
|
341
|
-
- templates/.env.
|
342
|
-
- templates
|
343
|
-
- templates/
|
344
|
-
- templates/
|
350
|
+
- templates/.env.dependencies.rspec
|
351
|
+
- templates/.env.rspec
|
352
|
+
- templates/.env.test
|
353
|
+
- templates/spec/lib/parent_spec.rb
|
354
|
+
- templates/spec/spec_helper.rb
|
data/format.vim
DELETED
data/templates/.env.erb
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
# ENV vars for production environment
|
2
|
-
CLOUD_TRAIL_MONITOR_SNS_RECIPIENTS="changeme@example.com,changemetoo@example.com"
|
3
|
-
ROOT_MONITOR_SNS_RECIPIENTS="changeme@example.com,changemetoo@example.com"
|
4
|
-
VPC_CIDR_BLOCK="10.200.0.0/16"
|
5
|
-
ARTIFACT_BUCKET="my-awesome-cloudformation-artifact-bucket-for-production"
|
6
|
-
STACK_NAME="production"
|
data/templates/.env.rspec.erb
DELETED
data/templates/.env.test.erb
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
# ENV vars for test environment
|
2
|
-
CLOUD_TRAIL_MONITOR_SNS_RECIPIENTS="changeme@example.com,changemetoo@example.com"
|
3
|
-
ROOT_MONITOR_SNS_RECIPIENTS="changeme@example.com,changemetoo@example.com"
|
4
|
-
VPC_CIDR_BLOCK="10.100.0.0/16"
|
5
|
-
ARTIFACT_BUCKET="my-awesome-cloudformation-artifact-bucket"
|
6
|
-
STACK_NAME="test"
|
@@ -1,75 +0,0 @@
|
|
1
|
-
image: rubycfn/rubycfn:latest
|
2
|
-
|
3
|
-
before_script:
|
4
|
-
- bundle
|
5
|
-
|
6
|
-
variables:
|
7
|
-
CFN_ARTIFACT_BUCKET: "my-awesome-cloudformation-bucket"
|
8
|
-
STAGING_AWS_REGION: eu-west-1
|
9
|
-
PROD_AWS_REGION: eu-west-1
|
10
|
-
|
11
|
-
stages:
|
12
|
-
- build
|
13
|
-
- test
|
14
|
-
- upload
|
15
|
-
- staging
|
16
|
-
- production
|
17
|
-
|
18
|
-
build:
|
19
|
-
stage: build
|
20
|
-
variables:
|
21
|
-
ARTIFACT_BUCKET: ${CFN_ARTIFACT_BUCKET}
|
22
|
-
script:
|
23
|
-
- export SLACK_WEBHOOK=$K8S_SECRET_SLACK_POST_HOOK
|
24
|
-
- ENVIRONMENT="test" rake compile
|
25
|
-
- ENVIRONMENT="production" rake compile
|
26
|
-
- rubocop
|
27
|
-
- cfn_nag_scan --input-path build/ || true
|
28
|
-
artifacts:
|
29
|
-
paths:
|
30
|
-
- build/
|
31
|
-
|
32
|
-
test:
|
33
|
-
stage: test
|
34
|
-
script:
|
35
|
-
- rake spec
|
36
|
-
dependencies:
|
37
|
-
- build
|
38
|
-
|
39
|
-
upload:
|
40
|
-
stage: upload
|
41
|
-
variables:
|
42
|
-
ARTIFACT_BUCKET: ${CFN_ARTIFACT_BUCKET}
|
43
|
-
AWS_REGION: ${STAGING_AWS_REGION}
|
44
|
-
script:
|
45
|
-
- export AWS_SECRET_ACCESS_KEY=$K8S_SECRET_AWS_SECRET_ACCESS_KEY
|
46
|
-
- export AWS_ACCESS_KEY_ID=$K8S_SECRET_AWS_ACCESS_KEY_ID
|
47
|
-
- ENVIRONMENT="test" rake upload
|
48
|
-
- ENVIRONMENT="production" rake upload
|
49
|
-
|
50
|
-
deploy_staging:
|
51
|
-
stage: staging
|
52
|
-
variables:
|
53
|
-
ARTIFACT_BUCKET: ${CFN_ARTIFACT_BUCKET}
|
54
|
-
AWS_REGION: ${STAGING_AWS_REGION}
|
55
|
-
script:
|
56
|
-
- export AWS_SECRET_ACCESS_KEY=$K8S_SECRET_AWS_SECRET_ACCESS_KEY
|
57
|
-
- export AWS_ACCESS_KEY_ID=$K8S_SECRET_AWS_ACCESS_KEY_ID
|
58
|
-
- export ENVIRONMENT="test"
|
59
|
-
- rake apply
|
60
|
-
allow_failure: false
|
61
|
-
|
62
|
-
deploy_prod:
|
63
|
-
stage: production
|
64
|
-
variables:
|
65
|
-
ARTIFACT_BUCKET: ${CFN_ARTIFACT_BUCKET}
|
66
|
-
AWS_REGION: ${PROD_AWS_REGION}
|
67
|
-
script:
|
68
|
-
- export AWS_SECRET_ACCESS_KEY=$K8S_SECRET_AWS_SECRET_ACCESS_KEY
|
69
|
-
- export AWS_ACCESS_KEY_ID=$K8S_SECRET_AWS_ACCESS_KEY_ID
|
70
|
-
- export ENVIRONMENT="production"
|
71
|
-
- rake apply
|
72
|
-
dependencies:
|
73
|
-
- deploy_staging
|
74
|
-
when: manual
|
75
|
-
allow_failure: false
|
data/templates/aws_sdk.rb.erb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
def create_bucket_if_not_exists(aws_region, artifact_bucket)
|
2
|
-
s3 = Aws::S3::Resource.new(region: aws_region)
|
3
|
-
begin
|
4
|
-
s3.create_bucket(bucket: artifact_bucket)
|
5
|
-
rescue => exception
|
6
|
-
raise exception unless exception.class == Aws::S3::Errors::BucketAlreadyOwnedByYou
|
7
|
-
end
|
8
|
-
s3
|
9
|
-
end
|
10
|
-
|
11
|
-
def set_aws_credentials(region, access_key_id, secret_access_key)
|
12
|
-
Aws.config.update(
|
13
|
-
region: region,
|
14
|
-
credentials: Aws::Credentials.new(
|
15
|
-
access_key_id, secret_access_key
|
16
|
-
)
|
17
|
-
)
|
18
|
-
end
|
data/templates/core_diff.rb.erb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
require "diffy"
|
2
|
-
require_relative "../aws_helper/main"
|
3
|
-
|
4
|
-
env_vars = load_env_vars
|
5
|
-
|
6
|
-
set_aws_credentials(
|
7
|
-
env_vars[:aws_region],
|
8
|
-
env_vars[:aws_access_key_id],
|
9
|
-
env_vars[:aws_secret_access_key]
|
10
|
-
)
|
11
|
-
|
12
|
-
client = Aws::CloudFormation::Client.new
|
13
|
-
template = client.get_template(
|
14
|
-
stack_name: "#{ENV["ENVIRONMENT"]}-#{ENV["PROJECT_NAME"]}"
|
15
|
-
)
|
16
|
-
|
17
|
-
s3 = Aws::S3::Resource.new(region: env_vars[:aws_region])
|
18
|
-
orig_template = {}
|
19
|
-
|
20
|
-
template = JSON.parse(template.template_body)
|
21
|
-
template["Resources"].each do |resource_name, content|
|
22
|
-
if content["Type"] == "AWS::CloudFormation::Stack"
|
23
|
-
stack_name = "#{ENV["PROJECT_NAME"].capitalize}Stack"
|
24
|
-
orig_template[stack_name] = JSON.pretty_generate(
|
25
|
-
JSON.parse(
|
26
|
-
template.to_json
|
27
|
-
)
|
28
|
-
)
|
29
|
-
end
|
30
|
-
next unless content["Type"] == "AWS::CloudFormation::Stack"
|
31
|
-
s3_filename = content["Properties"]["TemplateURL"].split("/").last
|
32
|
-
orig_template[resource_name] = JSON.pretty_generate(
|
33
|
-
JSON.parse(
|
34
|
-
s3.client.get_object(
|
35
|
-
bucket: env_vars[:artifact_bucket],
|
36
|
-
key: s3_filename
|
37
|
-
).body.read
|
38
|
-
)
|
39
|
-
)
|
40
|
-
end
|
41
|
-
|
42
|
-
stacks = compile_stacks(true)
|
43
|
-
@stack_hashes.each do |stack_name, _hash|
|
44
|
-
new_template = JSON.pretty_generate(
|
45
|
-
JSON.parse(
|
46
|
-
stacks[stack_name]
|
47
|
-
)
|
48
|
-
)
|
49
|
-
diff = Diffy::Diff.new(
|
50
|
-
orig_template[stack_name.to_s], new_template
|
51
|
-
).to_s(:color)
|
52
|
-
|
53
|
-
if diff.strip.empty?
|
54
|
-
puts "No difference between local #{stack_name} and remote #{stack_name}"
|
55
|
-
else
|
56
|
-
puts "Orig #{stack_name} vs #{stack_name}:"
|
57
|
-
puts diff
|
58
|
-
end
|
59
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module EcsStack
|
2
|
-
module EcsCluster
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
transform
|
7
|
-
parameter :vpc,
|
8
|
-
description: "VPC ID"
|
9
|
-
|
10
|
-
# Create an empty ECS Cluster to launch fargate bastions (or other things) in
|
11
|
-
resource :<%= name.downcase %>_ecs_cluster,
|
12
|
-
type: "AWS::ECS::Cluster"
|
13
|
-
|
14
|
-
output :<%= name.downcase %>_ecs_cluster,
|
15
|
-
value: "<%= name %>EcsCluster".ref
|
16
|
-
output :<%= name.downcase %>_ecs_cluster_arn,
|
17
|
-
value: "<%= name.downcase %>EcsCluster".ref("Arn")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Concerns
|
2
|
-
module GlobalVariables
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
variable :environment,
|
7
|
-
default: "test",
|
8
|
-
global: true,
|
9
|
-
value: ENV["ENVIRONMENT"]
|
10
|
-
|
11
|
-
variable :stack_name,
|
12
|
-
default: "#{environment}-<%= name %>",
|
13
|
-
value: ENV["STACK_NAME"]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/templates/helpers.rb.erb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require_relative "../vpc_stack/subnets"
|
2
|
-
|
3
|
-
module <%= name %>Stack
|
4
|
-
module Parent
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
included do
|
8
|
-
resource :vpc_stack,
|
9
|
-
type: "AWS::CloudFormation::Stack" do |r|
|
10
|
-
r.property(:template_u_r_l) { "vpcstack" }
|
11
|
-
r.property(:timeout_in_minutes) { "5" }
|
12
|
-
end
|
13
|
-
|
14
|
-
resource :ecs_stack,
|
15
|
-
type: "AWS::CloudFormation::Stack" do |r|
|
16
|
-
r.depends_on %w(VpcStack)
|
17
|
-
r.property(:template_u_r_l) { "ecsstack" }
|
18
|
-
r.property(:parameters) do
|
19
|
-
{
|
20
|
-
"Vpc": "VpcStack".ref("Outputs.<%= name %>Vpc")
|
21
|
-
}
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/templates/subnets.rb.erb
DELETED