Class: SimplyGenius::Atmos::Commands::Terraform
- Inherits:
-
BaseCommand
- Object
- Clamp::Command
- BaseCommand
- SimplyGenius::Atmos::Commands::Terraform
show all
- Includes:
- FileUtils
- Defined in:
- lib/simplygenius/atmos/commands/terraform.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from UI
#agree, #ask, #choose, color_enabled, color_enabled=, #display, #error, #notify, #say, #warn
Instance Attribute Details
#auto_init ⇒ Object
Returns the value of attribute auto_init.
11
12
13
|
# File 'lib/simplygenius/atmos/commands/terraform.rb', line 11
def auto_init
@auto_init
end
|
Class Method Details
.description ⇒ Object
13
14
15
|
# File 'lib/simplygenius/atmos/commands/terraform.rb', line 13
def self.description
"Runs terraform"
end
|
Instance Method Details
#enable_shared_plugins(env) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/simplygenius/atmos/commands/terraform.rb', line 34
def enable_shared_plugins(env)
if ! Atmos.config["atmos.terraform.disable_shared_plugins"]
home_dir = OS.windows? ? File.join("~", "Application Data") : "~"
plugin_cache_dir = File.expand_path(File.join(home_dir,".terraform.d", "plugin-cache"))
logger.debug("Plugin cache dir: #{plugin_cache_dir}")
mkdir_p(plugin_cache_dir)
env["TF_PLUGIN_CACHE_DIR"] = plugin_cache_dir
end
end
|
#execute ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/simplygenius/atmos/commands/terraform.rb', line 44
def execute
unless Atmos.config.is_atmos_repo?
signal_usage_error <<~EOF
Atmos can only run terraform from a location configured for atmos.
Have you run atmos init?"
EOF
end
Atmos.config.provider.auth_manager.authenticate(ENV) do |auth_env|
begin
get_modules = @terraform_arguments.delete("--get-modules")
enable_shared_plugins(auth_env)
init_automatically(auth_env, get_modules)
exe = TerraformExecutor.new(process_env: auth_env)
exe.run(*@terraform_arguments, get_modules: get_modules.present?)
rescue TerraformExecutor::ProcessFailed => e
logger.error(e.message)
exit(1)
end
end
end
|
#init_automatically(auth_env, get_modules) ⇒ Object
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/simplygenius/atmos/commands/terraform.rb', line 23
def init_automatically(auth_env, get_modules)
tf_init_dir = File.join(Atmos.config.tf_working_dir, 'recipes', '.terraform')
backend_initialized = File.exist?(File.join(tf_init_dir, 'terraform.tfstate'))
auto_init_enabled = Atmos.config["atmos.terraform.auto_init"].to_s == "true"
if auto_init && auto_init_enabled && ! backend_initialized
exe = TerraformExecutor.new(process_env: auth_env)
exe.run("init", get_modules: get_modules.present?)
end
end
|
#parse(arguments) ⇒ Object
override so we can pass all options/flags/parameters directly to terraform instead of having clamp parse them
19
20
21
|
# File 'lib/simplygenius/atmos/commands/terraform.rb', line 19
def parse(arguments)
@terraform_arguments = arguments
end
|