rubycfn 0.4.10 → 0.5.4

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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -1
  3. data/Gemfile.lock +48 -46
  4. data/README.md +46 -71
  5. data/bin/rubycfn +17 -73
  6. data/lib/cli_methods.rb +2 -2
  7. data/lib/rubycfn/version.rb +1 -1
  8. data/rubycfn.gemspec +1 -1
  9. data/templates/.env +2 -0
  10. data/templates/.env.acceptance +1 -0
  11. data/templates/.env.dependencies.rspec +6 -0
  12. data/templates/.env.development +1 -0
  13. data/templates/.env.production +1 -0
  14. data/templates/.env.rspec +1 -0
  15. data/templates/.env.test +1 -0
  16. data/templates/{.gitignore.erb → .gitignore} +7 -0
  17. data/templates/{.rubocop.yml.erb → .rubocop.yml} +17 -1
  18. data/templates/{Gemfile.erb → Gemfile} +0 -1
  19. data/templates/README.md +58 -0
  20. data/templates/{Rakefile.erb → Rakefile} +15 -8
  21. data/templates/config.yaml +68 -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/lib/aws_helper/dependencies.rb +35 -0
  25. data/templates/{deploy.rb.erb → lib/aws_helper/deploy.rb} +5 -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} +8 -6
  29. data/templates/lib/core/applications.rb +625 -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 +29 -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 +221 -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} +11 -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 +190 -0
  47. data/templates/lib/stacks/ecs_stack/load_balancer.rb +70 -0
  48. data/templates/{ecs_stack.rb.erb → lib/stacks/ecs_stack/main.rb} +3 -0
  49. data/templates/lib/stacks/ecs_stack/rollback.rb +77 -0
  50. data/templates/{project_stack.rb.erb → lib/stacks/parent_stack/main.rb} +2 -2
  51. data/templates/lib/stacks/parent_stack/parent.rb +18 -0
  52. data/templates/lib/stacks/vpc_stack/infra_vpc.rb +193 -0
  53. data/templates/{vpc_stack.rb.erb → lib/stacks/vpc_stack/main.rb} +1 -2
  54. data/templates/{parent_stack_spec.rb.erb → spec/lib/parent_spec.rb} +2 -5
  55. data/templates/{spec_helper.rb.erb → spec/spec_helper.rb} +2 -2
  56. metadata +61 -51
  57. data/format.vim +0 -3
  58. data/templates/.env.erb +0 -4
  59. data/templates/.env.production.erb +0 -6
  60. data/templates/.env.rspec.erb +0 -6
  61. data/templates/.env.test.erb +0 -6
  62. data/templates/.gitlab-ci.yml.erb +0 -75
  63. data/templates/aws_sdk.rb.erb +0 -18
  64. data/templates/core_diff.rb.erb +0 -59
  65. data/templates/dependencies.rb.erb +0 -23
  66. data/templates/ecs_stack_concern.rb.erb +0 -20
  67. data/templates/global_variables.rb.erb +0 -16
  68. data/templates/helpers.rb.erb +0 -7
  69. data/templates/new_concern.rb.erb +0 -10
  70. data/templates/project_concern.rb.erb +0 -26
  71. data/templates/subnets.rb.erb +0 -18
  72. data/templates/vpc_concerns.rb.erb +0 -87
  73. data/templates/vpc_spec.rb.erb +0 -39
@@ -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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Vink
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-29 00:00:00.000000000 Z
11
+ date: 2021-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: neatjson
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.1.0
33
+ version: 2.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.1.0
40
+ version: 2.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -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,47 +272,59 @@ 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.private
280
+ - templates/.env.production
281
+ - templates/.env.rspec
282
+ - templates/.env.test
283
+ - templates/.gitignore
284
+ - templates/.rubocop.yml
285
+ - templates/Gemfile
286
+ - templates/README.md
287
+ - templates/Rakefile
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/ecs_stack/rollback.rb
317
+ - templates/lib/stacks/parent_stack/main.rb
318
+ - templates/lib/stacks/parent_stack/parent.rb
319
+ - templates/lib/stacks/vpc_stack/infra_vpc.rb
320
+ - templates/lib/stacks/vpc_stack/main.rb
321
+ - templates/spec/lib/parent_spec.rb
322
+ - templates/spec/spec_helper.rb
312
323
  homepage: https://github.com/dennisvink/rubycfn
313
324
  licenses:
314
325
  - MIT
315
326
  metadata: {}
316
- post_install_message:
327
+ post_install_message:
317
328
  rdoc_options: []
318
329
  require_paths:
319
330
  - lib
@@ -328,17 +339,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
328
339
  - !ruby/object:Gem::Version
329
340
  version: '0'
330
341
  requirements: []
331
- rubyforge_project:
332
- rubygems_version: 2.7.3
333
- signing_key:
342
+ rubygems_version: 3.1.2
343
+ signing_key:
334
344
  specification_version: 4
335
345
  summary: Rubycfn
336
346
  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,23 +0,0 @@
1
- def load_env_vars
2
- Dotenv.load(".env")
3
- Dotenv.load(".env.#{ENV["ENVIRONMENT"]}")
4
- Dotenv.load(".env.private")
5
- check_dependencies
6
- {
7
- aws_region: ENV["AWS_REGION"],
8
- aws_access_key_id: ENV["AWS_ACCESS_KEY_ID"],
9
- aws_secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
10
- artifact_bucket: ENV["ARTIFACT_BUCKET"],
11
- environment: ENV["ENVIRONMENT"],
12
- stack_name: ENV["STACK_NAME"]
13
- }
14
- end
15
-
16
- def check_dependencies
17
- ENV["AWS_REGION"] ||= ENV["AWS_DEFAULT_REGION"]
18
- raise "AWS_REGION not set" unless ENV["AWS_REGION"]
19
- raise "ARTIFACT_BUCKET not set" unless ENV["ARTIFACT_BUCKET"]
20
- raise "ENVIRONMENT not set" unless ENV["ENVIRONMENT"]
21
- raise "STACK_NAME not set" unless ENV["STACK_NAME"]
22
- raise "AWS CREDENTIALS NOT SET" unless ENV["AWS_ACCESS_KEY_ID"] && ENV["AWS_SECRET_ACCESS_KEY"]
23
- 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