Class: TerraspaceHooks::TfFmtValidator
- Inherits:
-
Object
- Object
- TerraspaceHooks::TfFmtValidator
- Defined in:
- lib/terraspace_hooks/tf_fmt_validator.rb
Overview
validate the terraform code with terraform fmt
Instance Method Summary collapse
-
#call(runner) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#terraform_available? ⇒ Boolean
rubocop:enable Metrics/MethodLength.
Instance Method Details
#call(runner) ⇒ Object
rubocop:disable Metrics/MethodLength
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/terraspace_hooks/tf_fmt_validator.rb', line 7 def call(runner) return if ENV['SKIP_TERRASPACE_HOOKS_ALL'] return if ENV['SKIP_TERRASPACE_HOOKS_TF_FMT_VALIDATOR'] raise 'Terraform not available' unless terraform_available? mod = runner.mod command = <<-COMMAND YELLOW='\033[0;33m' NC='\033[0m' cd #{mod.cache_dir} && \ echo "${YELLOW}[INFO #{mod.name}]${NC} Run terraform fmt for #{mod.name}..." && \ terraform fmt COMMAND system(command, exception: true) end |
#terraform_available? ⇒ Boolean
rubocop:enable Metrics/MethodLength
26 27 28 |
# File 'lib/terraspace_hooks/tf_fmt_validator.rb', line 26 def terraform_available? system('which terraform') end |