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

Add support for AWS config and credential files #441

Merged
merged 14 commits into from
Mar 21, 2016

Conversation

alexconst
Copy link
Contributor

When either access_key_id or secret_access_key are not set it will attempt to read from environment variables, if those are empty then it will attempt to read from config and credentials.
It allows choosing a profile (by default it's "default") and an "info" directory (by default $HOME/.aws).
Supported information: region, aws_access_key_id, aws_secret_access_key and aws_session_token.

Closes issue #151

When either access_key_id or secret_access_key are not set it will
attempt to read from environment variables, if those are empty then it
will attempt to read from config and credentials.
It allows choosing a profile (by default it's [default]) and an "info"
directory (by default $HOME/.aws).
Supported information: region, aws_access_key_id, aws_secret_access_key
and aws_session_token.
AWS info (credentials and config) verification is done at validate and
the error message is read from the locales yml file.
@chriswgerber
Copy link

Thanks for the work getting this started. We've been looking for something like this as well.

Two things:

  1. If you're trying to mimic the way the AWS CLI works, config and credential filepaths should fall back to declared values in AWS_SHARED_CREDENTIALS_FILE and AWS_CONFIG_FILE environmental variables before defaulting to ~/.aws/credentials or ~/.aws/config.
  2. You can clean up the config/credential file parser by using an INI/PythonConfig parser such as https://rubygems.org/gems/configparser or https://rubygems.org/gems/iniparse

Fix AWS environment variable names in tests.
Fix AWS variables coupling: id and secret must both be present.
Updated code to work together with finalize defaults.
Set tests to run with defined order, making debugging easier.
Test case: with EC2 credential environment variables set
Test case: without EC2 credential environment variables but with
AWS_CONFIG_FILE and AWS_SHARED_CREDENTIALS_FILE set
Add support for AWS shared credentials location environment variables
AWS_CONFIG_FILE and AWS_SHARED_CREDENTIALS_FILE
@alexconst
Copy link
Contributor Author

@ThatGerber I've implemented 1) and 2).
Let me know if it works for you.

@alexconst
Copy link
Contributor Author

Updated description:
This PR reads AWS config and credentials.
Behaviour aims to mimic what is described in AWS documentation:
http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
http://docs.aws.amazon.com/cli/latest/topic/config-vars.html
Which is the following (stopping at the first successful case):

  1. read config and credentials from environment variables
  2. read config and credentials from files at location defined by environment variables
  3. read config and credentials from files at default location

The mandatory fields for a successful "get credentials" are the id and the secret keys.
Region is not required since Config#finalize falls back to sensible defaults.
The behaviour is all-or-nothing (ie: no mixing between vars and files).

It also allows choosing a profile (by default it's [default]) and an "info"
directory (by default $HOME/.aws), which can be specified in the Vagrantfile.
Supported information: region, aws_access_key_id, aws_secret_access_key, and aws_session_token.

@alexconst
Copy link
Contributor Author

@rtyler Any chance for this and the other PRs to get some love?

@alexconst
Copy link
Contributor Author

@mitchellh is anyone actively maintaining this project?

@madsem
Copy link

madsem commented Mar 6, 2016

@mitchellh don't understand why packer is reading ~/.aws/credentials but vagrant-aws is not. Please look into merging

@@ -7,6 +7,7 @@ group :development do
# gem dependency because we expect to be installed within the
# Vagrant environment itself using `vagrant plugin`.
gem "vagrant", :git => "https://github.com/mitchellh/vagrant.git"
gem 'iniparse', '~> 1.4', '>= 1.4.2'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gem is referred to in vagrant-aws/config.rb so I'm not clear on why it is in the :development group of this Gemfile instead of as a dependency listed in the gemspec proper.

@alexconst
Copy link
Contributor Author

@rtyler I believe I fixed the gemspec issue.

@alexconst
Copy link
Contributor Author

@rtyler any updates on this?

rtyler pushed a commit that referenced this pull request Mar 21, 2016
Add support for AWS config and credential files
@rtyler rtyler merged commit db7bf88 into mitchellh:master Mar 21, 2016
@lantins
Copy link

lantins commented Apr 9, 2016

If possible, I'd love to see a new gem released that includes this change.

@kenorb
Copy link

kenorb commented Apr 15, 2016

I have this error after applying this PR:

$ vagrant up --provider=aws
~/.vagrant.d/gems/gems/vagrant-aws-0.7.0/lib/vagrant-aws/config.rb:537:in `read_aws_files': undefined method `[]' for nil:NilClass (NoMethodError)
    from ~/.vagrant.d/gems/gems/vagrant-aws-0.7.0/lib/vagrant-aws/config.rb:513:in `get_aws_info'
    from ~/.vagrant.d/gems/gems/vagrant-aws-0.7.0/lib/vagrant-aws/config.rb:326:in `finalize!'

My config file is like:

[default]
region = us-east-1
output = text

[testing]
region = us-east-1
output = text

What's wrong?

@chriswgerber
Copy link

@kenorb You are configuring your profiles incorrectly, that's why it's not working.

http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-multiple-profiles

The method is that config files should have [profile NAME]. Credentials files are set up as [NAME].

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants