class WdiTf::Main
Public Instance Methods
build_workspace(files:)
click to toggle source
# File lib/wdi_tf/main.rb, line 32 def build_workspace(files:) verbose("Building workspace.") files.each do |d_file, s_file| verbose(" symlinking #{ s_file }") File.symlink(s_file, d_file) end end
clean_workspace()
click to toggle source
# File lib/wdi_tf/main.rb, line 6 def clean_workspace verbose("Cleaning workspace.") Dir["*.tf"].each do |file| if File.symlink?(file) verbose(" removing #{ file }") File.delete(file) end end end
generate_vars_file(file:, vars:)
click to toggle source
# File lib/wdi_tf/main.rb, line 17 def generate_vars_file(file:, vars:) if vars.length > 0 verbose("Generate the #{ file } file from Terraform.proj information.") open(file, 'w') do |f| vars.each do |var, val| verbose(" #{ var } = \"#{ val }\"") f.puts "#{ var } = \"#{ val }\"" end end elsif File.exists?(file) File.delete(file) end end
run_terraform(command:, variables:)
click to toggle source
# File lib/wdi_tf/main.rb, line 41 def run_terraform(command:, variables:) info("Running Terraform command.") cmd = "terraform init && terraform #{ command }" if File.exists?(variables) cmd = "#{ cmd } -var-file=#{ variables }" end if command == 'apply' cmd = "#{ cmd } -auto-approve" end if command == 'destroy' cmd = "#{ cmd } -force" end info(" #{ cmd }") Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr| while line = stdout_err.gets puts line end exit_status = wait_thr.value unless exit_status.success? abort "FAILED !!! #{cmd}" end end end