Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Allow override region from Vagrantfile #484

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/vagrant-aws/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ def finalize!
if @access_key_id == UNSET_VALUE or @secret_access_key == UNSET_VALUE
@aws_profile = 'default' if @aws_profile == UNSET_VALUE
@aws_dir = ENV['HOME'].to_s + '/.aws/' if @aws_dir == UNSET_VALUE
@region, @access_key_id, @secret_access_key, @session_token = Credentials.new.get_aws_info(@aws_profile, @aws_dir)
@region = UNSET_VALUE if @region.nil?
@aws_region, @access_key_id, @secret_access_key, @session_token = Credentials.new.get_aws_info(@aws_profile, @aws_dir)
@region = @aws_region if @region == UNSET_VALUE and !@aws_region.nil?
else
@aws_profile = nil
@aws_dir = nil
Expand Down
17 changes: 17 additions & 0 deletions spec/vagrant-aws/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,23 @@
its("access_key_id") { should == "AKIdefault" }
its("secret_access_key") { should == "PASSdefault" }
its("session_token") { should be_nil }
its("region") { should == "eu-west-1" }
end

context "with default profile and overriding region" do
subject do
allow(File).to receive(:exist?).and_return(true)
allow(File).to receive(:read).with(filename_cfg).and_return(data_cfg)
allow(File).to receive(:read).with(filename_keys).and_return(data_keys)
instance.region = "eu-central-1"
instance.tap do |o|
o.finalize!
end
end
its("access_key_id") { should == "AKIdefault" }
its("secret_access_key") { should == "PASSdefault" }
its("session_token") { should be_nil }
its("region") { should == "eu-central-1" }
end

context "without any credential environment variables and chosing a profile" do
Expand Down