Module: Terraspace::Core

Extended by:
Memoist
Included in:
Terraspace
Defined in:
lib/terraspace/core.rb

Constant Summary collapse

@@root =
nil
@@logger =
nil
@@cloud_warning_shown =
false
@@buffer =
[]

Instance Method Summary collapse

Instance Method Details

#appObject



10
11
12
# File 'lib/terraspace/core.rb', line 10

def app
  ENV['TS_APP'] unless ENV['TS_APP'].blank?
end

#bufferObject



102
103
104
# File 'lib/terraspace/core.rb', line 102

def buffer
  @@buffer
end

#cache_rootObject



41
42
43
# File 'lib/terraspace/core.rb', line 41

def cache_root
  ENV['TS_CACHE_ROOT'] || "#{root}/.terraspace-cache"
end

#cloud?Boolean

Returns:

  • (Boolean)


89
90
91
92
93
94
95
96
97
98
99
# File 'lib/terraspace/core.rb', line 89

def cloud?
  enabled = !!Terraspace.config.cloud.org
  if ENV['TS_TOKEN'] && !enabled && !@@cloud_warning_shown
    logger.warn <<~EOL.color(:yellow)
      WARN: TS_TOKEN is set but config.cloud.org is not set.
      See: http://terraspace.cloud/docs/cloud/setup/
    EOL
    @@cloud_warning_shown = true
  end
  enabled
end

#command?(name) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/terraspace/core.rb', line 106

def command?(name)
  ARGV[0] == name || ARGV[1] == name
end

#configObject

Generally, use the Terraspace.config instead of App.instance.config since it guarantees the load_project_config call



60
61
62
63
# File 'lib/terraspace/core.rb', line 60

def config
  App.instance.load_project_config
  App.instance.config
end

#configure(&block) ⇒ Object



55
56
57
# File 'lib/terraspace/core.rb', line 55

def configure(&block)
  App.instance.configure(&block)
end

#envObject



18
19
20
# File 'lib/terraspace/core.rb', line 18

def env
  ENV['TS_ENV'].blank? ? "dev" : ENV['TS_ENV']
end

#extraObject



22
23
24
# File 'lib/terraspace/core.rb', line 22

def extra
  ENV['TS_EXTRA'] unless ENV['TS_EXTRA'].blank?
end

#log_rootObject



51
52
53
# File 'lib/terraspace/core.rb', line 51

def log_root
  "#{root}/log"
end

#loggerObject



67
68
69
# File 'lib/terraspace/core.rb', line 67

def logger
  @@logger ||= config.logger
end

#logger=(v) ⇒ Object

allow different logger when running up all



72
73
74
# File 'lib/terraspace/core.rb', line 72

def logger=(v)
  @@logger = v
end

#pass_file?(path) ⇒ Boolean

Returns:

  • (Boolean)


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

def pass_file?(path)
  pass_files = config.build.pass_files + config.build.default_pass_files
  pass_files.uniq.detect do |i|
    i.is_a?(Regexp) ? path =~ i : path.include?(i)
  end
end

#projectObject



26
27
28
29
30
31
32
# File 'lib/terraspace/core.rb', line 26

def project
  if ENV['TS_PROJECT'].blank?
    "main"
  else
    ENV['TS_PROJECT']
  end
end

#roleObject



14
15
16
# File 'lib/terraspace/core.rb', line 14

def role
  ENV['TS_ROLE'] unless ENV['TS_ROLE'].blank?
end

#rootObject



35
36
37
# File 'lib/terraspace/core.rb', line 35

def root
  @@root ||= ENV['TS_ROOT'] || Dir.pwd
end

#terraform_binObject



5
6
7
8
# File 'lib/terraspace/core.rb', line 5

def terraform_bin
  # basename so command shows up as a prettier short name in the output
  File.basename(Terraspace::Check.new.terraform_bin)
end

#tmp_rootObject



46
47
48
# File 'lib/terraspace/core.rb', line 46

def tmp_root
  ENV['TS_TMP_ROOT'] || "/tmp/terraspace"
end