Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#clean_up_kitchenObject



3
4
5
6
7
8
# 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_terraformObject



10
11
12
13
14
15
# 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_tfObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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_convergeObject



4
5
6
7
8
9
# 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_destroyObject



25
26
27
28
29
30
# 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_testObject



18
19
20
21
22
23
# 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_verifyObject



11
12
13
14
15
16
# 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_tfObject

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



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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_tfObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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