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 = <<-COMMAND
    YELLOW='\033[0;33m'
    NC='\033[0m'
    cd #{mod.cache_dir} && \
    echo "${YELLOW}[INFO #{mod.name}]${NC} Run tflint for #{mod.name}..." && \
    tflint . --disable-rule=terraform_required_version --module
  COMMAND

  system(command, exception: true)
end

#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