cloudformation_rspec 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3db66fc637f051d0215b0a032ec4c4b8c53a79b8
4
- data.tar.gz: 9c8369901d78964f71cab1d6663395162883d9ce
2
+ SHA256:
3
+ metadata.gz: a073315a283411eaed933a0eb0e4eb51d3f87496e40e1f07673a94e6a2b6536c
4
+ data.tar.gz: 86dd0c5ca39eb1eb9f97c91e10194c71086cb231fb5b6127ce2241973af47b03
5
5
  SHA512:
6
- metadata.gz: 6345dfdd804ccfa4624e262671e329a88ef21a99db8e35ede647c69477f56e7ddfa5339c3ef9003edcb11d83951077f5c2f95e9c2de55ba255b62165da12ec53
7
- data.tar.gz: a97a4ddd76b905580867fdbdd2c54d48b5560a83bd06f3d6ce2e06ab9e54eac0dacf318eef66e67a687ac7659aaf57b4de6bed494dab05ae4ceb0bffaa0cc842
6
+ metadata.gz: a61097b4245128ba048d275f3244c04deafff180f3503cdd38b43bf4b3e35db89eecabfc88989aa422b568e69a511f1df978acabf2ecf7ee0ecf018f61a19996
7
+ data.tar.gz: 60f7bade60799bb6d8ed94ebe312fdc5cb3f0195294e2200978b45d7e57d16424aeecb28e81b75ae57c22b47f13a0ff096bf151bb156612d97b29415145e9bce
data/.travis.yml CHANGED
@@ -1,6 +1,10 @@
1
1
  language: ruby
2
- rvm:
3
- - 2.3.7
4
- - 2.4.4
5
- - 2.5.1
6
- script: bundle exec rake spec
2
+
3
+ services:
4
+ - docker
5
+
6
+ before_install:
7
+ - docker build -t cloudformation_rspec -f Dockerfile.ci .
8
+
9
+ script:
10
+ - docker run cloudformation_rspec /bin/sh -c "bundle exec rake spec"
data/Dockerfile.ci ADDED
@@ -0,0 +1,10 @@
1
+ FROM ruby:2.6.5-slim
2
+
3
+ RUN apt update -y && apt install -y python-pip git && pip install cfn-lint
4
+
5
+ COPY . /app
6
+ WORKDIR /app
7
+
8
+ RUN bundle install
9
+
10
+
@@ -2,7 +2,7 @@ $:.unshift File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "cloudformation_rspec"
5
- gem.version = "0.1.0"
5
+ gem.version = "0.2.0"
6
6
 
7
7
  gem.authors = ["Patrick Robinson"]
8
8
  gem.email = ["patrick.robinson@envato.com"]
@@ -1,4 +1,5 @@
1
1
  require 'aws-sdk-cloudformation'
2
+ require 'open3'
2
3
 
3
4
  module CloudFormationRSpec::Matchers::Validate
4
5
  def validate_cf_template(template_body)
@@ -11,12 +12,35 @@ module CloudFormationRSpec::Matchers::Validate
11
12
  end
12
13
  true
13
14
  end
15
+
16
+ def lint_cf_template(template_body)
17
+ # Issue a warning if cfn-lint is not installed, but pass the test
18
+ unless cfn_lint_available
19
+ warn "Failed to run cfn-lint, do you have it installed and available in $PATH?"
20
+ return true
21
+ end
22
+
23
+ Tempfile.open(['cfn-lint', '.json']) do |f|
24
+ f.write(template_body)
25
+ f.flush
26
+ stdout, _stderr, status = Open3.capture3('cfn-lint', '-i', 'W', '--', f.path)
27
+ if status.exitstatus != 0
28
+ @error = stdout
29
+ end
30
+ status.exitstatus == 0
31
+ end
32
+ end
33
+
34
+ def cfn_lint_available
35
+ _, _, status = Open3.capture3('cfn-lint', '-l')
36
+ status.exitstatus == 0
37
+ end
14
38
  end
15
39
 
16
40
  RSpec::Matchers.define :be_valid do
17
41
  include CloudFormationRSpec::Matchers::Validate
18
42
  match do |cf_template|
19
- validate_cf_template(cf_template)
43
+ validate_cf_template(cf_template) && lint_cf_template(cf_template)
20
44
  end
21
45
 
22
46
  failure_message do
@@ -39,7 +63,7 @@ RSpec::Matchers.define :be_valid_sparkleformation do
39
63
  @error = error
40
64
  return false
41
65
  end
42
- validate_cf_template(template_body)
66
+ validate_cf_template(template_body) && lint_cf_template(template_body)
43
67
  end
44
68
 
45
69
  failure_message do
@@ -0,0 +1,20 @@
1
+ {
2
+ "AWSTemplateFormatVersion" : "2010-09-09",
3
+ "Resources" : {
4
+ "myVPC" : {
5
+ "Type" : "AWS::EC2::VPC",
6
+ "Properties" : {
7
+ "CidrBlock" : 1,
8
+ "EnableDnsSupport" : [],
9
+ "EnableDnsHostnames" : [],
10
+ "InstanceTenancy" : {},
11
+ "Tags" : [ {"Key" : "foo", "Value" : "bar"} ]
12
+ }
13
+ }
14
+ },
15
+ "Outputs" : {
16
+ "VpcId": {
17
+ "Value": {"Ref": "myVPC"}
18
+ }
19
+ }
20
+ }
@@ -13,4 +13,11 @@ SparkleFormation.new(:vpc,
13
13
  constraint_description 'CIDR block parameter must be in the form x.x.x.x/16-28'
14
14
  default state!(:vpc_cidr)
15
15
  end
16
+
17
+ resources.vpc do
18
+ type "AWS::EC2::VPC"
19
+ properties do
20
+ cidr_block ref!(:vpc_cidr)
21
+ end
22
+ end
16
23
  end
@@ -2,7 +2,7 @@ SparkleFormation.new(:vpc) do
2
2
  resources.vpc do
3
3
  type "AWS::EC2::VPC"
4
4
  properties do
5
- cidr "10.0.0.0/16"
5
+ cidr_block "10.0.0.0/16"
6
6
  end
7
7
  end
8
8
 
@@ -26,6 +26,17 @@ describe 'be_valid' do
26
26
  expect(template).not_to be_valid
27
27
  end
28
28
  end
29
+
30
+ context "the stack fails linting" do
31
+ let(:template) { File.join('spec', 'fixtures', 'invalid_lint_template.json') }
32
+ before do
33
+ allow(cf_stub).to receive(:validate_template)
34
+ end
35
+
36
+ it 'succeeds' do
37
+ expect(template).not_to be_valid
38
+ end
39
+ end
29
40
  end
30
41
 
31
42
  describe 'be_valid_sparkleformation' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudformation_rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Robinson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-07 00:00:00.000000000 Z
11
+ date: 2020-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - ".travis.yml"
77
77
  - CODE_OF_CONDUCT.md
78
+ - Dockerfile.ci
78
79
  - Gemfile
79
80
  - LICENSE.md
80
81
  - README.md
@@ -89,6 +90,7 @@ files:
89
90
  - lib/cloudformation_rspec/resource_change.rb
90
91
  - lib/cloudformation_rspec/sparkle.rb
91
92
  - spec/change_set_spec.rb
93
+ - spec/fixtures/invalid_lint_template.json
92
94
  - spec/fixtures/invalid_sparkle_vpc_template.rb
93
95
  - spec/fixtures/template_with_compile_parameters.rb
94
96
  - spec/fixtures/valid_sparkle_vpc_template.rb
@@ -117,13 +119,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
119
  - !ruby/object:Gem::Version
118
120
  version: '0'
119
121
  requirements: []
120
- rubyforge_project:
121
- rubygems_version: 2.6.11
122
+ rubygems_version: 3.0.4
122
123
  signing_key:
123
124
  specification_version: 4
124
125
  summary: Test your CloudFormation templates
125
126
  test_files:
126
127
  - spec/change_set_spec.rb
128
+ - spec/fixtures/invalid_lint_template.json
127
129
  - spec/fixtures/invalid_sparkle_vpc_template.rb
128
130
  - spec/fixtures/template_with_compile_parameters.rb
129
131
  - spec/fixtures/valid_sparkle_vpc_template.rb