mitchellh/vagrant-aws

config.rb:574:in `read_aws_files': undefined method `[]'

iam-decoder opened this issue · 4 comments

looks like the problem is when using aws_profile in the Vagrantfile. when setting up aws configure, mine did not come out as profile nonprod but rather just nonprod so I'm forced to put my Access Key & Access Key ID instead which I can't do for security reasons.

rather than making new aws configs just so this plugin works, I think this section should be changed

# determine section in config ini file
if profile == 'default'
  ini_profile = profile
else
  ini_profile = 'profile ' + profile
end
# get info from config ini file for selected profile
data = File.read(aws_config)
doc_cfg = IniParse.parse(data)

possibly to:

# get info from config ini file for selected profile
data = File.read(aws_config)
doc_cfg = IniParse.parse(data)

# determine section in config ini file
if profile == 'default'  || !doc_cfg[profile].nil?
  ini_profile = profile
else
  ini_profile = 'profile ' + profile
end

OR

# determine section in config ini file
if profile == 'default'
  ini_profile = profile
else
  ini_profile = 'profile ' + profile
end
# get info from config ini file for selected profile
data = File.read(aws_config)
doc_cfg = IniParse.parse(data)
aws_region = doc_cfg[ini_profile]['region']

# determine section in credentials ini file
ini_profile = profile
# get info from credentials ini file for selected profile
data = File.read(aws_creds)
doc_cfg = IniParse.parse(data)
aws_id = doc_cfg[ini_profile]['aws_access_key_id']
aws_secret = doc_cfg[ini_profile]['aws_secret_access_key']
aws_token = doc_cfg[ini_profile]['aws_session_token']

to:

# determine section in credentials ini file
ini_profile = profile
# get info from credentials ini file for selected profile
data = File.read(aws_creds)
doc_cfg = IniParse.parse(data)
aws_region = doc_cfg[ini_profile]['region']
aws_id = doc_cfg[ini_profile]['aws_access_key_id']
aws_secret = doc_cfg[ini_profile]['aws_secret_access_key']
aws_token = doc_cfg[ini_profile]['aws_session_token']

not sure which would work better, but both fix my issue.

How come more people aren't hitting this? it's (almost) a show-stopper in my org. :-(

I don't know. I even supplied the fixes. What I ended up having to do was download and compile my own :/

It looks like some changes were made to my PR but nothing has happened with it yet: #523

I hit on this issue as well. The code in question is reading the aws config file (~/.aws/config), not the credentials file, to read the default region. In that file, each profile is indeed prefixed with the string "profile" except for the "default" profile. e.g.

[default]
region = us-east-1

[profile prod]  
region = us-west-1

If the code does not find such a section, it barfs.

To fix this, add a config section in ~/.aws/config with a region for the profile being used.
So this should not be a blocker for anyone in production or test.

Not sure what the code "fix" would be for this - hardcode a default aws region I suppose? Or perhaps don't set a default region and let aws assume the default?