Class: Lono::Sets::Instances::Sync

Inherits:
Base show all
Includes:
Summarize, Utils::Sure
Defined in:
lib/lono/sets/instances/sync.rb

Instance Method Summary collapse

Methods included from Utils::Sure

#sure?

Methods included from Summarize

#summarize

Methods inherited from Base

#requested, #stack_instances

Methods inherited from Base

#build_options, #exit_unless_updatable!, #operation_preferences

Methods inherited from Cfn::Base

#capabilities, #check_registration, #command_with_iam, #continue_update_rollback, #continue_update_rollback_sure?, #delete_rollback_stack, #exit_unless_updatable!, #generate_all, #pretty_path, #prompt_for_iam, #quit, #rerun_with_iam?, #set_template_url!, #show_options, #stack_status, #starting_message, #status, #tags

Methods included from AwsServices

#cfn, #ec2, #iam, #s3, #s3_presigner, #s3_resource, #sts

Methods included from AwsServices::Helper

#rollback_complete?, #testing_update?

Methods included from AwsServices::StackSet

#find_stack_set, #stack_set_exists?

Methods included from AwsServices::Stack

#find_stack, #stack_exists?

Methods inherited from AbstractBase

#reinitialize, #template_path

Methods included from Blueprint::Root

#find_blueprint_root, #set_blueprint_root

Constructor Details

#initialize(options = {}) ⇒ Sync

Returns a new instance of Sync.



6
7
8
9
# File 'lib/lono/sets/instances/sync.rb', line 6

def initialize(options={})
  super # need conventions so config lookup will work
  @regions, @accounts = [], []
end

Instance Method Details

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/lono/sets/instances/sync.rb', line 11

def run
  unless stack_set_exists?(@stack)
    puts "ERROR: Cannot update a stack set because #{@stack} does not exists.".color(:red)
    return
  end
  exit_unless_updatable!

  validate!

  existing = stack_instances.map do |summary|
    [summary., summary.region]
  end

  creates = requested - existing
  deletes = existing - requested

  if creates.empty? and deletes.empty?
    puts <<~EOL
      Nothing to be synced. IE: No stack instances need to be added or removed.  If you want to update the
      stack set and update all stack instances instead, use the `lono sets deploy` command.
    EOL
    return
  end
  sure?("Are you sure you want to sync stack instances?", long_desc(creates: creates, deletes: deletes))

  # Note: Not calling update_stack_instances because after deleting stacks it instances in in a weird state
  # where an update_stack_instances fails. Can reproduce this by deleting stacks and then trying an update_stack_instances
  # with the AWS CLI. In theory, we never really should have to call update_stack_instances anyway because
  # updating the stack set at the parent level kicks off an update_stack_instances automatically.
  operation_id = execute(:create_stack_instances, creates)
  summarize(operation_id) if operation_id
  if @options[:delete]
    operation_id = execute(:delete_stack_instances, deletes)
    summarize(operation_id) if operation_id
  end
end