rubycfn 0.3.2 → 0.3.3

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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -1
  3. data/Gemfile.lock +1 -1
  4. data/README.md +13 -40
  5. data/bin/rubycfn +56 -20
  6. data/lib/cli_methods.rb +5 -1
  7. data/lib/rubycfn/version.rb +1 -1
  8. data/lib/rubycfn.rb +0 -1
  9. data/templates/.env.erb +0 -1
  10. data/templates/.env.production.erb +6 -0
  11. data/templates/.env.rspec.erb +6 -0
  12. data/templates/.env.test.erb +5 -1
  13. data/templates/.gitignore.erb +82 -0
  14. data/templates/.gitlab-ci.yml.erb +75 -0
  15. data/templates/.rubocop.yml.erb +91 -0
  16. data/templates/Gemfile.erb +13 -5
  17. data/templates/Rakefile.erb +34 -1
  18. data/templates/aws_sdk.rb.erb +18 -0
  19. data/templates/compiler.rb.erb +61 -0
  20. data/templates/core_compile.rb.erb +6 -0
  21. data/templates/core_deploy.rb.erb +115 -0
  22. data/templates/core_diff.rb.erb +59 -0
  23. data/templates/core_upload.rb.erb +3 -0
  24. data/templates/dependencies.rb.erb +23 -0
  25. data/templates/deploy.rb.erb +53 -0
  26. data/templates/ecs_stack.rb.erb +12 -0
  27. data/templates/ecs_stack_concern.rb.erb +20 -0
  28. data/templates/global_variables.rb.erb +4 -0
  29. data/templates/helper_methods.rb.erb +3 -0
  30. data/templates/helpers.rb.erb +7 -0
  31. data/templates/main.rb.erb +4 -4
  32. data/templates/main_aws_helper.rb.erb +16 -0
  33. data/templates/parent_stack_spec.rb.erb +38 -0
  34. data/templates/project_concern.rb.erb +16 -50
  35. data/templates/project_stack.rb.erb +5 -2
  36. data/templates/shared_methods.rb.erb +38 -0
  37. data/templates/spec_helper.rb.erb +3 -1
  38. data/templates/subnets.rb.erb +18 -0
  39. data/templates/upload_stack.rb.erb +27 -0
  40. data/templates/vpc_concerns.rb.erb +87 -0
  41. data/templates/vpc_spec.rb.erb +40 -0
  42. data/templates/vpc_stack.rb.erb +12 -0
  43. metadata +30 -13
  44. data/lib/compound/resources.rb +0 -1
  45. data/lib/compound/vpc.rb +0 -90
  46. data/lib/compound.rb +0 -1
  47. data/templates/buildspec.yml.erb +0 -21
  48. data/templates/cfn2rubycfn.erb +0 -127
  49. data/templates/cicd.rb.erb +0 -91
  50. data/templates/compile.rb.erb +0 -18
  51. data/templates/example_stack_spec.rb.erb +0 -101
  52. data/templates/format.vim.erb +0 -3
@@ -0,0 +1,87 @@
1
+ require_relative "subnets"
2
+
3
+ module VpcStack
4
+ module Main
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ variable :cidr_block,
9
+ default: "10.0.0.0/16",
10
+ value: ENV["VPC_CIDR_BLOCK"]
11
+
12
+ resource :<%= name.downcase %>_vpc,
13
+ type: "AWS::EC2::VPC" do |r|
14
+ r.property(:cidr_block) { cidr_block }
15
+ r.property(:enable_dns_support) { true }
16
+ r.property(:enable_dns_hostnames) { true }
17
+ end
18
+
19
+ resource "<%= name.downcase %>_internet_gateway".cfnize,
20
+ type: "AWS::EC2::InternetGateway"
21
+
22
+ resource "<%= name.downcase %>_route".cfnize,
23
+ type: "AWS::EC2::Route" do |r|
24
+ r.property(:destination_cidr_block) { "0.0.0.0/0" }
25
+ r.property(:gateway_id) { "<%= name.downcase %>_internet_gateway".cfnize.ref }
26
+ r.property(:route_table_id) { "<%= name.downcase %>_route_table".cfnize.ref }
27
+ end
28
+
29
+ resource "<%= name.downcase %>_route_table".cfnize,
30
+ type: "AWS::EC2::RouteTable" do |r|
31
+ r.property(:vpc_id) { "<%= name.downcase %>_vpc".cfnize.ref }
32
+ end
33
+
34
+ resource "<%= name.downcase %>_vpc_gateway_attachment".cfnize,
35
+ type: "AWS::EC2::VPCGatewayAttachment" do |r|
36
+ r.property(:internet_gateway_id) { "<%= name.downcase %>_internet_gateway".cfnize.ref }
37
+ r.property(:vpc_id) { "<%= name.downcase %>_vpc".cfnize.ref }
38
+ end
39
+
40
+ vpc_subnets.each_with_index do |subnet, _subnet_count|
41
+ subnet.each do |subnet_name, arguments|
42
+ resource "<%= name.downcase %>_#{subnet_name}_subnet".cfnize,
43
+ type: "AWS::EC2::Subnet",
44
+ amount: 3 do |r, index|
45
+ r.property(:availability_zone) do
46
+ {
47
+ "Fn::GetAZs": ""
48
+ }.fnselect(index)
49
+ end
50
+ r.property(:cidr_block) do
51
+ [
52
+ "<%= name %>Vpc".ref("CidrBlock"),
53
+ (3 * arguments[:offset]).to_s,
54
+ (Math.log(256) / Math.log(2)).floor.to_s
55
+ ].fncidr.fnselect(index + (3 * arguments[:offset]) - 3)
56
+ end
57
+ r.property(:map_public_ip_on_launch) { arguments[:public] }
58
+ r.property(:tags) do
59
+ [
60
+ {
61
+ "Key": "owner",
62
+ "Value": arguments[:owner].to_s.cfnize
63
+ },
64
+ {
65
+ "Key": "resource_type",
66
+ "Value": subnet_name.to_s.cfnize
67
+ }
68
+ ]
69
+ end
70
+ r.property(:vpc_id) { "<%= name %>Vpc".ref }
71
+ end
72
+
73
+ # Generate outputs for these subnets
74
+ 3.times do |i|
75
+ output "#{subnet_name}_subnet#{i.positive? ? (i + 1) : ""}_name".cfnize,
76
+ value: "<%= name.downcase %>_#{subnet_name}_subnet#{i.positive? ? (i + 1) : ""}".cfnize.ref
77
+ end
78
+ end
79
+ end
80
+
81
+ output :vpc_cidr,
82
+ value: "<%= name %>Vpc".ref("CidrBlock")
83
+ output :<%= name.downcase %>_vpc,
84
+ value: "<%= name %>Vpc".ref
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+
3
+ require "rubycfn"
4
+ require "active_support/concern"
5
+
6
+ require_relative "../../lib/main.rb"
7
+
8
+ module VpcSpec
9
+ extend ActiveSupport::Concern
10
+ include Rubycfn
11
+
12
+ included do
13
+ description "VPC Stack RSpec"
14
+ include Concerns::GlobalVariables
15
+ include Concerns::SharedMethods
16
+ include VpcStack::Main
17
+ end
18
+ end
19
+
20
+ VpcSpecCfn = include VpcSpec
21
+
22
+ describe VpcSpec do
23
+ RspecVpcSpec = VpcSpecCfn.render_template
24
+ let(:template) { JSON.parse(RspecVpcSpec) }
25
+
26
+ context "Renders template" do
27
+ subject { template }
28
+ it { should have_key "Resources" }
29
+
30
+ context "Has Required Resources" do
31
+ let(:resources) { template["Resources"] }
32
+ subject { resources }
33
+ it { should have_key "<%= name %>InternetGateway" }
34
+ it { should have_key "<%= name %>Route" }
35
+ it { should have_key "<%= name %>RouteTable" }
36
+ it { should have_key "<%= name %>Vpc" }
37
+ it { should have_key "<%= name %>VpcGatewayAttachment" }
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,12 @@
1
+ module VpcStack
2
+ extend ActiveSupport::Concern
3
+ include Rubycfn
4
+
5
+ included do
6
+ include Concerns::GlobalVariables
7
+ include Concerns::SharedMethods
8
+ include VpcStack::Main
9
+
10
+ description generate_stack_description("VpcStack")
11
+ end
12
+ 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.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Vink
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-04 00:00:00.000000000 Z
11
+ date: 2019-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: neatjson
@@ -265,29 +265,45 @@ files:
265
265
  - bin/rubycfn
266
266
  - format.vim
267
267
  - lib/cli_methods.rb
268
- - lib/compound.rb
269
- - lib/compound/resources.rb
270
- - lib/compound/vpc.rb
271
268
  - lib/rubycfn.rb
272
269
  - lib/rubycfn/version.rb
273
270
  - rubycfn.gemspec
274
271
  - spec/lib/rubycfn_spec.rb
275
272
  - spec/spec_helper.rb
276
273
  - templates/.env.erb
274
+ - templates/.env.production.erb
275
+ - templates/.env.rspec.erb
277
276
  - templates/.env.test.erb
277
+ - templates/.gitignore.erb
278
+ - templates/.gitlab-ci.yml.erb
279
+ - templates/.rubocop.yml.erb
278
280
  - templates/Gemfile.erb
279
281
  - templates/Rakefile.erb
280
- - templates/buildspec.yml.erb
281
- - templates/cfn2rubycfn.erb
282
- - templates/cicd.rb.erb
283
- - templates/compile.rb.erb
284
- - templates/example_stack_spec.rb.erb
285
- - templates/format.vim.erb
282
+ - templates/aws_sdk.rb.erb
283
+ - templates/compiler.rb.erb
284
+ - templates/core_compile.rb.erb
285
+ - templates/core_deploy.rb.erb
286
+ - templates/core_diff.rb.erb
287
+ - templates/core_upload.rb.erb
288
+ - templates/dependencies.rb.erb
289
+ - templates/deploy.rb.erb
290
+ - templates/ecs_stack.rb.erb
291
+ - templates/ecs_stack_concern.rb.erb
286
292
  - templates/global_variables.rb.erb
293
+ - templates/helper_methods.rb.erb
294
+ - templates/helpers.rb.erb
287
295
  - templates/main.rb.erb
296
+ - templates/main_aws_helper.rb.erb
297
+ - templates/parent_stack_spec.rb.erb
288
298
  - templates/project_concern.rb.erb
289
299
  - templates/project_stack.rb.erb
300
+ - templates/shared_methods.rb.erb
290
301
  - templates/spec_helper.rb.erb
302
+ - templates/subnets.rb.erb
303
+ - templates/upload_stack.rb.erb
304
+ - templates/vpc_concerns.rb.erb
305
+ - templates/vpc_spec.rb.erb
306
+ - templates/vpc_stack.rb.erb
291
307
  homepage: https://github.com/dennisvink/rubycfn
292
308
  licenses:
293
309
  - MIT
@@ -316,7 +332,8 @@ test_files:
316
332
  - rubycfn.gemspec
317
333
  - spec/lib/rubycfn_spec.rb
318
334
  - spec/spec_helper.rb
335
+ - templates/.env.rspec.erb
319
336
  - templates/.env.test.erb
320
- - templates/buildspec.yml.erb
321
- - templates/example_stack_spec.rb.erb
337
+ - templates/parent_stack_spec.rb.erb
322
338
  - templates/spec_helper.rb.erb
339
+ - templates/vpc_spec.rb.erb
@@ -1 +0,0 @@
1
- require_relative "vpc"
data/lib/compound/vpc.rb DELETED
@@ -1,90 +0,0 @@
1
- module RubyCfn
2
- module VPC
3
- def self.[](prefix, suffix, &block)
4
- Module.new do
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
-
9
- def validate_instance_tenancy(value)
10
- unless ["", 'default', 'dedicated'].include? value
11
- raise "Expected instance_tenancy to be within `default` or `dedicated`. Received `#{value}`"
12
- end
13
- value
14
- end
15
-
16
- variable :cidr_block,
17
- default: "10.0.0.0/16"
18
- variable :enable_dns_support,
19
- default: true
20
- variable :enable_dns_hostnames,
21
- default: true
22
- variable :instance_tenancy,
23
- filter: :validate_instance_tenancy
24
-
25
- # TODO: Move to separate compound resource
26
- # variable :ipv6,
27
- # default: false
28
- # variable :subnets,
29
- # default: 3
30
- # variable :subnet_ip_addresses,
31
- # default: 256
32
-
33
- yield self if block_given? # Variable overrides
34
-
35
- resource "#{prefix}_vpc#{suffix}".cfnize,
36
- type: "AWS::EC2::VPC" do |r, index|
37
- r.property(:cidr_block) { cidr_block }
38
- r.property(:enable_dns_support) { enable_dns_support }
39
- r.property(:enable_dns_hostnames) { enable_dns_hostnames }
40
- r.property(:instance_tenancy) { instance_tenancy } unless instance_tenancy.empty?
41
- end
42
-
43
- resource "#{prefix}_internet_gateway#{suffix}".cfnize,
44
- type: "AWS::EC2::InternetGateway"
45
-
46
- resource "#{prefix}_route#{suffix}".cfnize,
47
- type: "AWS::EC2::Route" do |r, index|
48
- r.property(:destination_cidr_block) { "0.0.0.0/0" }
49
- r.property(:gateway_id) { "#{prefix}_internet_gateway#{suffix}".cfnize.ref }
50
- r.property(:route_table_id) { "#{prefix}_route_table#{suffix}".cfnize.ref }
51
- end
52
-
53
- resource "#{prefix}_route_table#{suffix}".cfnize,
54
- type: "AWS::EC2::RouteTable" do |r, index|
55
- r.property(:vpc_id) { "#{prefix}_vpc#{suffix}".cfnize.ref }
56
- end
57
-
58
- resource "#{prefix}_vpc_gateway_attachment#{suffix}".cfnize,
59
- type: "AWS::EC2::VPCGatewayAttachment" do |r, index|
60
- r.property(:internet_gateway_id) { "#{prefix}_internet_gateway#{suffix}".cfnize.ref }
61
- r.property(:vpc_id) { "#{prefix}_vpc#{suffix}".cfnize.ref }
62
- end
63
-
64
- # TODO: Move to separate compound resource
65
- #subnets.times do |i|
66
- # resource "#{prefix}_subnet#{suffix}#{i == 0 ? "" : i+1}",
67
- # type: "AWS::EC2::Subnet",
68
- # compound: true do |r, index|
69
- # r.property(:vpc_id) { "#{prefix}_vpc#{suffix}".cfnize.ref }
70
- # r.property(:cidr_block) { ["#{prefix}_vpc#{suffix}".cfnize.ref("CidrBlock"), subnets.to_s, ((Math.log(subnet_ip_addresses)/Math.log(2)).floor).to_s].fncidr.fnselect(i) }
71
- # #if ipv6 == "true"
72
- # # r.property(:ipv6_cidr_block) do
73
- # # .. todo ..
74
- # # end
75
- # #end
76
- # end
77
- #end
78
-
79
- #if ipv6 == "true"
80
- # resource "#{prefix}_ipv6_cidr_block#{suffix}",
81
- # type: "AWS::EC2::VPCCidrBlock" do |r, index|
82
- # r.property(:vpc_id) { "#{prefix}_vpc#{suffix}".cfnize.ref }
83
- # r.property(:amazon_provided_ipv6_cidr_block) { true }
84
- # end
85
- #end
86
- end
87
- end
88
- end
89
- end
90
- end
data/lib/compound.rb DELETED
@@ -1 +0,0 @@
1
- require_relative "compound/vpc"
@@ -1,21 +0,0 @@
1
- version: 0.1
2
-
3
- phases:
4
- install:
5
- commands:
6
- - gem install cfn-nag
7
- - bundle install
8
- pre_build:
9
- commands:
10
- - echo Do nothing
11
- build:
12
- commands:
13
- - echo Build started on `date`
14
- - rake
15
- - cfn_nag_scan --input-path build
16
- post_build:
17
- commands:
18
- - echo Build completed on `date`
19
- artifacts:
20
- files:
21
- - ./**
@@ -1,127 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "json"
4
-
5
- class String
6
- def snake
7
- self.gsub(/::/, '/').
8
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
9
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
10
- tr("-", "_").
11
- downcase
12
- end
13
- end
14
-
15
-
16
- def add_code(line, append = false)
17
- if append === true
18
- orig_line = @code.pop
19
- line = "#{orig_line}#{line}"
20
- end
21
- @code.push(line)
22
- end
23
-
24
- def wash(input = {}, target = :Ref)
25
- return input unless input.respond_to?("each")
26
- hash = {}
27
- input.map do |key, value|
28
- case key
29
- when 'Ref'
30
- hash = "###'" + value.to_s + "'." + key.downcase.to_s + '###'
31
- else
32
- if value.respond_to?("each")
33
- hash[key] = wash(value, :Ref)
34
- else
35
- return input
36
- end
37
- end
38
- end
39
- hash
40
- end
41
-
42
- raise "Filename required" unless ARGV[0]
43
- raise "File does not exist" unless File.file?(ARGV[0])
44
-
45
- @code = []
46
- template = JSON.parse(File.read(ARGV[0]))
47
- resources = template["Resources"]
48
- outadd_code = template["Outadd_code"]
49
- parameters = template["Parameters"]
50
- outputs = template["Outputs"]
51
-
52
- add_code "module ConvertedStack"
53
- add_code " module Main"
54
- add_code " extend ActiveSupport::Concern"
55
- add_code " included do"
56
-
57
- # Convert parameters
58
- parameters.each do |param_name, param_attr|
59
- add_code " parameter :#{param_name.snake}"
60
- add_code(parameters.count > 1 ? "," : "", true)
61
- param_attr.each_with_index do |attr, index|
62
- add_code " #{attr.first.snake}: \"#{attr.last}\""
63
- add_code(index+1 == param_attr.count ? "" : ",", true)
64
- end
65
- add_code("")
66
- end
67
-
68
- # Convert resources
69
- resources.each do |resource_name, resource_attr|
70
- properties = resource_attr["Properties"]
71
- unless resource_attr["Properties"].empty?
72
- add_code " resource :#{resource_name.snake},"
73
- add_code " type: \"#{resource_attr["Type"]}\" do |r|"
74
- properties.each do |k,v|
75
- if v.respond_to?("each")
76
- v = wash(v)
77
- v = JSON.pretty_generate(v)
78
- v = v.gsub(/\"\#\#\#/, "")
79
- v = v.gsub(/\#\#\#\"/, "")
80
-
81
- add_code " r.property(:#{k.snake}) do"
82
- add_code " #{v}"
83
- add_code " end"
84
- else
85
- add_code " r.property(:#{k.snake}) { #{v.to_json} }"
86
- end
87
- end
88
- add_code " end"
89
- else
90
- add_code " resource :#{resource_name.snake},"
91
- add_code " type: \"#{resource_attr["Type"]}\""
92
- end
93
- add_code("")
94
- end
95
-
96
- outputs.each do |output_name, output_attr|
97
- add_code " output :#{output_name.snake}"
98
- add_code(output_attr.count > 0 ? "," : "", true)
99
- output_attr.each_with_index do |attr, index|
100
- add_code " #{attr.first.snake}: "
101
- if attr.last.class == Hash
102
- add_code(wash(attr.last), true)
103
- else
104
- add_code("\"#{attr.last}\"", true)
105
- end
106
- add_code(index+1 == output_attr.count ? "" : ",", true)
107
- end
108
- add_code("")
109
- end
110
-
111
- add_code " end"
112
- add_code " end"
113
- add_code "end"
114
-
115
- @code = @code.join("\n")
116
- @code = @code.gsub(/\"\#\#\#/, "")
117
- @code = @code.gsub(/\#\#\#\"/, "")
118
- @code = @code.gsub(/\'\#\#\#/, "'")
119
- @code = @code.gsub(/\#\#\#\'/, "'")
120
- @code = @code.gsub(/\#\#\#${1}/, "")
121
-
122
- File.open("generated.rb", "w") do |f|
123
- f.puts(@code)
124
- end
125
-
126
- puts "Reformatting code..."
127
- `vim generated.rb -s format.vim 2>&1 >/dev/null`
@@ -1,91 +0,0 @@
1
- module <%= name %>Stack
2
- module CICD
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- variable :github_repository,
7
- default: "https://github.com/dennisvink/elastic-cloud-engineering/",
8
- value: ENV["GITHUB_REPOSITORY"]
9
-
10
- resource :code_build_<%= small_name %>_service_role,
11
- type: "AWS::IAM::Role" do |r|
12
- r.property(:assume_role_policy_document) do
13
- {
14
- "Version": "2012-10-17",
15
- "Statement": [
16
- {
17
- "Effect": "Allow",
18
- "Principal": {
19
- "Service": [
20
- "codebuild.amazonaws.com"
21
- ]
22
- },
23
- "Action": [
24
- "sts:AssumeRole"
25
- ]
26
- }
27
- ]
28
- }
29
- end
30
- r.property(:path) { "/service-role/" }
31
- r.property(:policies) do
32
- [
33
- {
34
- "PolicyName": "CodeBuildAccessPolicies",
35
- "PolicyDocument": {
36
- "Version": "2012-10-17",
37
- "Statement": [
38
- {
39
- "Effect": "Allow",
40
- "Action": [
41
- "logs:CreateLogGroup",
42
- "logs:CreateLogStream",
43
- "logs:PutLogEvents"
44
- ],
45
- "Resource": [
46
- "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/codebuild/*".fnsub
47
- ]
48
- }
49
- ]
50
- }
51
- }
52
- ]
53
- end
54
- end
55
-
56
- resource :code_build_<%= small_name %>_project,
57
- type: "AWS::CodeBuild::Project" do |r|
58
- r.property(:name) { "<%= name %>-project-${AWS::Region}-${AWS::StackName}".fnsub }
59
- r.property(:service_role) { "code_build_<%= small_name %>_service_role".cfnize.ref("Arn") }
60
- r.property(:artifacts) do
61
- {
62
- "Type": "no_artifacts"
63
- }
64
- end
65
- r.property(:environment) do
66
- {
67
- "Type": "LINUX_CONTAINER",
68
- "ComputeType": "BUILD_GENERAL1_SMALL",
69
- "Image": "aws/codebuild/ruby:2.3.1"
70
- }
71
- end
72
- r.property(:source) do
73
- {
74
- "BuildSpec": text = File.read("config/buildspec.yml"),
75
- "Auth": {
76
- "Type": "OAUTH"
77
- },
78
- "Location": "#{github_repository}",
79
- "Type": "GITHUB"
80
- }
81
- end
82
- r.property(:triggers) do
83
- {
84
- "Webhook": true
85
- }
86
- end
87
- r.property(:timeout_in_minutes) { 10 }
88
- end
89
- end
90
- end
91
- end
@@ -1,18 +0,0 @@
1
- require 'fileutils'
2
-
3
- FileUtils.mkdir_p 'build'
4
-
5
- google_stacks = {}
6
- stacks = {}
7
-
8
- Module.constants.select do |mod|
9
- if mod =~ /Stack$/
10
- send("include", Object.const_get("SharedConcerns"))
11
- stacks[mod.to_sym] = send("include", Object.const_get(mod)).render_template("AWS")
12
- end
13
- end
14
-
15
- stacks.each do |stack_name, stack|
16
- puts "- Saved #{stack_name} to build/#{ENV["ENVIRONMENT"]}-#{stack_name.downcase}.json"
17
- File.open("build/#{ENV["ENVIRONMENT"]}-#{stack_name.downcase}.json", "w") { |f| f.write(stack) }
18
- end
@@ -1,101 +0,0 @@
1
- require "spec_helper"
2
-
3
- require "rubycfn"
4
- require "active_support/concern"
5
- require_relative "../../lib/main.rb"
6
-
7
- describe Rubycfn do
8
- module RspecStack
9
- extend ActiveSupport::Concern
10
- include Rubycfn
11
-
12
- included do
13
- description "RSpec Stack"
14
- include <%= name %>Stack::CICD
15
- end
16
- end
17
-
18
- CloudFormation = include RspecStack
19
- RspecStack = CloudFormation.render_template
20
- Given(:json) { JSON.parse(RspecStack) }
21
-
22
- context "Renders template" do
23
- let(:template) { json }
24
- subject { template }
25
-
26
- it { should_not have_key "Parameters" }
27
- it { should have_key "Resources" }
28
-
29
- context "Has Codebuild Resources" do
30
- let(:resources) { template["Resources"] }
31
- subject { resources }
32
-
33
- it { should have_key "CodeBuild<%= name %>Project" }
34
- it { should have_key "CodeBuild<%= name %>ServiceRole" }
35
-
36
- context "Codebuild Repository" do
37
- let(:repository) { resources["CodeBuild<%= name %>Project"] }
38
- subject { repository }
39
-
40
- it { should have_key "Properties" }
41
-
42
- context "Codebuild properties" do
43
- let(:codebuild_properties) { repository["Properties"] }
44
- subject { codebuild_properties }
45
-
46
- it { should have_key "Artifacts" }
47
- it { should have_key "Environment" }
48
- it { should have_key "Name" }
49
- it { should have_key "ServiceRole" }
50
- it { should have_key "Source" }
51
- it { should have_key "TimeoutInMinutes" }
52
- it { should have_key "Triggers" }
53
-
54
- context "Codebuild Auth Type" do
55
- let(:auth_type) { codebuild_properties["Source"]["Auth"]["Type"] }
56
- subject { auth_type }
57
-
58
- it { should eq "OAUTH" }
59
- end
60
-
61
- context "Codebuild creates webhook" do
62
- let(:webhook) { codebuild_properties["Triggers"]["Webhook"] }
63
- subject { webhook }
64
-
65
- it { should eq true }
66
- end
67
- end
68
- end
69
-
70
- context "Codebuild Service Role" do
71
- let(:code_build_service_role) { resources["CodeBuild<%= name %>ServiceRole"] }
72
- subject { code_build_service_role }
73
-
74
- it { should have_key "Properties" }
75
-
76
- context "Code build service role properties" do
77
- let(:code_build_service_role_properties) { code_build_service_role["Properties"] }
78
- subject { code_build_service_role_properties }
79
-
80
- it { should have_key "AssumeRolePolicyDocument" }
81
- it { should have_key "Path" }
82
- it { should have_key "Policies" }
83
-
84
- context "Code build service role policy document" do
85
- let(:policy_document) { code_build_service_role_properties["Policies"][0]["PolicyDocument"] }
86
- subject { policy_document }
87
-
88
- it { should have_key "Statement" }
89
-
90
- context "Code build service role actions" do
91
- let(:statement) { policy_document["Statement"][0]["Action"] }
92
- subject { statement }
93
-
94
- it { should eq %w(logs:CreateLogGroup logs:CreateLogStream logs:PutLogEvents) }
95
- end
96
- end
97
- end
98
- end
99
- end
100
- end
101
- end
@@ -1,3 +0,0 @@
1
- gg=G
2
- :retab
3
- ZZ