Class: Cloudshaper::Resource

Inherits:
StackElement show all
Defined in:
lib/cloudshaper/resource.rb

Overview

Defines a terraform resource

Instance Attribute Summary collapse

Attributes inherited from StackElement

#fields

Instance Method Summary collapse

Methods included from Aws

#post_processing_aws, taggable?

Constructor Details

#initialize(parent_module, resource_name, resource_type, &block) ⇒ Resource

Returns a new instance of Resource.



8
9
10
11
12
13
14
15
16
# File 'lib/cloudshaper/resource.rb', line 8

def initialize(parent_module, resource_name, resource_type, &block)
  @resource_name = resource_name
  @resource_type = resource_type
  super(parent_module, &block)

  # Allow provider specific post processing
  sym = "post_processing_#{resource_type.split('_').first}"
  send(sym) if self.respond_to?(sym, include_private: true)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Cloudshaper::StackElement

Instance Attribute Details

#resource_nameObject (readonly)

Returns the value of attribute resource_name.



6
7
8
# File 'lib/cloudshaper/resource.rb', line 6

def resource_name
  @resource_name
end

Instance Method Details

#provisioner(provisioner_type, &block) ⇒ Object

Allow provisioner blocks to be nested within resources



19
20
21
22
23
24
25
26
# File 'lib/cloudshaper/resource.rb', line 19

def provisioner(provisioner_type, &block)
  provisioner_type = provisioner_type.to_sym

  @fields[:provisioner] = @fields[:provisioner] || []

  provisioner_set = Provisioner.new(@module, &block)
  @fields[:provisioner] << { cleanup_provisioner_type(provisioner_type) => provisioner_set.fields }
end