Module: SparkleFormation::SparkleAttribute::Terraform

Included in:
SparkleFormation::SparkleStruct::Terraform
Defined in:
lib/sparkle_formation/sparkle_attribute/terraform.rb

Overview

Terraform specific helper implementations

Constant Summary collapse

TERRAFORM_INTRINSIC_FUNCTIONS =
[
  'base64decode',
  'base64encode',
  'base64sha256',
  'cidrhost',
  'cidrnetmask',
  'cidrsubnet',
  'coalesce',
  'compact',
  'concat',
  'distinct',
  'element',
  'file',
  'format',
  'formatlist',
  'index',
  'join',
  'jsonencode',
  'length',
  'list',
  'lower',
  'map',
  'md5',
  'merge',
  'uuid',
  'replace',
  'sha1',
  'sha256',
  'signum',
  'sort',
  'split',
  'trimspace',
  'upper',
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

Set customized struct behavior



12
13
14
# File 'lib/sparkle_formation/sparkle_attribute/terraform.rb', line 12

def self.included(klass)
  klass.const_set(:CAMEL_KEYS, false)
end

Instance Method Details

#__resource_lookup(name) ⇒ Object



121
122
123
124
125
126
127
128
# File 'lib/sparkle_formation/sparkle_attribute/terraform.rb', line 121

def __resource_lookup(name)
  resource = root!.resources[name]
  if resource.nil?
    name
  else
    "#{resource.type}.#{name}"
  end
end

#_depends_on(resource_name) ⇒ Array<String> #_depends_on(resource_names) ⇒ Array<String> #_depends_on(*resource_names) ⇒ Array<String> Also known as: depends_on!

Note:

this will directly modify the struct at its current context to inject depends on structure

Resource dependency generator

Overloads:

  • #_depends_on(resource_name) ⇒ Array<String>

    Parameters:

    • resource_name (String, Symbol)

      logical resource name

  • #_depends_on(resource_names) ⇒ Array<String>

    Parameters:

    • resource_names (Array<String, Symbol>)

      list of logical resource names

  • #_depends_on(*resource_names) ⇒ Array<String>

    Parameters:

    • resource_names (Array<String, Symbol>)

      list of logical resource names

Returns:

  • (Array<String>)


139
140
141
# File 'lib/sparkle_formation/sparkle_attribute/terraform.rb', line 139

def _depends_on(*args)
  _set('depends_on', [args].flatten.compact.map { |s| __attribute_key(s) })
end

#_fn_format(*args) ⇒ SparkleFormation::FunctionStruct

Generate a builtin terraform function



101
102
103
104
105
# 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) ⇒ Object Also known as: module!



31
32
33
34
# 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

#_path(p_name) ⇒ Object Also known as: path!



24
25
26
27
# 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

#_resource(r_name) ⇒ Object Also known as: resource!

TODO: Add resource checking before returning structure



52
53
54
55
56
# 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

#_stack_output(stack_name, output_name) ⇒ Hash Also known as: stack_output!

Reference output value from nested stack

Parameters:

  • stack_name (String, Symbol)

    logical resource name of stack

  • output_name (String, Symbol)

    stack output name

Returns:

  • (Hash)


150
151
152
# File 'lib/sparkle_formation/sparkle_attribute/terraform.rb', line 150

def _stack_output(stack_name, output_name)
  _module(stack_name)._set(output_name)
end

#_terraform_lookup(*args) ⇒ Object Also known as: lookup!



45
46
47
# File 'lib/sparkle_formation/sparkle_attribute/terraform.rb', line 45

def _terraform_lookup(*args)
  ::SparkleFormation::TerraformStruct.new('lookup', *args)
end

#_terraform_self(s_name) ⇒ Object Also known as: self!



38
39
40
41
# 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

#_var(v_name) ⇒ Object Also known as: var!, parameter!



16
17
18
19
# 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