mitchellh / vagrant-aws

Use Vagrant to manage your EC2 and VPC instances.
MIT License
2.61k stars 572 forks source link

Add support for AWS config and credential files #441

Closed alexconst closed 8 years ago

alexconst commented 8 years ago

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

chriswgerber commented 8 years ago

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
alexconst commented 8 years ago

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

alexconst commented 8 years ago

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 commented 8 years ago

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

alexconst commented 8 years ago

@mitchellh is anyone actively maintaining this project?

madsem commented 8 years ago

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

alexconst commented 8 years ago

@rtyler I believe I fixed the gemspec issue.

alexconst commented 8 years ago

@rtyler any updates on this?

lantins commented 8 years ago

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

kenorb commented 8 years ago

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 commented 8 years ago

@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].