Class: Pronto::TerraformFormat::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/pronto/terraform_format/wrapper.rb

Instance Method Summary collapse

Constructor Details

#initializeWrapper

Returns a new instance of Wrapper.



9
10
11
# File 'lib/pronto/terraform_format/wrapper.rb', line 9

def initialize
  @terraform_path = ENV['PRONTO_TERRAFORM_PATH'] || 'terraform'
end

Instance Method Details

#run(file_path) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pronto/terraform_format/wrapper.rb', line 13

def run(file_path)
  stdout, stderr, = Open3.capture3("#{@terraform_path} "\
                                   'fmt '\
                                   '-write=false '\
                                   '-list=false '\
                                   '-diff=true '\
                                   '-check=false '\
                                   "#{file_path}")
  if stderr && !stderr.empty?
    puts "WARN: pronto-terraform_format: #{file_path}: #{stderr}"
  end
  return [] if stdout.nil? || stdout == 0
  OutputParser.new.parse(file_path, stdout)
end