Class: Terraspace::Terraform::Api::Vars

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Http::Concern
Defined in:
lib/terraspace/terraform/api/vars.rb,
lib/terraspace/terraform/api/vars/rb.rb,
lib/terraspace/terraform/api/vars/base.rb,
lib/terraspace/terraform/api/vars/json.rb

Defined Under Namespace

Classes: Base, Json, Rb

Instance Method Summary collapse

Methods included from Http::Concern

#http

Constructor Details

#initialize(mod, workspace) ⇒ Vars

workspace: details from the api response



7
8
9
# File 'lib/terraspace/terraform/api/vars.rb', line 7

def initialize(mod, workspace)
  @mod, @workspace = mod, workspace
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/terraspace/terraform/api/vars.rb', line 30

def exist?
  !!vars_path
end

#runObject



11
12
13
14
15
16
17
18
# File 'lib/terraspace/terraform/api/vars.rb', line 11

def run
  return unless exist?

  vars = vars_class.new(@mod, vars_path).vars
  vars.each do |attrs|
    Var.new(@workspace, attrs).sync
  end
end

#vars_classObject

Return value examples:

Terraspace::Terraform::Api::Vars::Json
Terraspace::Terraform::Api::Vars::Rb


25
26
27
28
# File 'lib/terraspace/terraform/api/vars.rb', line 25

def vars_class
  ext = File.extname(vars_path).sub('.','')
  "Terraspace::Terraform::Api::Vars::#{ext.camelize}".constantize
end

#vars_pathObject



34
35
36
37
# File 'lib/terraspace/terraform/api/vars.rb', line 34

def vars_path
  # .rb takes higher precedence
  Dir.glob("#{Terraspace.root}/config/terraform/tfc/vars.{rb,json}").first
end