mitchellh/vagrant-aws

AWS_PROFILE ignored?

darkn3rd opened this issue · 3 comments

DESCRIPTION

Default profile set with either AWS_PROFILE or AWS_DEFAULT_PROFILE seems ignored and instead plugin parses INI file manually. AWS SDK has built in mechanism to parse INI given the environment variable.

Credentials ($HOME/.aws/credentials)

[dev]
aws_access_key_id = REDACTED
aws_secret_access_key = REDACTED
[prod]
aws_access_key_id = REDACTED
aws_secret_access_key = REDACTED
[ninjapants]
aws_access_key_id = REDACTED
aws_secret_access_key = REDACTED

Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "dummy"

  config.vm.provider :aws do |aws, override|
    aws.keypair_name = "vagrant"
    aws.ami = "ami-0cd3dfa4e37921605"
    override.ssh.private_key_path = "#{ENV['HOME']}/.ssh/vagrant_aws.pem"
  end
end

Steps

export AWS_DEFAULT_PROFILE=ninjapants
export AWS_PROFILE=ninjapants
vagrant up

EXPECTED RESULTS

  1. Default profile used.
  2. Should profile not found, friendly message that is the case

ACTUAL RESULTS

/Users/mejoaqui/.vagrant.d/gems/2.4.4/gems/vagrant-aws-0.7.2/lib/vagrant-aws/config.rb:544:in `read_aws_files': undefined method `[]' for nil:NilClass (NoMethodError)
	from /Users/mejoaqui/.vagrant.d/gems/2.4.4/gems/vagrant-aws-0.7.2/lib/vagrant-aws/config.rb:513:in `get_aws_info'
	from /Users/mejoaqui/.vagrant.d/gems/2.4.4/gems/vagrant-aws-0.7.2/lib/vagrant-aws/config.rb:326:in `finalize!'
	from /opt/vagrant/embedded/gems/2.2.4/gems/vagrant-2.2.4/plugins/kernel_v2/config/vm.rb:509:in `block in finalize!'
	from /opt/vagrant/embedded/gems/2.2.4/gems/vagrant-2.2.4/plugins/kernel_v2/config/vm.rb:474:in `each'
	from /opt/vagrant/embedded/gems/2.2.4/gems/vagrant-2.2.4/plugins/kernel_v2/config/vm.rb:474:in `finalize!'
	from /opt/vagrant/embedded/gems/2.2.4/gems/vagrant-2.2.4/lib/vagrant/config/v2/root.rb:52:in `block in finalize!'
	from /opt/vagrant/embedded/gems/2.2.4/gems/vagrant-2.2.4/lib/vagrant/config/v2/root.rb:51:in `each'
	from /opt/vagrant/embedded/gems/2.2.4/gems/vagrant-2.2.4/lib/vagrant/config/v2/root.rb:51:in `finalize!'
	from /opt/vagrant/embedded/gems/2.2.4/gems/vagrant-2.2.4/lib/vagrant/config/v2/loader.rb:21:in `finalize'
	from /opt/vagrant/embedded/gems/2.2.4/gems/vagrant-2.2.4/lib/vagrant/config/loader.rb:200:in `load'
	from /opt/vagrant/embedded/gems/2.2.4/gems/vagrant-2.2.4/lib/vagrant/vagrantfile.rb:29:in `initialize'
	from /opt/vagrant/embedded/gems/2.2.4/gems/vagrant-2.2.4/lib/vagrant/environment.rb:794:in `new'
	from /opt/vagrant/embedded/gems/2.2.4/gems/vagrant-2.2.4/lib/vagrant/environment.rb:794:in `vagrantfile'
	from /opt/vagrant/embedded/gems/2.2.4/gems/vagrant-2.2.4/lib/vagrant/environment.rb:178:in `initialize'
	from /opt/vagrant/embedded/gems/2.2.4/gems/vagrant-2.2.4/bin/vagrant:145:in `new'
	from /opt/vagrant/embedded/gems/2.2.4/gems/vagrant-2.2.4/bin/vagrant:145:in **`<main>'**

WORKAROUND

Can manually add aws.aws_profile = "#{ENV['AWS_PROFILE']}", but really should just let AWS SDK do the work, and not get in the way.

Curious if there was any interest in this. The underlying SDK supports AWS_PROFILE, but looks like we are circumventing existing functionality.

Curious if there was any interest in this. The underlying SDK supports AWS_PROFILE, but looks like we are circumventing existing functionality.

Yes, this is impacting me today :(

I believe I fixed this (or something closely related) in #564.