Class: Terraspace::Compiler::Dsl::Tfvars
- Includes:
- Syntax::Tfvar
- Defined in:
- lib/terraspace/compiler/dsl/tfvars.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #add_instance_vars!(new_instance_vars) ⇒ Object
-
#build ⇒ Object
Can return nil if there’s no tfvars declared.
- #evaluate(path) ⇒ Object
Methods included from Terraspace::Compiler::Dependencies::Helpers
#depends_on, #each_depends_on, #output
Methods inherited from Base
Constructor Details
This class inherits a constructor from Terraspace::Compiler::Dsl::Base
Instance Method Details
#add_instance_vars!(new_instance_vars) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/terraspace/compiler/dsl/tfvars.rb', line 19 def add_instance_vars!(new_instance_vars) # IE: new_instance_variables = [:@cidr_block, :@name] @structure.deep_stringify_keys! new_instance_vars.each do |var| key = var.to_s.sub('@','') # better to keep String as tfvar will usually use String notation, also deep_stringify_keys! earlier just in case value = instance_variable_get(var) @structure.merge!(key => value) end end |
#build ⇒ Object
Can return nil if there’s no tfvars declared
6 7 8 9 10 |
# File 'lib/terraspace/compiler/dsl/tfvars.rb', line 6 def build evaluate(@src_path) result = @structure.deep_stringify_keys JSON.pretty_generate(result) unless result.empty? end |
#evaluate(path) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/terraspace/compiler/dsl/tfvars.rb', line 12 def evaluate(path) current_instance_vars = instance_variables evaluate_file(path) # tfvar calls creates variables in @structure new_instance_vars = instance_variables - current_instance_vars add_instance_vars!(new_instance_vars) end |