module SparkleFormation::SparkleAttribute::Terraform
Terraform
specific helper implementations
Constants
- TERRAFORM_INTRINSIC_FUNCTIONS
Public Class Methods
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
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
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
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
# 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
# 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
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
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
# File lib/sparkle_formation/sparkle_attribute/terraform.rb, line 45 def _terraform_lookup(*args) ::SparkleFormation::TerraformStruct.new("lookup", *args) end
# 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
# 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