Class: TerraspaceHooks::TfsecValidator

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

Overview

validate the terraform code with tfsec

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

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

  raise 'Tfsec not available' unless tfsec_available?

  mod = runner.mod
  command = <<-COMMAND
    YELLOW='\033[0;33m'
    NC='\033[0m'
    cd #{mod.cache_dir} && \
    echo "${YELLOW}[INFO #{mod.name}]${NC} Run tfsec for #{mod.name}..." && \
    tfsec --concise-output
  COMMAND

  system(command, exception: true)
end

#tfsec_available?Boolean

rubocop:enable Metrics/MethodLength

Returns:

  • (Boolean)


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

def tfsec_available?
  system('which tfsec')
end