module Convection::DSL::TerraformIntrinsicFunctions

AWS psuedo-functions overridden to be terraform compatible, sort of!

Public Class Methods

extended(base) click to toggle source
Calls superclass method
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 8
def self.extended(base)
  return base.include(self) if base.is_a?(Class) || base.is_a?(Module)

  super
end
overload(objects) click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 14
def self.overload(objects)
  mod = self
  objects.each { |o| o.extend(mod) }
end

Public Instance Methods

base64(_content) click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 19
def base64(_content)
  %q(base64(#{content.to_json}))
end
find_in_map(*) click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 58
def find_in_map(*)
  warn "WARNING: Fn::FindInMap cannot be inferred when migrating to terraform. Please consult with the interpolation syntax terraform docs #{self.class}(#{terraform_name})"
  '${lookup(lookup(YOUR_MAP, YOUR_TOP_LEVEL_KEY), YOUR_NESTED_KEY)}'
end
fn_and(*) click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 23
def fn_and(*)
  warn "WARNING: Condition functions cannot be inferred when migrating to terraform. Please set count on migrated resources manually. #{self.class}(#{terraform_name})"
  '${todo.fn_and.ATTRIBUTE.set_in_count}'
end
fn_equals(*) click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 28
def fn_equals(*)
  warn "WARNING: Condition functions cannot be inferred when migrating to terraform. Please set count on migrated resources manually. #{self.class}(#{terraform_name})"
  '${todo.fn_equals.ATTRIBUTE.set_in_count}'
end
fn_if(*) click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 33
def fn_if(*)
  warn "WARNING: Condition functions cannot be inferred when migrating to terraform. Please set count on migrated resources manually. #{self.class}(#{terraform_name})"
  '${todo.fn_if.ATTRIBUTE.set_in_count}'
end
fn_import_value(*) click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 38
def fn_import_value(*)
  warn "WARNING: Fn::ImportValue cannot be inferred when migrated to terraform. Please pull in this input through a variable or local value in your configuration. #{self.class}(#{terraform_name})"
  '${todo.fn_import_value.ATTRIBUTE}'
end
fn_not(*) click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 43
def fn_not(*)
  warn "WARNING: Condition functions cannot be inferred when migrating to terraform. Please set count on migrated resources manually. #{self.class}(#{terraform_name})"
  '${todo.fn_not.ATTRIBUTE.set_in_count}'
end
fn_or(*) click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 48
def fn_or(*)
  warn "WARNING: Condition functions cannot be inferred when migrating to terraform. Please set count on migrated resources manually. #{self.class}(#{terraform_name})"
  '${todo.fn_or.ATTRIBUTE.set_in_count}'
end
fn_ref(resource_name) click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 86
def fn_ref(resource_name)
  interpolation_string = "${#{terraform_resource_type(resource_name)}.#{terraform_resource_name(resource_name)}.id}"
  warn "WARNING: Inferring you want to use #{interpolation_string} in place of Fn::Ref. Please consult with the interpolation syntax terraform docs and docs for this resource type in terraform to verify compatablity. #{self.class}(#{terraform_name})"
  interpolation_string
end
fn_sub(*) click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 53
def fn_sub(*)
  warn "WARNING: Fn::Sub cannot be inferred when migrating to terraform. Please use ${replace(str, search, replace)} instead. #{self.class}(#{terraform_name})"
  '${replace(todo.fn_sub.STRING, todo.fn_sub.SEARCH, todo.fn_sub.REPLACE)}'
end
get_att(resource_name, attr_name) click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 63
def get_att(resource_name, attr_name)
  interpolation_string = "${#{terraform_resource_type(resource_name)}.#{terraform_resource_name(resource_name)}.#{attr_name.underscore}}"
  warn "WARNING: Inferring you want to use #{interpolation_string} in place of Fn::GetAtt. Please consult with the interpolation syntax terraform docs and docs for this resource type in terraform to verify compatablity. #{self.class}(#{terraform_name})"
  interpolation_string
end
get_azs(*) click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 69
def get_azs(*)
  warn "WARNING: Inferring you want to use ${var.availability_zones} instead of Fn::GetAZs. Please consult with the interpolation syntax terraform docs to verify compatablity. Additionally you should attempt to use variables in place of a literal list. #{self.class}(#{terraform_name})"
  '${var.availability_zones}'
end
join(delimiter, *values) click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 74
def join(delimiter, *values)
  interpolation_string = "${join(\"#{delimiter}\", list(#{values.map { |o| "\"#{o}\"" }.join(', ')}))"
  warn "WARNING: Inferring you want to use #{interpolation_string} in place of Fn::Join. Please consult with the interpolation syntax terraform docs to verify compatablity. Additionally you should attempt to use variables in place of a literal list. #{self.class}(#{terraform_name})"
  interpolation_string
end
select(index, *objects) click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 80
def select(index, *objects)
  interpolation_string = "${element(list(#{objects.map { |o| "\"#{o}\"" }.join(', ')}), #{index})"
  warn "WARNING: Inferring you want to use #{interpolation_string} in place of Fn::Select. Please consult with the interpolation syntax terraform docs to verify compatablity. Additionally you should attempt to use variables in place of a literal list. #{self.class}(#{terraform_name})"
  interpolation_string
end
terraform_name() click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 92
def terraform_name
  return name if respond_to?(:name)
  return sid if respond_to?(:sid)

  object_id
end
terraform_resource_name(resource_name) click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 99
def terraform_resource_name(resource_name)
  resource_name.underscore
end
terraform_resource_type(resource_name) click to toggle source
# File lib/convection/dsl/terraform_intrinsic_functions.rb, line 103
def terraform_resource_type(resource_name)
  return type if respond_to?(:name) && respond_to?(:type) && resource_name == name
  return resources[resource_name].type.underscore.tr('/', '_') if respond_to?(:resources) && resources[resource_name]
  return all_resources[resource_name].type.underscore.tr('/', '_') if respond_to?(:all_resources) && all_resources[resource_name]
  return parent.resources[resource_name].type.underscore.tr('/', '_') if respond_to?(:parent) && parent.resources[resource_name]

  'todo_fixme_see_resource_type'
end