Sha256: 1c224ed55fbe7ef3dd37af0102af78543616b930faf4bb76f0b49715a7c9a886

Contents?: true

Size: 941 Bytes

Versions: 5

Compression:

Stored size: 941 Bytes

Contents

module Terraspace::Terraform::Args
  class Custom
    extend Memoist
    include Dsl
    include DslEvaluator

    attr_accessor :name
    def initialize(mod, name)
      @mod, @name = mod, name
      @file = "#{Terraspace.root}/config/args/terraform.rb"
      @commands = {}
    end

    def build
      return @commands unless File.exist?(@file)
      evaluate_file(@file)
      @commands.deep_stringify_keys!
    end
    memoize :build

    def args
      build
      args = dig("args")
      args.compact.flatten
    end

    def var_files
      build
      var_files = dig("var_files")
      var_files.select! { |f| var_file_exist?(f) }
      var_files.map { |f| "-var-file=#{f}" }
    end

    def env_vars
      build
      dig("env", {})
    end

    def var_file_exist?(var_file)
      File.exist?("#{@mod.cache_dir}/#{var_file}")
    end

    def dig(prop, default=[])
      @commands.dig(@name, prop) || default
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
terraspace-0.4.4 lib/terraspace/terraform/args/custom.rb
terraspace-0.4.3 lib/terraspace/terraform/args/custom.rb
terraspace-0.4.2 lib/terraspace/terraform/args/custom.rb
terraspace-0.4.1 lib/terraspace/terraform/args/custom.rb
terraspace-0.4.0 lib/terraspace/terraform/args/custom.rb