Class: Lono::SetInstances::Deploy

Inherits:
Changeable show all
Defined in:
lib/lono/set_instances/deploy.rb

Instance Method Summary collapse

Methods inherited from Changeable

#accounts, #initialize, #regions, #validate!

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

#accounts, #regions, #requested, #stack_instances

Methods inherited from Lono::Sets::Base

#build_options, #exit_unless_updatable!, #initialize, #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

#initialize, #reinitialize, #template_path

Methods included from Blueprint::Root

#find_blueprint_root, #set_blueprint_root

Constructor Details

This class inherits a constructor from Lono::SetInstances::Changeable

Instance Method Details

#deploy(type, changes) ⇒ Object



20
21
22
23
24
# File 'lib/lono/set_instances/deploy.rb', line 20

def deploy(type, changes)
  changes.each do |, regions|
    run_action(type, , regions)
  end
end

#lono_command(klass) ⇒ Object



38
39
40
41
# File 'lib/lono/set_instances/deploy.rb', line 38

def lono_command(klass)
  klass = klass.to_s
  klass.split('::').map(&:underscore).join(' ')
end

#runObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/lono/set_instances/deploy.rb', line 3

def run
  # computes whether create or update should be ran for stack instances within each account
  updates, creates = Hash.new([]), Hash.new([])
  accounts.each do ||
    regions.each do |region|
      if stack_instance_exists?(, region)
        updates[] += [region] # += [item] works, << item doesnt seem to work
      else
        creates[] += [region] # += [item] works, << item doesnt seem to work
      end
    end
  end

  deploy(:create, creates)
  deploy(:update, updates)
end

#run_action(type, account, regions) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lono/set_instances/deploy.rb', line 26

def run_action(type, , regions)
  klass = "Lono::SetInstances::#{type.to_s.camelize}"
  klass = klass.constantize
  command = lono_command(klass)
  puts "Running #{command.color(:green)} on account: #{} regions: #{regions.join(',')}"

  options = @options.dup
  options[:accounts] = []
  options[:regions] = regions
  klass.new(options).run
end

#stack_instance_exists?(account, region) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
# File 'lib/lono/set_instances/deploy.rb', line 43

def stack_instance_exists?(, region)
  existing = stack_instances.map do |summary|
    [summary., summary.region]
  end
  intersect = existing & [[, region]]
  !intersect.empty?
end