Class: CemAcpt::Provision::TerraformCmd

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/cem_acpt/provision/terraform/terraform_cmd.rb

Overview

Stand-in for ruby-terraform because ruby-terraform doesn’t work with Ruby 3

Constant Summary

Constants included from Logging

Logging::LEVEL_MAP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

current_log_config, #current_log_config, current_log_format, #current_log_format, #current_log_level, current_log_level, included, #logger, logger, new_log_config, #new_log_config, new_log_formatter, #new_log_formatter, #new_log_level, new_log_level, #new_logger, new_logger, verbose?, #verbose?

Constructor Details

#initialize(working_dir = nil, environment = {}) ⇒ TerraformCmd

Returns a new instance of TerraformCmd.



18
19
20
21
22
# File 'lib/cem_acpt/provision/terraform/terraform_cmd.rb', line 18

def initialize(working_dir = nil, environment = {})
  @working_dir = working_dir
  @environment = environment
  @bin_path = which_terraform
end

Instance Attribute Details

#bin_pathObject (readonly)

Returns the value of attribute bin_path.



16
17
18
# File 'lib/cem_acpt/provision/terraform/terraform_cmd.rb', line 16

def bin_path
  @bin_path
end

#working_dirObject

Returns the value of attribute working_dir.



15
16
17
# File 'lib/cem_acpt/provision/terraform/terraform_cmd.rb', line 15

def working_dir
  @working_dir
end

Instance Method Details

#apply(opts = {}, env = {}) ⇒ Object



57
58
59
60
# File 'lib/cem_acpt/provision/terraform/terraform_cmd.rb', line 57

def apply(opts = {}, env = {})
  plan = extract_arg!(opts, :plan, required: true)
  run_cmd('apply', opts, env, suffix: plan)
end

#destroy(opts = {}, env = {}) ⇒ Object



62
63
64
# File 'lib/cem_acpt/provision/terraform/terraform_cmd.rb', line 62

def destroy(opts = {}, env = {})
  run_cmd('destroy', opts, env)
end

#environment(env = {}) ⇒ Object

Raises:

  • (ArgumentError)


38
39
40
41
42
43
44
45
# File 'lib/cem_acpt/provision/terraform/terraform_cmd.rb', line 38

def environment(env = {})
  raise ArgumentError, 'additional environment must be a Hash' unless env.is_a?(Hash)

  if env.key?(:environment) && env[:environment].is_a?(Hash)
    env = env[:environment]
  end
  @environment.merge(env)
end

#environment=(env) ⇒ Object

Raises:

  • (ArgumentError)


32
33
34
35
36
# File 'lib/cem_acpt/provision/terraform/terraform_cmd.rb', line 32

def environment=(env)
  raise ArgumentError, 'environment must be a Hash' unless env.is_a?(Hash)

  @environment = env
end

#init(opts = {}, env = {}) ⇒ Object



47
48
49
# File 'lib/cem_acpt/provision/terraform/terraform_cmd.rb', line 47

def init(opts = {}, env = {})
  run_cmd('init', opts, env)
end

#inspectObject



24
25
26
# File 'lib/cem_acpt/provision/terraform/terraform_cmd.rb', line 24

def inspect
  to_s
end

#output(opts = {}, env = {}) ⇒ Object



70
71
72
73
# File 'lib/cem_acpt/provision/terraform/terraform_cmd.rb', line 70

def output(opts = {}, env = {})
  name = extract_arg!(opts, :name, required: true)
  run_cmd('output', opts, env, suffix: name)
end

#plan(opts = {}, env = {}) ⇒ Object



51
52
53
54
55
# File 'lib/cem_acpt/provision/terraform/terraform_cmd.rb', line 51

def plan(opts = {}, env = {})
  plan = extract_arg!(opts, :plan, required: true)
  opts[:out] = plan
  run_cmd('plan', opts, env)
end

#show(opts = {}, env = {}) ⇒ Object



66
67
68
# File 'lib/cem_acpt/provision/terraform/terraform_cmd.rb', line 66

def show(opts = {}, env = {})
  run_cmd('show', opts, env)
end

#to_sObject



28
29
30
# File 'lib/cem_acpt/provision/terraform/terraform_cmd.rb', line 28

def to_s
  "#<#{self.class.name}:0x#{object_id.to_s(16)}>"
end