Skip to content

Commit

Permalink
Various ARN handling fixes (ansible-collections#1848)
Browse files Browse the repository at this point in the history
Various ARN handling fixes

Depends-On: ansible-collections#1619
SUMMARY
fixes: ansible-collections#1846
Various modules had hard-coded ARN handling which assumed the use of the main  partition.  This causes problems for folks using Gov Cloud (and aws-cn)
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
plugins/modules/batch_compute_environment.py
plugins/modules/ec2_launch_template.py
plugins/modules/elasticache_info.py
plugins/modules/iam_group.py
plugins/modules/iam_role.py
plugins/modules/msk_config.py
plugins/modules/redshift.py
plugins/modules/sns_topic.py
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@25a636c
  • Loading branch information
tremble authored and mandar242 committed Sep 13, 2023
1 parent e26f1cc commit dabe138
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions plugins/modules/iam_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.arn import validate_aws_arn
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry

Expand Down Expand Up @@ -203,7 +204,7 @@ def compare_group_members(current_group_members, new_group_members):


def convert_friendly_names_to_arns(connection, module, policy_names):
if not any(not policy.startswith("arn:") for policy in policy_names if policy is not None):
if all(validate_aws_arn(policy, service="iam") for policy in policy_names if policy is not None):
return policy_names
allpolicies = {}
paginator = connection.get_paginator("list_policies")
Expand All @@ -213,7 +214,7 @@ def convert_friendly_names_to_arns(connection, module, policy_names):
allpolicies[policy["PolicyName"]] = policy["Arn"]
allpolicies[policy["Arn"]] = policy["Arn"]
try:
return [allpolicies[policy] for policy in policy_names]
return [allpolicies[policy] for policy in policy_names if policy is not None]
except KeyError as e:
module.fail_json(msg="Couldn't find policy: " + str(e))

Expand Down

0 comments on commit dabe138

Please sign in to comment.