Class: TerraspaceHooks::TflintValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/terraspace_hooks/tflint_validator.rb

Overview

validate the terraform code with tflint

Instance Method Summary collapse

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/tflint_validator.rb', line 7

def call(runner)
  return if ENV['SKIP_TERRASPACE_HOOKS_ALL']
  return if ENV['SKIP_TERRASPACE_HOOKS_TFLINT_VALIDATOR']

  raise 'Tflint not available' unless tflint_available?

  mod = runner.mod
  command = "    YELLOW='\\033[0;33m'\n    NC='\\033[0m'\n    cd \#{mod.cache_dir} && \\\n    echo \"${YELLOW}[INFO \#{mod.name}]${NC} Run tflint for \#{mod.name}...\" && \\\n    tflint --disable-rule=terraform_required_version --call-module-type=all\n  COMMAND\n\n  system(command, exception: true)\nend\n"

#tflint_available?Boolean

rubocop:enable Metrics/MethodLength

Returns:

  • (Boolean)


26
27
28
# File 'lib/terraspace_hooks/tflint_validator.rb', line 26

def tflint_available?
  system('which tflint')
end