Module: RSpec::Terraspace::Concern

Extended by:
Memoist
Included in:
Ts
Defined in:
lib/rspec/terraspace/concern.rb

Instance Method Summary collapse

Instance Method Details

#out_pathObject



21
22
23
# File 'lib/rspec/terraspace/concern.rb', line 21

def out_path
  "#{Terraspace.tmp_root}/rspec/terraform-output.json"
end

#output(mod, name) ⇒ Object



5
6
7
# File 'lib/rspec/terraspace/concern.rb', line 5

def output(mod, name)
  outputs.dig(name, "value")
end

#outputsObject



9
10
11
12
# File 'lib/rspec/terraspace/concern.rb', line 9

def outputs
  save_output
  JSON.load(IO.read(out_path))
end

#save_outputObject

Note: a terraspace.down will remove the output.json since it does a clean



15
16
17
18
# File 'lib/rspec/terraspace/concern.rb', line 15

def save_output
  FileUtils.mkdir_p(File.dirname(out_path))
  run("output #{@mod.name} --format json --out #{out_path}")
end

#save_stateObject



39
40
41
42
# File 'lib/rspec/terraspace/concern.rb', line 39

def save_state
  FileUtils.mkdir_p(File.dirname(state_path))
  run("state pull #{@mod.name} > #{state_path}")
end

#stateObject



25
26
27
28
# File 'lib/rspec/terraspace/concern.rb', line 25

def state
  save_state
  JSON.load(IO.read(state_path))
end

#state_pathObject



45
46
47
# File 'lib/rspec/terraspace/concern.rb', line 45

def state_path
  "#{Terraspace.tmp_root}/rspec/terraform-state.json"
end

#state_resource(full_name) ⇒ Object

full_name: random_pet.this



31
32
33
34
35
36
37
# File 'lib/rspec/terraspace/concern.rb', line 31

def state_resource(full_name)
  type, name = full_name.split('.')
  state['resources'].find do |i|
    i['type'] == type && i['name'] == name || # IE: type=random_pet name=this
    i['module'] == full_name # IE: module.bucket
  end
end