Class: TerraspaceHooks::TfValidator
- Inherits:
-
Object
- Object
- TerraspaceHooks::TfValidator
- Defined in:
- lib/terraspace_hooks/tf_validator.rb
Overview
validate the terraform code with terraform validate
Instance Method Summary collapse
-
#call(runner) ⇒ Object
rubocop:disable Metrics/MethodLength.
- #opentofu_available? ⇒ Boolean
-
#terraform_bin ⇒ Object
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_validator.rb', line 7 def call(runner) return if ENV['SKIP_TERRASPACE_HOOKS_ALL'] return if ENV['SKIP_TERRASPACE_HOOKS_TF_VALIDATOR'] raise 'Terraform not available' unless opentofu_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_bin} validate for #{mod.name}..." && \ #{terraform_bin} validate COMMAND system(command, exception: true) end |
#opentofu_available? ⇒ Boolean
30 31 32 |
# File 'lib/terraspace_hooks/tf_validator.rb', line 30 def opentofu_available? system("which #{terraform_bin}") end |
#terraform_bin ⇒ Object
rubocop:enable Metrics/MethodLength
26 27 28 |
# File 'lib/terraspace_hooks/tf_validator.rb', line 26 def terraform_bin ENV['TERRASPACE_HOOKS_BIN'] || 'tofu' end |