Skip to content

Commit

Permalink
Merge pull request mitchellh#1 from sharabash/mkubenka
Browse files Browse the repository at this point in the history
Recall and use region instance was launched in
  • Loading branch information
mkubenka authored Oct 2, 2017
2 parents 768a45b + a12ccea commit 00ca219
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/vagrant-aws/action/connect_aws.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(app, env)

def call(env)
# Get the region we're going to booting up in
region = env[:machine].provider_config.region
region = env[:machine].provider.region

# Get the configs
region_config = env[:machine].provider_config.get_region_config(region)
Expand Down
5 changes: 5 additions & 0 deletions lib/vagrant-aws/action/run_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ def call(env)
# Immediately save the ID since it is created at this point.
env[:machine].id = server.id

# Immediately save the region in which the instance was launched.
env[:machine].data_dir.join("region").open("w+") do |f|
f.write(region)
end

# Wait for the instance to be ready first
env[:metrics]["instance_ready_time"] = Util::Timer.time do
tries = region_config.instance_ready_timeout / 2
Expand Down
12 changes: 12 additions & 0 deletions lib/vagrant-aws/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ def state
Vagrant::MachineState.new(state_id, short, long)
end

def region
# Return the region associated with the instance if the machine
# has already been launched, or return the default region configured.
machine_region_file = @machine.data_dir.join("region")

if File.exists?(machine_region_file)
return File.read(machine_region_file)
else
return @machine.provider_config.region
end
end

def to_s
id = @machine.id.nil? ? "new" : @machine.id
"AWS (#{id})"
Expand Down

0 comments on commit 00ca219

Please sign in to comment.