Sha256: 4729919348e294ff10d54e3479d8fb09e07df6debc73d8c2aecfcf28cc3b1f2d

Contents?: true

Size: 856 Bytes

Versions: 53

Compression:

Stored size: 856 Bytes

Contents

require "hcl_parser"

class Terraspace::Compiler::Backend
  class Parser
    extend Memoist

    def initialize(mod)
      @mod = mod
    end

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

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

    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

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

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

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
terraspace-0.6.23 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.22 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.21 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.20 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.19 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.18 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.17 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.16 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.15 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.13 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.12 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.11 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.10 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.9 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.8 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.7 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.6 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.5 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.4 lib/terraspace/compiler/backend/parser.rb
terraspace-0.6.3 lib/terraspace/compiler/backend/parser.rb