Sha256: 2e73e1b0d537b7b92993f715e77a878865a8c1df70680ef9d04f624d007e0dc1

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

module Terragov
  class Terraform

    def package_check
      unless system("which terraform >/dev/null")
        abort("Must install terraform")
      end

      unless system("which sops >/dev/null")
        abort("Must install sops")
      end
    end

    def execute(command, vars, backend, directory)
      package_check

      if command == 'init'
        puts "Running 'init' is not required as it is applied for each command"
        exit 1
      end

      Dir.chdir directory
      init(backend)

      full_command = "bash -c 'terraform #{command} #{vars}'"

      if ENV['TERRAGOV_DRYRUN']
        puts full_command
      else
        puts "#{command} command: #{full_command}" if ENV['TERRAGOV_VERBOSE']
        abort("There was an issue running the command") unless system(full_command)
      end
    end

    def init(backend_file)
      init_cmd = "terraform init -backend-config #{backend_file}"
      if ENV['TERRAGOV_DRYRUN']
        puts init_cmd
      else
        puts "init command: #{init_cmd}" if ENV['TERRAGOV_VERBOSE']
        abort("Issue running: terraform init -backend-config #{backend_file}") unless system(init_cmd)
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
terragov-0.2.1 lib/terragov/terraform.rb
terragov-0.2.0 lib/terragov/terraform.rb
terragov-0.1.0 lib/terragov/terraform.rb