Class: Terraspace::CLI::Init
Instance Method Summary collapse
- #auto? ⇒ Boolean
-
#build_remote_dependencies ⇒ Object
Currently only handles remote modules only one-level deep.
- #build_remote_mod(meta) ⇒ Object
-
#init ⇒ Object
Note the init will always create the Terraform Cloud Workspace.
-
#initialize(options = {}) ⇒ Init
constructor
A new instance of Init.
- #run ⇒ Object
- #sync_cloud ⇒ Object
Methods included from Util
Methods included from Util::Sure
Methods included from Util::Sh
Methods included from Util::Logging
Constructor Details
#initialize(options = {}) ⇒ Init
Returns a new instance of Init.
5 6 7 8 9 10 |
# File 'lib/terraspace/cli/init.rb', line 5 def initialize(={}) # Original calling command. Can be from Commander which is a terraform command. IE: terraform apply # Or can be from terraspace cloud setup. Which will be cloud-setup. @calling_command = [:calling_command] super() end |
Instance Method Details
#auto? ⇒ Boolean
54 55 56 57 |
# File 'lib/terraspace/cli/init.rb', line 54 def auto? # command is only passed from CLI in the update specifically for this check @options[:auto] && @calling_command == "apply" end |
#build_remote_dependencies ⇒ Object
Currently only handles remote modules only one-level deep.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/terraspace/cli/init.rb', line 35 def build_remote_dependencies modules_json_path = "#{@mod.cache_dir}/.terraform/modules/modules.json" return unless File.exist?(modules_json_path) initialized_modules = JSON.load(IO.read(modules_json_path)) # For example of structure see spec/fixtures/initialized/modules.json initialized_modules["Modules"].each do || build_remote_mod() end end |
#build_remote_mod(meta) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/terraspace/cli/init.rb', line 46 def build_remote_mod() return if local_source?(["Source"]) return if ['Dir'] == '.' # root is already built remote_mod = Mod::Remote.new(, @mod) Compiler::Builder.new(remote_mod).build end |
#init ⇒ Object
Note the init will always create the Terraform Cloud Workspace
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/terraspace/cli/init.rb', line 19 def init # default init timeout is pretty generous in case of slow internet to download the provider plugins init_timeout = Integer(ENV['TS_INIT_TIMEOUT'] || 600) Timeout::timeout(init_timeout) do Terraspace::Terraform::Runner.new("init", @options).run if !auto? && @options[:init] != false # will run on @options[:init].nil? end rescue Timeout::Error logger.error "ERROR: It took too long to run terraform init. Here is the output logs of terraform init:".color(:red) logger.error IO.read(Terraspace::Terraform::Args::Default.terraform_init_log) end |
#run ⇒ Object
12 13 14 15 16 |
# File 'lib/terraspace/cli/init.rb', line 12 def run init if init? build_remote_dependencies # runs after terraform init, which downloads remote modules sync_cloud end |
#sync_cloud ⇒ Object
30 31 32 |
# File 'lib/terraspace/cli/init.rb', line 30 def sync_cloud Terraspace::Terraform::Cloud.new(@options).run if %w[apply plan destroy cloud-setup].include?(@calling_command) end |