Sha256: d4b30dd99633b75aad08d8e5e198bad4eb317f09654d90a8c237bd3e64920b5a

Contents?: true

Size: 796 Bytes

Versions: 2

Compression:

Stored size: 796 Bytes

Contents

class Terraspace::Terraform::Api::Vars
  class Json < Base
    def vars
      context = Terraspace::Compiler::Erb::Context.new(@mod)
      result = RenderMePretty.result(@vars_path, context: context)

      data = json_load(result)
      items = data.select do |item|
        item['data']['type'] == 'vars'
      end
      items.map { |i| i['data']['attributes'] }
    end

    def json_load(result)
      JSON.load(result)
    rescue JSON::ParserError => e
      # TODO: show exact line with error
      logger.info("ERROR in json: #{e.class}: #{e.message}")
      path = "#{Terraspace.tmp_root}/terraspace/debug/vars.json"
      logger.info("Result also written to #{path} for inspection")
      FileUtils.mkdir_p(File.dirname(path))
      IO.write(path, result)
      exit 1
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
terraspace-2.2.17 lib/terraspace/terraform/api/vars/json.rb
terraspace-2.2.16 lib/terraspace/terraform/api/vars/json.rb