class Object

Public Instance Methods

clean_up_kitchen() click to toggle source
# File lib/validate/file_utils.rb, line 3
def clean_up_kitchen
  if File.exists? '.kitchen'
    print "INFO: Cleaning up the .kitchen folder...\n"
    FileUtils.rm_rf('.kitchen')
  end
end
clean_up_terraform() click to toggle source
# File lib/validate/file_utils.rb, line 10
def clean_up_terraform
  if File.exists? '.terraform'
    print "INFO: Cleaning up the .terraform folder...\n"
    FileUtils.rm_rf('.terraform')
  end
end
format_tf() click to toggle source
# File lib/validate/static_utils.rb, line 42
def format_tf
  # Apply the canonical format and style on current working folder.
  print "INFO: Formatting Terraform configurations...\n".yellow
  if ENV['TERRAFORM_VERSION'].nil? || ENV['TERRAFORM_VERSION'].start_with?("0.11.")
    message = `terraform fmt -diff=true 2>&1`
  elsif ENV['TERRAFORM_VERSION'].start_with?("0.12.")
    message = `terraform fmt -diff 2>&1`
  end

  # Check the styling message.
  if not message.empty?
    raise "ERROR: Formatting Terraform configurations failed!\n#{message}\n".red
  else
    print "INFO: Done!\n".green
  end
end
kitchen_converge() click to toggle source
# File lib/validate/test_kitchen.rb, line 4
def kitchen_converge
  success = system("kitchen converge")
  if not success 
    raise "ERROR: Test kitchen converge failed!\n".red
  end
end
kitchen_destroy() click to toggle source
# File lib/validate/test_kitchen.rb, line 25
def kitchen_destroy
  success = system("kitchen destroy")
  if not success 
    raise "ERROR: Test kitchen destroy failed!\n".red
  end
end
kitchen_test() click to toggle source
# File lib/validate/test_kitchen.rb, line 18
def kitchen_test
  success = system("kitchen test")
  if not success 
    raise "ERROR: Test kitchen test failed!\n".red
  end
end
kitchen_verify() click to toggle source
# File lib/validate/test_kitchen.rb, line 11
def kitchen_verify
  success = system("kitchen verify")
  if not success 
    raise "ERROR: Test kitchen verify failed!\n".red
  end
end
lint_tf() click to toggle source

To use Terraform 0.12 syntax, set ENV variable TERRAFORM_VERSION to 0.12.*

# File lib/validate/static_utils.rb, line 6
def lint_tf
  # Do the linting on current working folder.
  print "INFO: Linting Terraform configurations...\n".yellow  
  

  if ENV['TERRAFORM_VERSION'].nil? || ENV['TERRAFORM_VERSION'].start_with?("0.11.")
    message = `terraform validate -check-variables=false 2>&1`
  elsif ENV['TERRAFORM_VERSION'].start_with?("0.12.")
    message = `terraform validate >/dev/null`
  end

  # Check the linting message.
  if not message.empty?
    raise "ERROR: Linting Terraform configurations failed!\n#{message}\n".red
  else
    print "INFO: Done!\n".green
  end
end
style_tf() click to toggle source
# File lib/validate/static_utils.rb, line 25
def style_tf
  # Do the style checking on current working folder.
  print "INFO: Styling Terraform configurations...\n".yellow  
  if ENV['TERRAFORM_VERSION'].nil? || ENV['TERRAFORM_VERSION'].start_with?("0.11.")
    message = `terraform fmt -check=true 2>&1`
  elsif ENV['TERRAFORM_VERSION'].start_with?("0.12.")
    message = `terraform fmt -check 2>&1`
  end

  # Check the styling message.
  if not message.empty?
    raise "ERROR: Styling Terraform configurations failed!\n#{message}\n".red
  else
    print "INFO: Done!\n".green
  end
end