terraspace_hooks 0.1.1 → 0.2.2

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
2
  SHA256:
3
- metadata.gz: 0c8425e565615e04f849ac80b7b5ef892fe9b8b517d5f49c768ba951cbeeafa0
4
- data.tar.gz: 16e2cdc8ea72c276caa1bdd58d0ff736e80b6b2505d0e124470467027f169395
3
+ metadata.gz: 88a091069723549e82176aec851e7796e97757a3e05c466b5700af981e4b4b3e
4
+ data.tar.gz: 7c92d6e9a25961c6247cb9ef895cd69d96c9c7c4139ef4c56787a8894157858e
5
5
  SHA512:
6
- metadata.gz: b8c48cbcc411d5c8528cbc82106b4e3a848ed96d6ac7131a7a0db2431ab35fbe57d3560828efe7eef9b2be61f9ce808ff140951a4315c8362eb1b1b19f95d67b
7
- data.tar.gz: d82ccce566a807540c22c3adc3dab2d024741fa95989f4bd11f09e430b90c6ec51213a7f963fe826b88ac8c6adafce1c03ad101f9529766c681acf4b4ed7825b
6
+ metadata.gz: 41dea204776e26e5e3f95fcd1f4af172066866caafe376a59d0ab646390eea6e7ffcc43ca74d7fdc68dde9b0738ff0d94c316623068e325663ea8c1069128a2e
7
+ data.tar.gz: ae9cc8efa4fe98b87ef1dcc8297bd574bca10fa8de961ac70afe3eb75106600dc7f281d97702da5d767edea9b11d23745aeeda16261e4cde1cc25e4cb5ad0c3f
data/.rubocop.yml CHANGED
@@ -1,13 +1,3 @@
1
- AllCops:
2
- TargetRubyVersion: 2.6
1
+ inherit_from: .rubocop_todo.yml
3
2
 
4
- Style/StringLiterals:
5
- Enabled: true
6
- EnforcedStyle: double_quotes
7
-
8
- Style/StringLiteralsInInterpolation:
9
- Enabled: true
10
- EnforcedStyle: double_quotes
11
-
12
- Layout/LineLength:
13
- Max: 120
3
+ require: rubocop-rake
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,7 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2023-03-23 23:34:39 UTC using RuboCop version 1.44.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
data/Gemfile CHANGED
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in terraspace_hooks.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ gem 'rake', '~> 13.0'
9
9
 
10
- gem "minitest", "~> 5.0"
10
+ gem 'minitest', '~> 5.0'
11
11
 
12
- gem "rubocop", "~> 1.21"
12
+ gem 'standard'
13
+
14
+ gem 'rubocop-rake'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- terraspace_hooks (0.1.0)
4
+ terraspace_hooks (0.2.1)
5
5
  zeitwerk (~> 2.6.7)
6
6
 
7
7
  GEM
@@ -9,6 +9,7 @@ GEM
9
9
  specs:
10
10
  ast (2.4.2)
11
11
  json (2.6.3)
12
+ language_server-protocol (3.17.0.3)
12
13
  minitest (5.17.0)
13
14
  parallel (1.22.1)
14
15
  parser (3.2.1.0)
@@ -17,30 +18,41 @@ GEM
17
18
  rake (13.0.6)
18
19
  regexp_parser (2.7.0)
19
20
  rexml (3.2.5)
20
- rubocop (1.46.0)
21
+ rubocop (1.44.1)
21
22
  json (~> 2.3)
22
23
  parallel (~> 1.10)
23
24
  parser (>= 3.2.0.0)
24
25
  rainbow (>= 2.2.2, < 4.0)
25
26
  regexp_parser (>= 1.8, < 3.0)
26
27
  rexml (>= 3.2.5, < 4.0)
27
- rubocop-ast (>= 1.26.0, < 2.0)
28
+ rubocop-ast (>= 1.24.1, < 2.0)
28
29
  ruby-progressbar (~> 1.7)
29
30
  unicode-display_width (>= 2.4.0, < 3.0)
30
31
  rubocop-ast (1.26.0)
31
32
  parser (>= 3.2.1.0)
33
+ rubocop-performance (1.15.2)
34
+ rubocop (>= 1.7.0, < 2.0)
35
+ rubocop-ast (>= 0.4.0)
36
+ rubocop-rake (0.6.0)
37
+ rubocop (~> 1.0)
32
38
  ruby-progressbar (1.11.0)
39
+ standard (1.24.3)
40
+ language_server-protocol (~> 3.17.0.2)
41
+ rubocop (= 1.44.1)
42
+ rubocop-performance (= 1.15.2)
33
43
  unicode-display_width (2.4.2)
34
44
  zeitwerk (2.6.7)
35
45
 
36
46
  PLATFORMS
37
47
  arm64-darwin-22
48
+ x86_64-linux
38
49
 
39
50
  DEPENDENCIES
40
51
  minitest (~> 5.0)
41
52
  rake (~> 13.0)
42
- rubocop (~> 1.21)
53
+ rubocop-rake
54
+ standard
43
55
  terraspace_hooks!
44
56
 
45
57
  BUNDLED WITH
46
- 2.4.7
58
+ 2.4.8
data/README.md CHANGED
@@ -15,15 +15,49 @@ Install the gem and add to the application's Gemfile by executing:
15
15
  ```ruby
16
16
 
17
17
  # inside config/hooks/terraform.rb
18
+
19
+ # run `tflint` before # terraform plan
18
20
  before("plan", execute: TerraspaceHooks::TflintValidator)
21
+
22
+ # run `terraform validate` before terraform plan
19
23
  before("plan", execute: TerraspaceHooks::TfValidator)
24
+
25
+ # generate infracost output after terraform plan
20
26
  after("plan", execute: TerraspaceHooks::InfracostGenerator)
27
+ ```
21
28
 
29
+ ```ruby
22
30
  # inside config/hooks/terraspace.rb
31
+
32
+ # Run `terraform fmt` after terraspace build
23
33
  after("build", execute: TerraspaceHooks::TfFmtValidator)
34
+
35
+ # Run `tfsec` after terraspace build
24
36
  after("build", execute: TerraspaceHooks::TfsecValidator)
25
37
  ```
26
38
 
39
+ To use InfracostGenerator, you need to add this line in
40
+ `config/args/terraform.rb`
41
+
42
+ ```ruby
43
+ command("plan", args: ["-out tfplan.binary"])
44
+ ```
45
+
46
+ Setting this each environment_variable below will skip the correspondent hook.
47
+
48
+ ```bash
49
+ SKIP_TERRASPACE_HOOKS_TFSEC_VALIDATOR=1
50
+ SKIP_TERRASPACE_HOOKS_TFLINT_VALIDATOR=1
51
+ SKIP_TERRASPACE_HOOKS_TF_VALIDATOR=1
52
+ SKIP_TERRASPACE_HOOKS_TF_FMT_VALIDATOR=1
53
+ SKIP_TERRASPACE_HOOKS_INFRACOST_GENERATOR=1
54
+
55
+ # or
56
+
57
+ SKIP_TERRASPACE_HOOKS_ALL=1
58
+ # to skip all the hooks
59
+ ```
60
+
27
61
  ## License
28
62
 
29
63
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,16 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+ require 'standard/rake'
5
6
 
6
7
  Rake::TestTask.new(:test) do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/test_*.rb"]
8
+ t.libs << 'test'
9
+ t.libs << 'lib'
10
+ t.test_files = FileList['test/**/test_*.rb']
10
11
  end
11
12
 
12
- require "rubocop/rake_task"
13
-
14
- RuboCop::RakeTask.new
15
-
16
- task default: %i[test rubocop]
13
+ task default: %i[test standard:fix]
@@ -1,33 +1,39 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TerraspaceHooks
4
+ # generate infracost breakdown
2
5
  class InfracostGenerator
6
+ # rubocop:disable Metrics/MethodLength
3
7
  def call(runner)
4
- raise "Infracost not available" unless infracost_available?
5
- raise "Terraform not available" unless terraform_available?
8
+ raise 'Infracost not available' unless infracost_available?
9
+ raise 'Terraform not available' unless terraform_available?
6
10
 
7
11
  mod = runner.mod
8
- command = <<-EOF
9
- YELLOW='\033[0;33m'
10
- NC='\033[0m'
11
- cd #{mod.cache_dir} && \
12
- echo "${YELLOW}[INFO #{mod.name}]${NC} Convert to plan.json..." && \
13
- terraform show -json tfplan.binary > plan.json && \
12
+ command = <<-COMMAND
13
+ YELLOW='\033[0;33m'
14
+ NC='\033[0m'
15
+ cd #{mod.cache_dir} && \
16
+ echo "${YELLOW}[INFO #{mod.name}]${NC} Convert to plan.json..." && \
17
+ terraform show -json tfplan.binary > plan.json && \
14
18
 
15
- echo "${YELLOW}[INFO #{mod.name}]${NC} Infracost breakdown for #{mod.name}..." && \
16
- infracost breakdown --project-name #{mod.name} --path plan.json --format json --out-file infracost_breakdown.json && \
17
- infracost output --path infracost_breakdown.json --format table --show-skipped
18
- EOF
19
+ echo "${YELLOW}[INFO #{mod.name}]${NC} Infracost breakdown for #{mod.name}..." && \
20
+ infracost breakdown --project-name #{mod.name} --path plan.json --format json --out-file infracost_breakdown.json && \
21
+ infracost output --path infracost_breakdown.json --format table --show-skipped
22
+ COMMAND
19
23
 
20
- return if ENV["SKIP_TERRASPACE_HOOKS_INFRACOST_GENERATOR"]
24
+ return if ENV['SKIP_TERRASPACE_HOOKS_ALL']
25
+ return if ENV['SKIP_TERRASPACE_HOOKS_INFRACOST_GENERATOR']
21
26
 
22
- system(command)
27
+ system(command, exception: true)
23
28
  end
29
+ # rubocop:enable Metrics/MethodLength
24
30
 
25
31
  def infracost_available?
26
- system("which infracost")
32
+ system('which infracost')
27
33
  end
28
34
 
29
35
  def terraform_available?
30
- system("which terraform")
36
+ system('which terraform')
31
37
  end
32
38
  end
33
39
  end
@@ -1,24 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TerraspaceHooks
4
+ # validate the terraform code with terraform fmt
2
5
  class TfFmtValidator
6
+ # rubocop:disable Metrics/MethodLength
3
7
  def call(runner)
4
- raise "Terraform not available" unless terraform_available?
8
+ raise 'Terraform not available' unless terraform_available?
5
9
 
6
10
  mod = runner.mod
7
- command = <<-EOF
8
- YELLOW='\033[0;33m'
9
- NC='\033[0m'
10
- cd #{mod.cache_dir} && \
11
- echo "${YELLOW}[INFO #{mod.name}]${NC} Run terraform fmt for #{mod.name}..." && \
12
- terraform fmt
13
- EOF
11
+ command = <<-COMMAND
12
+ YELLOW='\033[0;33m'
13
+ NC='\033[0m'
14
+ cd #{mod.cache_dir} && \
15
+ echo "${YELLOW}[INFO #{mod.name}]${NC} Run terraform fmt for #{mod.name}..." && \
16
+ terraform fmt
17
+ COMMAND
14
18
 
15
- return if ENV["SKIP_TERRASPACE_HOOKS_TF_FMT_VALIDATOR"]
19
+ return if ENV['SKIP_TERRASPACE_HOOKS_ALL']
20
+ return if ENV['SKIP_TERRASPACE_HOOKS_TF_FMT_VALIDATOR']
16
21
 
17
- system(command)
22
+ system(command, exception: true)
18
23
  end
24
+ # rubocop:enable Metrics/MethodLength
19
25
 
20
26
  def terraform_available?
21
- system("which terraform")
27
+ system('which terraform')
22
28
  end
23
29
  end
24
30
  end
@@ -1,24 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TerraspaceHooks
4
+ # validate the terraform code with terraform validate
2
5
  class TfValidator
6
+ # rubocop:disable Metrics/MethodLength
3
7
  def call(runner)
4
- raise "Terraform not available" unless terraform_available?
8
+ raise 'Terraform not available' unless terraform_available?
5
9
 
6
10
  mod = runner.mod
7
- command = <<-EOF
8
- YELLOW='\033[0;33m'
9
- NC='\033[0m'
10
- cd #{mod.cache_dir} && \
11
- echo "${YELLOW}[INFO #{mod.name}]${NC} Run terraform validate for #{mod.name}..." && \
12
- terraform validate
13
- EOF
11
+ command = <<-COMMAND
12
+ YELLOW='\033[0;33m'
13
+ NC='\033[0m'
14
+ cd #{mod.cache_dir} && \
15
+ echo "${YELLOW}[INFO #{mod.name}]${NC} Run terraform validate for #{mod.name}..." && \
16
+ terraform validate
17
+ COMMAND
14
18
 
15
- return if ENV["SKIP_TERRASPACE_HOOKS_TF_VALIDATOR"]
19
+ return if ENV['SKIP_TERRASPACE_HOOKS_ALL']
20
+ return if ENV['SKIP_TERRASPACE_HOOKS_TF_VALIDATOR']
16
21
 
17
- system(command)
22
+ system(command, exception: true)
18
23
  end
24
+ # rubocop:enable Metrics/MethodLength
19
25
 
20
26
  def terraform_available?
21
- system("which terraform")
27
+ system('which terraform')
22
28
  end
23
29
  end
24
30
  end
@@ -1,24 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TerraspaceHooks
4
+ # validate the terraform code with tflint
2
5
  class TflintValidator
6
+ # rubocop:disable Metrics/MethodLength
3
7
  def call(runner)
4
- raise "Tflint not available" unless tflint_available?
8
+ raise 'Tflint not available' unless tflint_available?
5
9
 
6
10
  mod = runner.mod
7
- command = <<-EOF
8
- YELLOW='\033[0;33m'
9
- NC='\033[0m'
10
- cd #{mod.cache_dir} && \
11
- echo "${YELLOW}[INFO #{mod.name}]${NC} Run tflint for #{mod.name}..." && \
12
- tflint . --disable-rule=terraform_required_version --module
13
- EOF
11
+ command = <<-COMMAND
12
+ YELLOW='\033[0;33m'
13
+ NC='\033[0m'
14
+ cd #{mod.cache_dir} && \
15
+ echo "${YELLOW}[INFO #{mod.name}]${NC} Run tflint for #{mod.name}..." && \
16
+ tflint . --disable-rule=terraform_required_version --module
17
+ COMMAND
14
18
 
15
- return if ENV["SKIP_TERRASPACE_HOOKS_TFLINT_VALIDATOR"]
19
+ return if ENV['SKIP_TERRASPACE_HOOKS_ALL']
20
+ return if ENV['SKIP_TERRASPACE_HOOKS_TFLINT_VALIDATOR']
16
21
 
17
- system(command)
22
+ system(command, exception: true)
18
23
  end
24
+ # rubocop:enable Metrics/MethodLength
19
25
 
20
26
  def tflint_available?
21
- system("which tflint")
27
+ system('which tflint')
22
28
  end
23
29
  end
24
30
  end
@@ -1,24 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TerraspaceHooks
4
+ # validate the terraform code with tfsec
2
5
  class TfsecValidator
6
+ # rubocop:disable Metrics/MethodLength
3
7
  def call(runner)
4
- raise "Tfsec not available" unless tfsec_available?
8
+ raise 'Tfsec not available' unless tfsec_available?
5
9
 
6
10
  mod = runner.mod
7
- command = <<-EOF
8
- YELLOW='\033[0;33m'
9
- NC='\033[0m'
10
- cd #{mod.cache_dir} && \
11
- echo "${YELLOW}[INFO #{mod.name}]${NC} Run tfsec for #{mod.name}..." && \
12
- tfsec --concise-output
13
- EOF
11
+ command = <<-COMMAND
12
+ YELLOW='\033[0;33m'
13
+ NC='\033[0m'
14
+ cd #{mod.cache_dir} && \
15
+ echo "${YELLOW}[INFO #{mod.name}]${NC} Run tfsec for #{mod.name}..." && \
16
+ tfsec --concise-output
17
+ COMMAND
14
18
 
15
- return if ENV["SKIP_TERRASPACE_HOOKS_TFSEC_VALIDATOR"]
19
+ return if ENV['SKIP_TERRASPACE_HOOKS_ALL']
20
+ return if ENV['SKIP_TERRASPACE_HOOKS_TFSEC_VALIDATOR']
16
21
 
17
- system(command)
22
+ system(command, exception: true)
18
23
  end
24
+ # rubocop:enable Metrics/MethodLength
19
25
 
20
26
  def tfsec_available?
21
- system("which tfsec")
27
+ system('which tfsec')
22
28
  end
23
29
  end
24
30
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TerraspaceHooks
4
- VERSION = "0.1.1"
4
+ VERSION = '0.2.2'
5
5
  end
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "zeitwerk"
3
+ require 'zeitwerk'
4
4
  loader = Zeitwerk::Loader.for_gem
5
5
  loader.setup
6
6
 
7
+ # TerraspaceHooks is the namespace for all Terraspace Hooks
7
8
  module TerraspaceHooks
8
9
  end
9
10
 
@@ -1,22 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/terraspace_hooks/version"
3
+ require_relative 'lib/terraspace_hooks/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "terraspace_hooks"
6
+ spec.name = 'terraspace_hooks'
7
7
  spec.version = TerraspaceHooks::VERSION
8
- spec.authors = ["slamet kristanto"]
9
- spec.email = ["botoksgonzales@gmail.com"]
8
+ spec.authors = ['slamet kristanto']
9
+ spec.email = ['botoksgonzales@gmail.com']
10
10
 
11
- spec.summary = "Useful terraspace hook collection (infracost generator, tflint, tf validate)"
12
- spec.description = "Useful terraspace hook collection (infracost generator, tflint, tf validate)"
13
- spec.homepage = "https://github.com/drselump14/terraspace_hooks"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.6.0"
11
+ spec.summary = 'Useful terraspace hook collection (infracost generator, tflint, tf validate)'
12
+ spec.description = 'Useful terraspace hook collection (infracost generator, tflint, tf validate)'
13
+ spec.homepage = 'https://github.com/drselump14/terraspace_hooks'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 2.6.0'
16
16
 
17
- spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = "https://github.com/drselump14/terraspace_hooks"
19
- spec.metadata["changelog_uri"] = "https://github.com/drselump14/terraspace_hooks"
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/drselump14/terraspace_hooks'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/drselump14/terraspace_hooks'
20
20
 
21
21
  # Specify which files should be added to the gem when it is released.
22
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -25,12 +25,12 @@ Gem::Specification.new do |spec|
25
25
  (File.expand_path(f) == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
26
26
  end
27
27
  end
28
- spec.bindir = "exe"
28
+ spec.bindir = 'exe'
29
29
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
- spec.require_paths = ["lib"]
30
+ spec.require_paths = ['lib']
31
31
 
32
32
  # Uncomment to register a new dependency of your gem
33
- spec.add_dependency "zeitwerk", "~> 2.6.7"
33
+ spec.add_dependency 'zeitwerk', '~> 2.6.7'
34
34
 
35
35
  # For more information and examples about making a new gem, check out our
36
36
  # guide at: https://bundler.io/guides/creating_gem.html
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraspace_hooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - slamet kristanto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-27 00:00:00.000000000 Z
11
+ date: 2023-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -32,6 +32,7 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - ".rubocop.yml"
35
+ - ".rubocop_todo.yml"
35
36
  - CHANGELOG.md
36
37
  - CODE_OF_CONDUCT.md
37
38
  - Gemfile
@@ -70,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
71
  - !ruby/object:Gem::Version
71
72
  version: '0'
72
73
  requirements: []
73
- rubygems_version: 3.4.7
74
+ rubygems_version: 3.4.13
74
75
  signing_key:
75
76
  specification_version: 4
76
77
  summary: Useful terraspace hook collection (infracost generator, tflint, tf validate)