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

Constructor Details

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

Returns a new instance of TerraformCmd.



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

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.



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

def bin_path
  @bin_path
end

#working_dirObject

Returns the value of attribute working_dir.



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

def working_dir
  @working_dir
end

Instance Method Details

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



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

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

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



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

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

#environment(env = {}) ⇒ Object

Raises:

  • (ArgumentError)


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

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)


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

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

  @environment = env
end

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



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

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

#inspectObject



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

def inspect
  to_s
end

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



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

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

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



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

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

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



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

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

#to_sObject



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

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