Module: TerraformConfig::Dsl

Extended by:
Forwardable
Included in:
Base
Defined in:
lib/core/terraform_config/dsl.rb

Defined Under Namespace

Classes: Context

Constant Summary collapse

EXPRESSION_PATTERN =
/(var|local|cpln_\w+)\./.freeze

Instance Method Summary collapse

Instance Method Details

#argument(name, value, optional: false, raw: false) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/core/terraform_config/dsl.rb', line 22

def argument(name, value, optional: false, raw: false)
  return if value.nil? && optional

  content =
    if value.is_a?(Hash)
      operator = raw ? ": " : " = "
      "{\n#{value.map { |n, v| "#{n}#{operator}#{tf_value(v)}" }.join("\n").indent(2)}\n}\n"
    else
      "#{tf_value(value)}\n"
    end

  # remove quotes from expression values
  content = content.gsub(/("#{EXPRESSION_PATTERN}.*")/) { ::Regexp.last_match(1)[1...-1] }

  put("#{name} = #{content}", indent: 2)
end

#block(name, *labels) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/core/terraform_config/dsl.rb', line 11

def block(name, *labels)
  switch_context do
    put("#{block_declaration(name, labels)} {\n")
    yield
    put("}\n")
  end

  # There is extra indent for whole output that needs to be removed
  output.unindent
end