Class: Covalence::TerraformCli

Inherits:
Object
  • Object
show all
Defined in:
lib/covalence/core/cli_wrappers/terraform_cli.rb

Class Method Summary collapse

Class Method Details

.loggerObject



126
127
128
# File 'lib/covalence/core/cli_wrappers/terraform_cli.rb', line 126

def self.logger
  Covalence::LOGGER
end

.require_initObject



13
14
15
16
17
18
19
20
# File 'lib/covalence/core/cli_wrappers/terraform_cli.rb', line 13

def self.require_init()
  if Semantic::Version.new(Covalence::TERRAFORM_VERSION) < Semantic::Version.new("0.9.0")
    raise "Terraform v0.9.0 or newer required"
  else
    cmds_yml = File.expand_path("terraform.yml", __dir__)
  end
  init_terraform_cmds(cmds_yml)
end

.terraform_check_style(path) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/covalence/core/cli_wrappers/terraform_cli.rb', line 36

def self.terraform_check_style(path)
  cmd = [Covalence::TERRAFORM_CMD, "fmt", "-check"]

  output = PopenWrapper.run(
      cmd,
      path,
      '',
      ignore_exitcode: false)
  (output == 0)
end

.terraform_clean(path, dry_run: false, verbose: true) ⇒ Object

:reek:BooleanParameter



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/covalence/core/cli_wrappers/terraform_cli.rb', line 23

def self.terraform_clean(path, dry_run: false, verbose: true)
  # standard run shouldn't need this since it does a chdir on a temp dir anyway
  # something about cln_cmd when working with docker images
  targets = [ File.join(File.expand_path(path), ".terraform") ] +
    Dir.glob(File.join(File.expand_path(path), "*.tfstate*"))

  FileUtils.rm_rf(targets, {
    noop: dry_run,
    verbose: verbose,
    secure: true,
  })
end

.terraform_get(path = Dir.pwd, workdir = Dir.pwd, args: '', ignore_exitcode: false) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/covalence/core/cli_wrappers/terraform_cli.rb', line 63

def self.terraform_get(path=Dir.pwd, workdir=Dir.pwd, args: '', ignore_exitcode: false)
  cmd = [Covalence::TERRAFORM_CMD, "get", path]

  output = PopenWrapper.run(
      cmd,
      path,
      args,
      ignore_exitcode: ignore_exitcode,
      workdir: workdir)

  (output == 0)
end

.terraform_init(path: '', workdir: Dir.pwd, args: '', ignore_exitcode: false) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/covalence/core/cli_wrappers/terraform_cli.rb', line 47

def self.terraform_init(path: '', workdir: Dir.pwd, args: '', ignore_exitcode: false)
  if ENV['TF_PLUGIN_LOCAL'] == 'true'
    cmd = [Covalence::TERRAFORM_CMD, "init", "-get-plugins=false", "-get=false", "-input=false", "-plugin-dir=#{Covalence::TERRAFORM_PLUGIN_CACHE}"]
  else
    cmd = [Covalence::TERRAFORM_CMD, "init", "-get-plugins=#{Covalence::TERRAFORM_GET_PLUGINS ? 'true' : 'false'}", "-get=false", "-input=false"]
  end

  output = PopenWrapper.run(
    cmd,
    path,
    args,
    ignore_exitcode: ignore_exitcode,
    workdir: workdir)
  (output == 0)
end

.terraform_output(output_var, args: '') ⇒ Object



114
115
116
# File 'lib/covalence/core/cli_wrappers/terraform_cli.rb', line 114

def self.terraform_output(output_var, args: '')
  raise "TODO: implement me"
end

.terraform_plan(path: '', workdir: Dir.pwd, args: '', ignore_exitcode: false) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/covalence/core/cli_wrappers/terraform_cli.rb', line 76

def self.terraform_plan(path: '', workdir: Dir.pwd, args: '', ignore_exitcode: false)
  cmd = [Covalence::TERRAFORM_CMD, "plan"]

  output = PopenWrapper.run(
      cmd,
      path,
      args,
      ignore_exitcode: ignore_exitcode,
      workdir: workdir)

  (output == 0)
end

.terraform_taint(resource_name, args: '') ⇒ Object



118
119
120
# File 'lib/covalence/core/cli_wrappers/terraform_cli.rb', line 118

def self.terraform_taint(resource_name, args: '')
  raise "TODO: implement me"
end

.terraform_untaint(resource_name, args: '') ⇒ Object



122
123
124
# File 'lib/covalence/core/cli_wrappers/terraform_cli.rb', line 122

def self.terraform_untaint(resource_name, args: '')
  raise "TODO: implement me"
end

.terraform_validate(path, workdir, args: '', ignore_exitcode: false) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/covalence/core/cli_wrappers/terraform_cli.rb', line 89

def self.terraform_validate(path, workdir, args: '', ignore_exitcode: false)
  cmd = [Covalence::TERRAFORM_CMD, "validate"]

  output = PopenWrapper.run(
      cmd,
      path,
      args,
      ignore_exitcode: ignore_exitcode,
      workdir: workdir)

  (output == 0)
end

.terraform_workspace(workspace, path = '', args: '', ignore_exitcode: false) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/covalence/core/cli_wrappers/terraform_cli.rb', line 102

def self.terraform_workspace(workspace, path='', args: '', ignore_exitcode: false)
  cmd = [Covalence::TERRAFORM_CMD, "workspace", "new", workspace]

  output = PopenWrapper.run(
    cmd,
    path,
    args,
    ignore_exitcode: ignore_exitcode)

  (output == 0)
end