class Lono::SetInstances::Changeable

Public Class Methods

new(options={}) click to toggle source
Calls superclass method Lono::Sets::Base::new
# File lib/lono/set_instances/changeable.rb, line 6
def initialize(options={})
  super # need conventions so config lookup will work
  @regions, @accounts = [], []
end

Public Instance Methods

accounts() click to toggle source
# File lib/lono/set_instances/changeable.rb, line 45
def accounts
  @options[:all] ? stack_instances.map(&:account).uniq : @options[:accounts]
end
regions() click to toggle source
# File lib/lono/set_instances/changeable.rb, line 49
def regions
  @options[:all] ? stack_instances.map(&:region).uniq : @options[:regions]
end
run() click to toggle source
# 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!() click to toggle source
# 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