Class: Lono::SetInstances::Changeable

Inherits:
Base show all
Includes:
AwsServices, Utils::Sure
Defined in:
lib/lono/set_instances/changeable.rb

Direct Known Subclasses

Create, Delete, Deploy, Update

Instance Method Summary collapse

Methods included from Utils::Sure

#sure?

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 Base

#requested, #stack_instances

Methods inherited from Lono::Sets::Base

#build_options, #exit_unless_updatable!, #operation_preferences

Methods inherited from Cfn::Base

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

Methods inherited from AbstractBase

#reinitialize, #template_path

Methods included from Blueprint::Root

#find_blueprint_root, #set_blueprint_root

Constructor Details

#initialize(options = {}) ⇒ Changeable

Returns a new instance of Changeable.



6
7
8
9
# File 'lib/lono/set_instances/changeable.rb', line 6

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

Instance Method Details

#accountsObject



45
46
47
# File 'lib/lono/set_instances/changeable.rb', line 45

def accounts
  @options[:all] ? stack_instances.map(&:account).uniq : @options[:accounts]
end

#regionsObject



49
50
51
# File 'lib/lono/set_instances/changeable.rb', line 49

def regions
  @options[:all] ? stack_instances.map(&:region).uniq : @options[:regions]
end

#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
# File 'lib/lono/set_instances/changeable.rb', line 11

def run
  validate!

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

  options = {
    stack_set_name: @stack,
    accounts: accounts,
    regions: regions,
  }
  begin
    resp = perform(options)
  rescue Aws::CloudFormation::Errors::ValidationError => e
    # IE: Aws::CloudFormation::Errors::ValidationError: Region eu-north-1 is not supported
    puts "#{e.class}: #{e.message}".color(:red)
    exit 1
  end

  return true if @options[:noop]
  Lono::Sets::Waiter.new(@options).run(resp[:operation_id])
end

#validate!Object



37
38
39
40
41
42
43
# File 'lib/lono/set_instances/changeable.rb', line 37

def validate!
  invalid = (regions.blank? || accounts.blank?) && !@options[:all]
  if invalid
    puts "ERROR: You must provide --accounts and --regions or --all.".color(:red)
    exit 1
  end
end