[aws] Fix IAM role name parsing to come from the ARN (#46076)

* [aws] Change IAM role name parsing to come from the ARN (#45534)

(cherry picked from commit fe6b7f6b5d)

* Changelog
This commit is contained in:
Ryan Brown 2018-10-11 12:43:14 -04:00 committed by Toshio Kuratomi
parent 4fe7671d34
commit d46ed88fa3
2 changed files with 4 additions and 2 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- ec2_metadata_facts - Parse IAM role name from metadata ARN instead of security credential field.

View file

@ -467,8 +467,8 @@ class Ec2Metadata(object):
new_fields = {}
for key, value in fields.items():
split_fields = key[len(uri):].split('/')
if len(split_fields) == 3 and split_fields[0:2] == ['iam', 'security-credentials']:
new_fields[self._prefix % "iam-instance-profile-role"] = split_fields[2]
if len(split_fields) == 2 and split_fields[0:2] == ['iam', 'info_instanceprofilearn']:
new_fields[self._prefix % "iam-instance-profile-role"] = value.split('/')[1]
if len(split_fields) > 1 and split_fields[1]:
new_key = "-".join(split_fields)
new_fields[self._prefix % new_key] = value