class Terraspace::Compiler::Backend::Parser

Public Class Methods

new(mod) click to toggle source
# File lib/terraspace/compiler/backend/parser.rb, line 7
def initialize(mod)
  @mod = mod
end

Public Instance Methods

backend_path() click to toggle source
# File lib/terraspace/compiler/backend/parser.rb, line 36
def backend_path
  expr = "#{@mod.cache_dir}/backend.tf*"
  Dir.glob(expr).first
end
exist?(path) click to toggle source
# File lib/terraspace/compiler/backend/parser.rb, line 32
def exist?(path)
  path && File.exist?(path)
end
hcl_backend() click to toggle source
# File lib/terraspace/compiler/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_backend() click to toggle source
# File lib/terraspace/compiler/backend/parser.rb, line 20
def json_backend
  data = JSON.load(IO.read(backend_path))
  data.dig("terraform", "backend") || {}
end
result() click to toggle source
# File lib/terraspace/compiler/backend/parser.rb, line 11
def result
  return {} unless exist?(backend_path)
  if backend_path.include?('.json')
    json_backend
  else
    hcl_backend
  end
end