Class: TerraformDSL::Module

Inherits:
Object
  • Object
show all
Defined in:
lib/scout/terraform_dsl.rb

Overview

Module objects hold the identity of a module and its :name, and can be used to create references to its outputs to pass as inputs for another module

Defined Under Namespace

Classes: Output

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, deployment) ⇒ Module

Create a new Module

Parameters:

  • name (String)

    instance name

  • type (String)

    module template name



53
54
55
56
57
# File 'lib/scout/terraform_dsl.rb', line 53

def initialize(name, type, deployment)
  @name = name
  @type = type
  @deployment = deployment
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(output) ⇒ Output

Construct output variable references to use on templates. They will be serialized when used in templates

Parameters:

  • output (String)

    the name of the output

Returns:

  • (Output)

    An output variable for Terraform templates



64
65
66
# File 'lib/scout/terraform_dsl.rb', line 64

def method_missing(output)
  Output.new(@name, output)
end

Instance Attribute Details

#deploymentObject

Returns the value of attribute deployment.



18
19
20
# File 'lib/scout/terraform_dsl.rb', line 18

def deployment
  @deployment
end

#nameObject

Returns the value of attribute name.



18
19
20
# File 'lib/scout/terraform_dsl.rb', line 18

def name
  @name
end

#typeObject

Returns the value of attribute type.



18
19
20
# File 'lib/scout/terraform_dsl.rb', line 18

def type
  @type
end

Instance Method Details

#respond_to_missing?(_method_name, _include_private = false) ⇒ Boolean

Any missing method call can be the name of an output

Returns:

  • (Boolean)


69
70
71
# File 'lib/scout/terraform_dsl.rb', line 69

def respond_to_missing?(_method_name, _include_private = false)
  true
end

#to_json(*_args) ⇒ String

Callback to produce the json content when we serialize variable values. It becomes a reference to a Module itself, and can be used in depends_on statements

Parameters:

  • args (Array)

    Extra arguments to to_json, not used

Returns:

  • (String)

    A reference to a module in Terraform format (e.g. module.<modulename>)



80
81
82
# File 'lib/scout/terraform_dsl.rb', line 80

def to_json(*_args)
  ['module', @name].join('.')
end