Skip to content

Commit

Permalink
Bulk migration to AnsibleAWSModule (ansible-collections#173)
Browse files Browse the repository at this point in the history
* Update comments to reference AnsibleAWSModule rather than AnsibleModule
* Bulk re-order imports and split onto one from import per-line.
* Add AnsibleAWSModule imports
* Migrate boto 2 based modules to AnsibleAWSModule
* Move boto3-only modules over to AnsibleAWSModule
* Remove extra ec2_argument_spec calls - not needed now we're using AnsibleAWSModule
* Remove most HAS_BOTO3 code, it's handled by AnsibleAWSModule
* Handle missing Boto 2 consistently  (HAS_BOTO)
* Remove AnsibleModule imports
* Changelog fragment

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@818c6d2
  • Loading branch information
tremble authored and alinabuzachis committed Oct 6, 2023
1 parent 06cb45d commit 134e48a
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions plugins/modules/iam_managed_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,17 @@
try:
import botocore
except ImportError:
pass # caught by imported HAS_BOTO3

from ansible.module_utils.basic import AnsibleModule
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import (boto3_conn,
get_aws_connection_info,
ec2_argument_spec,
AWSRetry,
camel_dict_to_snake_dict,
HAS_BOTO3,
compare_policies,
)
pass # Handled by AnsibleAWSModule

from ansible.module_utils._text import to_native

from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import compare_policies


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
def list_policies_with_backoff(iam):
Expand Down Expand Up @@ -296,25 +294,21 @@ def detach_all_entities(module, iam, policy, **kwargs):


def main():
argument_spec = ec2_argument_spec()
argument_spec.update(dict(
argument_spec = dict(
policy_name=dict(required=True),
policy_description=dict(default=''),
policy=dict(type='json'),
make_default=dict(type='bool', default=True),
only_version=dict(type='bool', default=False),
fail_on_delete=dict(type='bool', removed_at_date='2022-06-01', removed_from_collection='community.aws'),
state=dict(default='present', choices=['present', 'absent']),
))
)

module = AnsibleModule(
module = AnsibleAWSModule(
argument_spec=argument_spec,
required_if=[['state', 'present', ['policy']]]
required_if=[['state', 'present', ['policy']]],
)

if not HAS_BOTO3:
module.fail_json(msg='boto3 is required for this module')

name = module.params.get('policy_name')
description = module.params.get('policy_description')
state = module.params.get('state')
Expand Down

0 comments on commit 134e48a

Please sign in to comment.