Class: Terraspace::Terraform::Runner::Backend::Parser

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/terraspace/terraform/runner/backend/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(mod) ⇒ Parser

Returns a new instance of Parser.



7
8
9
# File 'lib/terraspace/terraform/runner/backend/parser.rb', line 7

def initialize(mod)
  @mod = mod
end

Instance Method Details

#backend_pathObject



36
37
38
39
# File 'lib/terraspace/terraform/runner/backend/parser.rb', line 36

def backend_path
  expr = "#{@mod.cache_dir}/backend.tf*"
  Dir.glob(expr).first
end

#exist?(path) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/terraspace/terraform/runner/backend/parser.rb', line 32

def exist?(path)
  path && File.exist?(path)
end

#hcl_backendObject



25
26
27
28
29
30
# File 'lib/terraspace/terraform/runner/backend/parser.rb', line 25

def hcl_backend
  return {} unless File.exist?(backend_path)
  backend_raw = HclParser.load(IO.read(backend_path))
  return {} unless backend_raw
  backend_raw.dig("terraform", "backend") || {}
end

#json_backendObject



20
21
22
23
# File 'lib/terraspace/terraform/runner/backend/parser.rb', line 20

def json_backend
  data = JSON.load(IO.read(backend_path))
  data.dig("terraform", "backend") || {}
end

#resultObject



11
12
13
14
15
16
17
18
# File 'lib/terraspace/terraform/runner/backend/parser.rb', line 11

def result
  return {} unless exist?(backend_path)
  if backend_path.include?('.json')
    json_backend
  else
    hcl_backend
  end
end