module SparkleFormation::SparkleAttribute::Terraform

Terraform specific helper implementations

Constants

TERRAFORM_INTRINSIC_FUNCTIONS

Public Class Methods

included(klass) click to toggle source

Set customized struct behavior

# File lib/sparkle_formation/sparkle_attribute/terraform.rb, line 12
def self.included(klass)
  klass.const_set(:CAMEL_KEYS, false)
end

Public Instance Methods

__resource_lookup(name) click to toggle source

Lookup resource based on name and provide formatted reference to the resource with type included.

@param name [String, Symbol] resource name @return [String] resource name

# File lib/sparkle_formation/sparkle_attribute/terraform.rb, line 126
def __resource_lookup(name)
  return name.to_s if name.to_s.include?(".")
  if root!.key?(:resources) && root!.resources.key?(name)
    resource = root!.resources[name]
    if resource.key?(:type)
      return "#{resource.type}.#{name}"
    end
  end
  if root!.key?(:resource)
    types = root!.resource._keys
    matches = types.find_all do |type|
      root!.resource._set(type).key?(name)
    end
    if matches.size > 1
      raise ArgumentError.new "Non-unique resource name. Multiple type " \
                              "matches for resource `#{name}`"
    elsif matches.size == 1
      return "#{matches.first}.#{name}"
    end
  end
  name.to_s
end
_depends_on(*args) click to toggle source

Resource dependency generator @overload _depends_on(resource_name)

@param resource_name [String, Symbol] logical resource name

@overload _depends_on(resource_names)

@param resource_names [Array<String, Symbol>] list of logical resource names

@overload _depends_on(*resource_names)

@param resource_names [Array<String, Symbol>] list of logical resource names

@return [Array<String>] @note this will directly modify the struct at its current context to inject depends on structure

# File lib/sparkle_formation/sparkle_attribute/terraform.rb, line 158
def _depends_on(*args)
  _set("depends_on", [args].flatten.compact.map { |s| __attribute_key(s) })
end
Also aliased as: depends_on!
_fn_format(*args) click to toggle source

Generate a builtin terraform function

@return [SparkleFormation::FunctionStruct]

# File lib/sparkle_formation/sparkle_attribute/terraform.rb, line 101
def _fn_format(*args)
  src = ::Kernel.__callee__.to_s
  src = ::Bogo::Utility.camel(src.sub(/(^_|\!$)/, ""), false)
  ::SparkleFormation::TerraformStruct.new(src, *args)
end
_module(m_name) click to toggle source
# File lib/sparkle_formation/sparkle_attribute/terraform.rb, line 31
def _module(m_name)
  __t_stringish(m_name)
  ::SparkleFormation::TerraformStruct.new("module").set!(__attribute_key(m_name))
end
Also aliased as: module!
_path(p_name) click to toggle source
# File lib/sparkle_formation/sparkle_attribute/terraform.rb, line 24
def _path(p_name)
  __t_stringish(p_name)
  ::SparkleFormation::TerraformStruct.new("path").set!(__attribute_key(p_name))
end
Also aliased as: path!
_resource(r_name) click to toggle source

TODO: Add resource checking before returning structure

# File lib/sparkle_formation/sparkle_attribute/terraform.rb, line 52
def _resource(r_name)
  __t_stringish(r_name)
  r_name = __resource_lookup(r_name)
  ::SparkleFormation::TerraformStruct.new(r_name)
end
Also aliased as: resource!
_stack_output(stack_name, output_name) click to toggle source

Reference output value from nested stack

@param stack_name [String, Symbol] logical resource name of stack @param output_name [String, Symbol] stack output name @return [Hash]

# File lib/sparkle_formation/sparkle_attribute/terraform.rb, line 169
def _stack_output(stack_name, output_name)
  _module(stack_name)._set(output_name)
end
Also aliased as: stack_output!
_terraform_lookup(*args) click to toggle source
# File lib/sparkle_formation/sparkle_attribute/terraform.rb, line 45
def _terraform_lookup(*args)
  ::SparkleFormation::TerraformStruct.new("lookup", *args)
end
Also aliased as: lookup!
_terraform_self(s_name) click to toggle source
# File lib/sparkle_formation/sparkle_attribute/terraform.rb, line 38
def _terraform_self(s_name)
  __t_stringish(s_name)
  ::SparkleFormation::TerraformStruct.new("self").set!(__attribute_key(s_name))
end
Also aliased as: self!
_var(v_name) click to toggle source
# File lib/sparkle_formation/sparkle_attribute/terraform.rb, line 16
def _var(v_name)
  __t_stringish(v_name)
  res = ::SparkleFormation::TerraformStruct.new("var").set!(__attribute_key(v_name))
end
Also aliased as: var!, parameter!
depends_on!(*args)
Alias for: _depends_on
lookup!(*args)
Alias for: _terraform_lookup
module!(m_name)
Alias for: _module
parameter!(v_name)
Alias for: _var
path!(p_name)
Alias for: _path
resource!(r_name)
Alias for: _resource
self!(s_name)
Alias for: _terraform_self
stack_output!(stack_name, output_name)
Alias for: _stack_output
var!(v_name)
Alias for: _var