Module: Terraspace::Plugin

Extended by:
Memoist, Plugin
Included in:
Plugin
Defined in:
lib/terraspace/plugin.rb,
lib/terraspace/plugin/meta.rb,
lib/terraspace/plugin/finder.rb,
lib/terraspace/plugin/infer_provider.rb

Defined Under Namespace

Modules: Backend, Config, Decorator, Expander, Helper, InferProvider, Layer, Summary Classes: Finder, Meta

Constant Summary collapse

@@meta =

The plugin metadata

Example meta:

{
  "aws"    => {root: "/path", backend: "s3"}
  "google" => {root: "/path", backend: "gcs"},
}
{}

Instance Method Summary collapse

Instance Method Details

#autodetectObject

Returns simple String: aws



76
77
78
79
80
81
82
# File 'lib/terraspace/plugin.rb', line 76

def autodetect
  plugins = meta.keys
  precedence = %w[aws azurerm google]
  precedence.find do |p|
    plugins.include?(p)
  end
end

#config_classesObject



23
24
25
# File 'lib/terraspace/plugin.rb', line 23

def config_classes
  @@meta.map { |plugin, data| data[:config_class] }.compact
end

#find_with(options = {}) ⇒ Object



70
71
72
# File 'lib/terraspace/plugin.rb', line 70

def find_with(options={})
  Finder.new.find_with(options)
end

#helper_classesObject



27
28
29
# File 'lib/terraspace/plugin.rb', line 27

def helper_classes
  @@meta.map { |plugin, data| data[:helper_class] }.compact
end

#klass(interface_class, options = {}) ⇒ Object

Example return:

TerraspacePluginAws::Interfaces::Backend
TerraspacePluginAws::Interfaces::Expander
TerraspacePluginGcp::Interfaces::Backend
TerraspacePluginGcp::Interfaces::Expander


64
65
66
67
68
# File 'lib/terraspace/plugin.rb', line 64

def klass(interface_class, options={})
  meta = find_with(options)
  return unless meta
  "TerraspacePlugin#{meta.plugin}::Interfaces::#{interface_class}"
end

#layer_classesObject



31
32
33
# File 'lib/terraspace/plugin.rb', line 31

def layer_classes
  @@meta.map { |plugin, data| data[:layer_class] }.compact
end

#metaObject



15
16
17
# File 'lib/terraspace/plugin.rb', line 15

def meta
  @@meta
end

#register(plugin, data) ⇒ Object



19
20
21
# File 'lib/terraspace/plugin.rb', line 19

def register(plugin, data)
  @@meta[plugin] = data
end

#resource_mapObject

The resource map can be used to customized the mapping from the resource “first word” to the plugin.

resource map is in meta structure.

{
  "long_cloud_plugin_name" => {resource_map: {"long_cloud_plugin_name" => "short_name"}
}

This is use by Plugin::Finder#find_with_resource Allows mapping of different values in case the terraspace plugin name doesnt match with the resource first word.

Generally we try to avoid this and the terraspace plugin name should match the resource “first word” when possible.



50
51
52
53
54
55
# File 'lib/terraspace/plugin.rb', line 50

def resource_map
  @@meta.inject({}) do |result, (plugin, data)|
    map = data[:resource_map] || {}
    result.merge(map.deep_stringify_keys)
  end
end