Skip to content

Commit

Permalink
Fix ssh command when using multiple ASGs (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
janost authored and askreet committed Feb 21, 2017
1 parent 5b4cfc6 commit c792089
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/moonshot/ssh_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def parser
Moonshot.config.ssh_config.ssh_identity_file = v
end

parser.on('-s', '--instance INSTANCE_ID', 'Specific AWS EC2 ID to connect through') do |v|
parser.on('-s', '--instance INSTANCE_ID', 'Specific AWS EC2 ID to connect to') do |v|
Moonshot.config.ssh_instance = v
end

Expand Down
8 changes: 4 additions & 4 deletions lib/moonshot/ssh_target_selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ def choose!

asg = if groups.count == 1
groups.first
elsif asgs.count > 1
elsif groups.count > 1
unless @asg_name
raise 'Multiple Auto Scaling Groups found in the stack. Please specify which '\
'one to SSH into using the --auto-scaling-group (-g) option.'
end
groups.detect { |x| x.logical_resource_id == @config.ssh_auto_scaling_group_name }
groups.detect { |x| x.logical_resource_id == @asg_name }
end
raise 'Failed to find the Auto Scaling Group.' unless asg

Aws::AutoScaling::Client.new.describe_auto_scaling_groups(
auto_scaling_group_names: [asg.physical_resource_id]
).auto_scaling_groups.first.instances.map(&:instance_id).first
rescue
raise 'Failed to find instances in the Auto Scaling Group!'
rescue => e
raise "Failed to select an instance from the Auto Scaling Group: #{e.message}"
end
end
end

0 comments on commit c792089

Please sign in to comment.