Class: Terraspace::Cloud::Update

Inherits:
Base show all
Defined in:
lib/terraspace/cloud/update.rb

Instance Method Summary collapse

Methods inherited from Base

#cancelled?, #changes?, #clean_cache2_stage, #cloud_upload, #initialize, #record?, #sh, #stage_attrs, #success_status

Methods included from Util::Pretty

#pretty_path, #pretty_time

Methods included from Util::Sure

#sure?

Methods included from Util::Logging

#logger

Methods included from Context

#setup_context

Methods included from Api::Validate

#validate

Methods included from Api::Concern

#api, #cloud_stack_name, #expander, #region

Methods included from Api::Concern::Errors

#error_message, #errors?

Methods inherited from Terraspace::CLI::Base

#initialize

Constructor Details

This class inherits a constructor from Terraspace::Cloud::Base

Instance Method Details

#build(success) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/terraspace/cloud/update.rb', line 17

def build(success)
  clean_cache2_stage
  # .terraspace-cache/dev/stacks/demo
  Dir.chdir(@mod.cache_dir) do
    cache2_path = ".terraspace-cache/.cache2/update"
    FileUtils.mkdir_p(cache2_path)

    IO.write("#{cache2_path}/update.log", Terraspace::Logger.logs)
    return unless success

    sh "#{Terraspace.terraform_bin} state pull > #{cache2_path}/state.json"
    sh "#{Terraspace.terraform_bin} output -json > #{cache2_path}/output.json"
  end
end

#cani?(exit_on_error: true) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/terraspace/cloud/update.rb', line 32

def cani?(exit_on_error: true)
  return true unless Terraspace.cloud?
  api.create_update(cani: 1, exit_on_error: exit_on_error)
end

#create(success, stream) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/terraspace/cloud/update.rb', line 3

def create(success, stream)
  return unless Terraspace.cloud?
  return unless record?

  build(success)
  upload = cloud_upload.create(type: "update", stream_id: stream['data']['id'])
  params = {
    upload_id: upload['data']['id'],
    stack_uid: upload['data']['attributes']['stack_id'], # use stack_uid since stack_id is friendly url name
    update: stage_attrs(success),
  }
  api.create_update(params)
end