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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -1
  3. data/Gemfile.lock +1 -1
  4. data/README.md +43 -67
  5. data/bin/rubycfn +17 -73
  6. data/lib/cli_methods.rb +2 -2
  7. data/lib/rubycfn/version.rb +1 -1
  8. data/templates/.env +2 -0
  9. data/templates/.env.acceptance +1 -0
  10. data/templates/.env.dependencies.rspec +6 -0
  11. data/templates/.env.development +1 -0
  12. data/templates/.env.production +1 -0
  13. data/templates/.env.rspec +1 -0
  14. data/templates/.env.test +1 -0
  15. data/templates/{.gitignore.erb → .gitignore} +3 -0
  16. data/templates/{.rubocop.yml.erb → .rubocop.yml} +14 -1
  17. data/templates/{Gemfile.erb → Gemfile} +0 -1
  18. data/templates/README.md +57 -0
  19. data/templates/{Rakefile.erb → Rakefile} +15 -8
  20. data/templates/bootstrap/dependency_stack.rb +49 -0
  21. data/templates/config.yaml +65 -0
  22. data/templates/lib/aws_helper/aws_sdk.rb +30 -0
  23. data/templates/{compiler.rb.erb → lib/aws_helper/compiler.rb} +15 -9
  24. data/templates/{dependencies.rb.erb → lib/aws_helper/dependencies.rb} +5 -3
  25. data/templates/{deploy.rb.erb → lib/aws_helper/deploy.rb} +6 -4
  26. data/templates/lib/aws_helper/helpers.rb +3 -0
  27. data/templates/{main_aws_helper.rb.erb → lib/aws_helper/main.rb} +0 -0
  28. data/templates/{upload_stack.rb.erb → lib/aws_helper/upload_stack.rb} +15 -6
  29. data/templates/lib/core/applications.rb +479 -0
  30. data/templates/lib/core/assume_role.rb +40 -0
  31. data/templates/lib/core/classes.rb +25 -0
  32. data/templates/{core_compile.rb.erb → lib/core/compile.rb} +1 -0
  33. data/templates/lib/core/dependencies.rb +22 -0
  34. data/templates/{core_deploy.rb.erb → lib/core/deploy.rb} +20 -10
  35. data/templates/lib/core/git.rb +15 -0
  36. data/templates/lib/core/init.rb +173 -0
  37. data/templates/{core_upload.rb.erb → lib/core/upload.rb} +0 -0
  38. data/templates/{main.rb.erb → lib/main.rb} +8 -6
  39. data/templates/lib/shared_concerns/global_variables.rb +56 -0
  40. data/templates/{helper_methods.rb.erb → lib/shared_concerns/helper_functions.rb} +0 -0
  41. data/templates/lib/shared_concerns/helper_methods.rb +3 -0
  42. data/templates/{shared_methods.rb.erb → lib/shared_concerns/shared_methods.rb} +9 -0
  43. data/templates/lib/stacks/acm_stack/certificate_manager.rb +79 -0
  44. data/templates/{new_stack.rb.erb → lib/stacks/acm_stack/main.rb} +3 -4
  45. data/templates/lib/stacks/ecs_stack/ecs_cluster.rb +344 -0
  46. data/templates/lib/stacks/ecs_stack/lifecycle_hook.rb +188 -0
  47. data/templates/lib/stacks/ecs_stack/load_balancer.rb +68 -0
  48. data/templates/{ecs_stack.rb.erb → lib/stacks/ecs_stack/main.rb} +2 -1
  49. data/templates/{project_stack.rb.erb → lib/stacks/parent_stack/main.rb} +2 -2
  50. data/templates/lib/stacks/parent_stack/parent.rb +18 -0
  51. data/templates/lib/stacks/vpc_stack/infra_vpc.rb +193 -0
  52. data/templates/{vpc_stack.rb.erb → lib/stacks/vpc_stack/main.rb} +1 -2
  53. data/templates/{parent_stack_spec.rb.erb → spec/lib/parent_spec.rb} +2 -5
  54. data/templates/{spec_helper.rb.erb → spec/spec_helper.rb} +2 -2
  55. metadata +54 -44
  56. data/format.vim +0 -3
  57. data/templates/.env.erb +0 -4
  58. data/templates/.env.production.erb +0 -6
  59. data/templates/.env.rspec.erb +0 -6
  60. data/templates/.env.test.erb +0 -6
  61. data/templates/.gitlab-ci.yml.erb +0 -75
  62. data/templates/aws_sdk.rb.erb +0 -18
  63. data/templates/core_diff.rb.erb +0 -59
  64. data/templates/ecs_stack_concern.rb.erb +0 -20
  65. data/templates/global_variables.rb.erb +0 -16
  66. data/templates/helpers.rb.erb +0 -7
  67. data/templates/new_concern.rb.erb +0 -10
  68. data/templates/project_concern.rb.erb +0 -26
  69. data/templates/subnets.rb.erb +0 -18
  70. data/templates/vpc_concerns.rb.erb +0 -87
  71. 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::Main
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 "<%= name %> RSpec"
11
+ description "Infra Stack RSpec"
12
12
  include Concerns::GlobalVariables
13
13
  include Concerns::SharedMethods
14
- include <%= name %>Stack::Parent
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
- end
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.10
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-02-29 00:00:00.000000000 Z
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.erb
277
- - templates/.env.production.erb
278
- - templates/.env.rspec.erb
279
- - templates/.env.test.erb
280
- - templates/.gitignore.erb
281
- - templates/.gitlab-ci.yml.erb
282
- - templates/.rubocop.yml.erb
283
- - templates/Gemfile.erb
284
- - templates/Rakefile.erb
285
- - templates/aws_sdk.rb.erb
286
- - templates/compiler.rb.erb
287
- - templates/core_compile.rb.erb
288
- - templates/core_deploy.rb.erb
289
- - templates/core_diff.rb.erb
290
- - templates/core_upload.rb.erb
291
- - templates/dependencies.rb.erb
292
- - templates/deploy.rb.erb
293
- - templates/ecs_stack.rb.erb
294
- - templates/ecs_stack_concern.rb.erb
295
- - templates/global_variables.rb.erb
296
- - templates/helper_methods.rb.erb
297
- - templates/helpers.rb.erb
298
- - templates/main.rb.erb
299
- - templates/main_aws_helper.rb.erb
300
- - templates/new_concern.rb.erb
301
- - templates/new_stack.rb.erb
302
- - templates/parent_stack_spec.rb.erb
303
- - templates/project_concern.rb.erb
304
- - templates/project_stack.rb.erb
305
- - templates/shared_methods.rb.erb
306
- - templates/spec_helper.rb.erb
307
- - templates/subnets.rb.erb
308
- - templates/upload_stack.rb.erb
309
- - templates/vpc_concerns.rb.erb
310
- - templates/vpc_spec.rb.erb
311
- - templates/vpc_stack.rb.erb
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.erb
341
- - templates/.env.test.erb
342
- - templates/parent_stack_spec.rb.erb
343
- - templates/spec_helper.rb.erb
344
- - templates/vpc_spec.rb.erb
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
@@ -1,3 +0,0 @@
1
- gg=G
2
- :retab
3
- ZZ
data/templates/.env.erb DELETED
@@ -1,4 +0,0 @@
1
- AWS_ACCOUNT_ID="<%= account_id %>"
2
- AWS_REGION="<%= region %>"
3
- ENVIRONMENT="test"
4
- PROJECT_NAME="<%= project_name %>"
@@ -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"
@@ -1,6 +0,0 @@
1
- # ENV vars for rspec environment
2
- CLOUD_TRAIL_MONITOR_SNS_RECIPIENTS="should@match"
3
- ROOT_MONITOR_SNS_RECIPIENTS="should@match"
4
- VPC_CIDR_BLOCK="10.0.0.0/16"
5
- ARTIFACT_BUCKET="my-mock-bucket"
6
- STACK_NAME="rspec"
@@ -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
@@ -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
@@ -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
@@ -1,7 +0,0 @@
1
- def stack_to_md5(stack_name, stack)
2
- @stack_hashes[stack_name] = Digest::MD5.hexdigest(JSON.pretty_generate(JSON.parse(stack.to_s)))
3
- end
4
-
5
- def generate_s3_filename(filename, hash)
6
- "#{File.basename(filename, ".json")}-#{hash}.json"
7
- end
@@ -1,10 +0,0 @@
1
- module <%= stack_name %>
2
- module MyModule
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- resource :sample_resource,
7
- type: "AWS::SQS::Queue"
8
- end
9
- end
10
- end
@@ -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
@@ -1,18 +0,0 @@
1
- def vpc_subnets
2
- [
3
- {
4
- "ec2_public": {
5
- "owner": "<%= name.downcase %>",
6
- "public": true,
7
- "offset": 2
8
- }
9
- },
10
- {
11
- "ec2_private": {
12
- "owner": "<%= name.downcase %>",
13
- "public": false,
14
- "offset": 3
15
- }
16
- }
17
- ]
18
- end