Class: Proteus::Modules::TerraformModule
Constant Summary
collapse
- @@hooks =
{}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
config_dir, config_path, context_path, context_temp_directory, contexts_path, environments_path, module_config_path, module_data_path, module_hooks_path, module_io_file, module_path, module_templates_path, modules_path, plan_file, root_path, state_file, var_file
#_, #camel_case
Constructor Details
#initialize(name:, context:, environment:, terraform_variables:) ⇒ TerraformModule
Returns a new instance of TerraformModule.
20
21
22
23
24
25
26
|
# File 'lib/proteus/modules/terraform_module.rb', line 20
def initialize(name:, context:, environment:, terraform_variables:)
@name = name
@context = context
@environment = environment
@terraform_variables = terraform_variables
@hook_variables = {}
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
18
19
20
|
# File 'lib/proteus/modules/terraform_module.rb', line 18
def name
@name
end
|
Class Method Details
.register_hook(module_name, hook) ⇒ Object
41
42
43
44
|
# File 'lib/proteus/modules/terraform_module.rb', line 41
def self.register_hook(module_name, hook)
@@hooks[module_name] ||= Array.new
@@hooks[module_name] << hook
end
|
Instance Method Details
#clean ⇒ Object
37
38
39
|
# File 'lib/proteus/modules/terraform_module.rb', line 37
def clean
File.file?(manifest) ? FileUtils.rm(manifest) : nil
end
|
#process ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/proteus/modules/terraform_module.rb', line 28
def process
clean
run_hooks
load_data
return if !data?
validate
render
end
|
#run_hooks ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/proteus/modules/terraform_module.rb', line 46
def run_hooks
Dir.glob(File.join(module_hooks_path(@context, @name), '*')).each do |file|
require file
end
hooks_module = "Proteus::Modules::#{camel_case(@name)}::Hooks"
if Kernel.const_defined?(hooks_module)
say "Hooks present for module #{@name}", :green
Kernel.const_get(hooks_module).constants.each do |constant|
say "Found hook: #{constant}", :green
self.class.include(Kernel.const_get("#{hooks_module}::#{constant}"))
end
end
if @@hooks.key?(@name)
@@hooks[@name].each do |hook|
hook_result = hook.call(@environment, @context, @name)
if hook_result.is_a?(Hash)
@hook_variables.merge!(hook_result)
end
@@hooks[@name].delete(hook)
end
end
end
|