Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into patch-9
Browse files Browse the repository at this point in the history
Aditya Putta authored Oct 10, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 170ad43 + b84ffc7 commit f66be46
Showing 284 changed files with 8,438 additions and 685 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/changelog_and_linters.yml
Original file line number Diff line number Diff line change
@@ -7,4 +7,7 @@ jobs:
changelog:
uses: ansible-network/github_actions/.github/workflows/changelog.yml@main
linters:
uses: ansible-network/github_actions/.github/workflows/tox-linters.yml@main
uses: ansible-network/github_actions/.github/workflows/tox.yml@main
with:
envname: ""
labelname: "lint"
15 changes: 15 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
rules:
indentation:
ignore: &default_ignores |
# automatically generated, we can't control it
changelogs/changelog.yaml
# Will be gone when we release and automatically reformatted
changelogs/fragments/*
document-start:
ignore: *default_ignores
line-length:
ignore: *default_ignores
max: 160

ignore-from-file: .gitignore
24 changes: 24 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -5,6 +5,30 @@ amazon.aws Release Notes
.. contents:: Topics


v6.4.0
======

Release Summary
---------------

This release brings a new module named ``amazon.aws.ec2_key_info``, some documentation improvements, new features and bugfixes.

Minor Changes
-------------

- cloudformation - Add support for ``disable_rollback`` to update stack operation (https://github.com/ansible-collections/amazon.aws/issues/1681).
- ec2_key - add support for new parameter ``file_name`` to save private key in when new key is created by AWS. When this option is provided the generated private key will be removed from the module return (https://github.com/ansible-collections/amazon.aws/pull/1704).

Bugfixes
--------

- backup_selection - ensures that updating an existing selection will add new ``Conditions`` if there previously were not any (https://github.com/ansible-collections/amazon.aws/pull/1701).

New Modules
-----------

- ec2_key_info - Gather information about EC2 key pairs in AWS

v6.3.0
======

32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Amazon AWS Collection
The Ansible Amazon AWS collection includes a variety of Ansible content to help automate the management of AWS instances. This collection is maintained by the Ansible cloud team.
The Ansible Amazon AWS collection includes a variety of Ansible content to help automate the management of AWS services. This collection is maintained by the Ansible cloud team.

AWS related modules and plugins supported by the Ansible community are in the [community.aws](https://github.com/ansible-collections/community.aws/) collection.

@@ -13,19 +13,33 @@ Use amazon.aws 4.x.y if you are using Ansible 2.9 or Ansible Core 2.10.

This collection depends on the AWS SDK for Python (Boto3 and Botocore). Due to the
[AWS SDK Python Support Policy](https://aws.amazon.com/blogs/developer/python-support-policy-updates-for-aws-sdks-and-tools/)
this collection requires Python 3.6 or greater.

Amazon have also announced the end of support for
[Python less than 3.7](https://aws.amazon.com/blogs/developer/python-support-policy-updates-for-aws-sdks-and-tools/).
As such support for Python less than 3.7 by this collection has been deprecated and will be removed in release 7.0.0.
Additionally, support for Python less than 3.8 is expected to be removed in a release after 2024-12-01 based on currently
available schedules.
this collection requires Python 3.7 or greater.

Amazon have also announced the planned end of support for
[Python less than 3.8](https://aws.amazon.com/blogs/developer/python-support-policy-updates-for-aws-sdks-and-tools/).
As such support for Python less than 3.8 will be removed in a release after 2024-12-01.

<!---
### End of Support by Python Versions:
| Python Version | AWS SDK | Collection |
| -------------- | -------- | ---------- |
| 2.7 | July 2021 | Release 2.0.0 (September 2021) |
| 3.4 | February 2021 | Release 1.0.0 (June 2020) |
| 3.5 | February 2021 | Release 2.0.0 (September 2021) |
| 3.6 | May 2022 | Release 7.0.0 (November 2023) |
| 3.7 | December 2023 | *After December 2024* |
| 3.8 | April 2025 | *After April 2026* |
| 3.9 | April 2026 | *After April 2027* |
| 3.10 | April 2027 | *After April 2028* |
| 3.11 | April 2028 | *After April 2029* |
--->

## AWS SDK version compatibility

Starting with the 2.0.0 releases of amazon.aws and community.aws, it is generally the collection's policy to support the versions of `botocore` and `boto3` that were released 12 months prior to the most recent major collection release, following semantic versioning (for example, 2.0.0, 3.0.0).

Version 6.0.0 of this collection supports `boto3 >= 1.22.0` and `botocore >= 1.25.0`
Version 7.0.0 of this collection supports `boto3 >= 1.26.0` and `botocore >= 1.29.0`

All support for the original AWS SDK `boto` was removed in release 4.0.0.

32 changes: 29 additions & 3 deletions changelogs/changelog.yaml
Original file line number Diff line number Diff line change
@@ -854,9 +854,9 @@ releases:
- validate-plugins.yml
release_date: '2022-05-26'
3.3.1:
release_date: '2022-06-22'
changes:
release_summary: Various minor documentation fixes.
release_date: '2022-06-22'
3.4.0:
changes:
bugfixes:
@@ -2007,8 +2007,9 @@ releases:
- ec2_vpc_route_table - add support for Carrier Gateway entry (https://github.com/ansible-collections/amazon.aws/pull/926).
- ec2_vpc_subnet - retry fetching subnet details after creation if the first
attempt fails (https://github.com/ansible-collections/amazon.aws/pull/1526).
- inventory aws ec2 - add parameter ``use_ssm_inventory`` allowing to query ssm
inventory information for configured EC2 instances and populate hostvars (https://github.com/ansible-collections/amazon.aws/issues/704).
- inventory aws ec2 - add parameter ``use_ssm_inventory`` allowing to query
ssm inventory information for configured EC2 instances and populate hostvars
(https://github.com/ansible-collections/amazon.aws/issues/704).
- inventory plugins - refactor cache handling (https://github.com/ansible-collections/amazon.aws/pull/1285).
- inventory plugins - refactor file verification handling (https://github.com/ansible-collections/amazon.aws/pull/1285).
- inventory_aws_ec2 integration tests - replace local module ``test_get_ssm_inventory``
@@ -2370,3 +2371,28 @@ releases:
- ec2_vpc_route_table_info-filter-fix.yml
- release_summary.yml
release_date: '2023-08-03'
6.4.0:
changes:
bugfixes:
- backup_selection - ensures that updating an existing selection will add new
``Conditions`` if there previously were not any (https://github.com/ansible-collections/amazon.aws/pull/1701).
minor_changes:
- cloudformation - Add support for ``disable_rollback`` to update stack operation
(https://github.com/ansible-collections/amazon.aws/issues/1681).
- ec2_key - add support for new parameter ``file_name`` to save private key
in when new key is created by AWS. When this option is provided the generated
private key will be removed from the module return (https://github.com/ansible-collections/amazon.aws/pull/1704).
release_summary: This release brings a new module named ``amazon.aws.ec2_key_info``,
some documentation improvements, new features and bugfixes.
fragments:
- 1681-cloudformation-add-support-for-disable_rollback-to-update.yml
- 1685-ssm_parameter-update-examples-to-use-fqcn.yml
- 1701-backup-selection-bugfix.yml
- doc_update_for_keypair_nolog.yml
- ec2_key-fix-security-vulnerability.yml
- release_summary.yml
modules:
- description: Gather information about EC2 key pairs in AWS
name: ec2_key_info
namespace: ''
release_date: '2023-09-05'
33 changes: 17 additions & 16 deletions changelogs/config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
changelog_filename_template: ../CHANGELOG.rst
changelog_filename_version_depth: 0
changes_file: changelog.yaml
@@ -9,21 +10,21 @@ notesdir: fragments
prelude_section_name: release_summary
prelude_section_title: Release Summary
sections:
- - major_changes
- Major Changes
- - minor_changes
- Minor Changes
- - breaking_changes
- Breaking Changes / Porting Guide
- - deprecated_features
- Deprecated Features
- - removed_features
- Removed Features (previously deprecated)
- - security_fixes
- Security Fixes
- - bugfixes
- Bugfixes
- - known_issues
- Known Issues
- - major_changes
- Major Changes
- - minor_changes
- Minor Changes
- - breaking_changes
- Breaking Changes / Porting Guide
- - deprecated_features
- Deprecated Features
- - removed_features
- Removed Features (previously deprecated)
- - security_fixes
- Security Fixes
- - bugfixes
- Bugfixes
- - known_issues
- Known Issues
title: amazon.aws
trivial_section_name: trivial
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
minor_changes:
- route53_health_check - add support for another ``type`` choice called ``CALCULATED`` (https://github.com/ansible-collections/amazon.aws/pull/1631).
- route53_health_check - add support for another ``type`` choice called ``CALCULATED`` (https://github.com/ansible-collections/amazon.aws/pull/1631).
- route53_health_check - add support for a string list parameter called ``child_health_checks`` to specify health checks that must be healthy for the calculated health check (https://github.com/ansible-collections/amazon.aws/pull/1631).
- route53_health_check - add support for an integer parameter called ``health_threshold`` to specify the minimum number of healthy child health checks that must be healthy for the calculated health check (https://github.com/ansible-collections/amazon.aws/pull/1631).
- route53_health_check - add support for an integer parameter called ``health_threshold`` to specify the minimum number of healthy child health checks that must be healthy for the calculated health check (https://github.com/ansible-collections/amazon.aws/pull/1631).
2 changes: 1 addition & 1 deletion changelogs/fragments/1647-add-type-started-and-stopped.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
minor_changes:
- rds_cluster - add support for another ``state`` choice called ``started``. This starts the rds cluster (https://github.com/ansible-collections/amazon.aws/pull/1647/files).
- rds_cluster - add support for another ``state`` choice called ``stopped``. This stops the rds cluster (https://github.com/ansible-collections/amazon.aws/pull/1647/files).
- rds_cluster - add support for another ``state`` choice called ``stopped``. This stops the rds cluster (https://github.com/ansible-collections/amazon.aws/pull/1647/files).

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions changelogs/fragments/1701-backup-selection-bugfix.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- rds_cluster - Add support for removing cluster from global db (https://github.com/ansible-collections/amazon.aws/pull/1705).
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bugfixes:
- elb_application_lb_info - ensure all API queries use the retry decorator (https://github.com/ansible-collections/amazon.aws/issues/1767).
minor_changes:
- elb_application_lb_info - drop redundant ``describe_load_balancers`` call fetching ``ip_address_type`` (https://github.com/ansible-collections/amazon.aws/pull/1768).
2 changes: 2 additions & 0 deletions changelogs/fragments/1771-isort.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- amazon.aws collection - apply isort code formatting to ensure consistent formatting of code (https://github.com/ansible-collections/amazon.aws/pull/1771).
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "elb_application_lb_info - add new parameters ``include_attributes``, ``include_listeners`` and ``include_listener_rules`` to optionally speed up module by fetching less information (https://github.com/ansible-collections/amazon.aws/pull/1778)."
2 changes: 2 additions & 0 deletions changelogs/fragments/20230906-galaxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trivial:
- galaxy.yml - add description to collection.
2 changes: 2 additions & 0 deletions changelogs/fragments/20230908-alias-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trivial:
- Update integration tests to reflect renamed plugins
2 changes: 2 additions & 0 deletions changelogs/fragments/20230911-ec2_ami-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trivial:
- ec2_ami - fix version_added for org owners.
6 changes: 6 additions & 0 deletions changelogs/fragments/botocore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
breaking_changes:
- The amazon.aws collection has dropped support for ``botocore<1.29.0`` and
``boto3<1.26.0``. Most modules will continue to work with older versions of the AWS SDK, however
compatability with older versions of the SDK is not guaranteed and will not be tested. When using
older versions of the SDK a warning will be emitted by Ansible
(https://github.com/ansible-collections/amazon.aws/pull/1763).
3 changes: 0 additions & 3 deletions changelogs/fragments/doc_update_for_keypair_nolog.yml

This file was deleted.

3 changes: 0 additions & 3 deletions changelogs/fragments/ec2_key-fix-security-vulnerability.yml

This file was deleted.

5 changes: 5 additions & 0 deletions changelogs/fragments/migrate_aws_region_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
major_changes:
- aws_region_info - The module has been migrated from the ``community.aws`` collection.
Playbooks using the Fully Qualified Collection Name for this module should be
updated to use ``amazon.aws.aws_region_info``.
7 changes: 7 additions & 0 deletions changelogs/fragments/migrate_iam_access_key.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
major_changes:
- iam_access_key - The module has been migrated from the ``community.aws`` collection.
Playbooks using the Fully Qualified Collection Name for this module should be updated
to use ``amazon.aws.iam_access_key``.
- iam_access_key_info - The module has been migrated from the ``community.aws`` collection.
Playbooks using the Fully Qualified Collection Name for this module should be updated
to use ``amazon.aws.iam_access_key_info``.
4 changes: 4 additions & 0 deletions changelogs/fragments/migrate_iam_group.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
major_changes:
- iam_group - The module has been migrated from the ``community.aws`` collection.
Playbooks using the Fully Qualified Collection Name for this module should be updated
to use ``amazon.aws.iam_group`` (https://github.com/ansible-collections/amazon.aws/pull/1755).
4 changes: 4 additions & 0 deletions changelogs/fragments/migrate_iam_managed_policy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
major_changes:
- iam_managed_policy - The module has been migrated from the ``community.aws`` collection.
Playbooks using the Fully Qualified Collection Name for this module should be updated
to use ``amazon.aws.iam_managed_policy`` (https://github.com/ansible-collections/amazon.aws/pull/1762).
4 changes: 4 additions & 0 deletions changelogs/fragments/migrate_iam_mfa_device_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
major_changes:
- iam_mfa_device_info - The module has been migrated from the ``community.aws`` collection.
Playbooks using the Fully Qualified Collection Name for this module should be updated
to use ``amazon.aws.iam_mfa_device_info`` (https://github.com/ansible-collections/amazon.aws/pull/1761).
4 changes: 4 additions & 0 deletions changelogs/fragments/migrate_iam_password_policy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
major_changes:
- iam_password_policy - The module has been migrated from the ``community.aws`` collection.
Playbooks using the Fully Qualified Collection Name for this module should be updated
to use ``amazon.aws.iam_password_policy``.
7 changes: 7 additions & 0 deletions changelogs/fragments/migrate_iam_role.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
major_changes:
- iam_role - The module has been migrated from the ``community.aws`` collection. Playbooks
using the Fully Qualified Collection Name for this module should be updated to use
``amazon.aws.iam_role`` (https://github.com/ansible-collections/amazon.aws/pull/1760).
- iam_role_info - The module has been migrated from the ``community.aws`` collection.
Playbooks using the Fully Qualified Collection Name for this module should be updated
to use ``amazon.aws.iam_role_info`` (https://github.com/ansible-collections/amazon.aws/pull/1760).
8 changes: 8 additions & 0 deletions changelogs/fragments/migrate_s3_bucket_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
major_changes:
- aws_s3_bucket_info - The module has been migrated from the ``community.aws`` collection.
Playbooks using the Fully Qualified Collection Name for this module should be
updated to use ``amazon.aws.aws_s3_bucket_info``.
- s3_bucket_info - The module has been migrated from the ``community.aws`` collection.
Playbooks using the Fully Qualified Collection Name for this module should be
updated to use ``amazon.aws.s3_bucket_info``.
4 changes: 4 additions & 0 deletions changelogs/fragments/migrate_sts_assume_role.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
major_changes:
- sts_assume_role - The module has been migrated from the ``community.aws`` collection.
Playbooks using the Fully Qualified Collection Name for this module should be updated
to use ``amazon.aws.sts_assume_role``.
10 changes: 10 additions & 0 deletions changelogs/fragments/python37.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
breaking_changes:
- amazon.aws collection - due to the AWS SDKs announcing the end of support
for Python less than 3.7 (https://aws.amazon.com/blogs/developer/python-support-policy-updates-for-aws-sdks-and-tools/)
support for Python less than 3.7 by this collection wss been deprecated in release 6.0.0 and removed in release 7.0.0.
(https://github.com/ansible-collections/amazon.aws/pull/1763).

# We've already announced the deprecation for <3.8 (with 6.0.0), dropping support for <3.9 on ours side will happen
# after April 2026. This is about 2 years + 5 months away assuming a November 7.0.0 release, we could announce
# the deprecation now, but assuming we release 8.0.0 in about 6 months a just short of 2 year
# deprecation feels fine given it's predictable.
3 changes: 2 additions & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
namespace: amazon
name: aws
version: 7.0.0-dev0
readme: README.md
authors:
- Ansible (https://github.com/ansible)
description: null
description: A variety of Ansible content to help automate the management of AWS services.
license_file: COPYING
tags: [amazon, aws, cloud]
repository: https://github.com/ansible-collections/amazon.aws
217 changes: 116 additions & 101 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -2,106 +2,118 @@
requires_ansible: '>=2.12.0'
action_groups:
aws:
- autoscaling_group
- autoscaling_group_info
- aws_az_info
- aws_caller_info
- aws_s3
- backup_plan
- backup_plan_info
- backup_tag
- backup_tag_info
- backup_selection
- backup_selection_info
- backup_vault
- backup_vault_info
- cloudformation
- cloudformation_info
- cloudtrail
- cloudtrail_info
- cloudwatch_metric_alarm
- cloudwatchevent_rule
- cloudwatchevent_rule
- cloudwatchlogs_log_group
- cloudwatchlogs_log_group_info
- cloudwatchlogs_log_group_metric_filter
- cloudwatch_metric_alarm_info
- ec2_ami
- ec2_ami_info
- ec2_eip
- ec2_eip_info
- ec2_elb_lb
- ec2_eni
- ec2_eni_info
- ec2_group
- ec2_group_info
- ec2_instance
- ec2_instance_info
- ec2_key
- ec2_key_info
- ec2_security_group
- ec2_security_group_info
- ec2_snapshot
- ec2_snapshot_info
- ec2_spot_instance
- ec2_spot_instance_info
- ec2_tag
- ec2_tag_info
- ec2_vol
- ec2_vol_info
- ec2_vpc_dhcp_option
- ec2_vpc_dhcp_option_info
- ec2_vpc_endpoint
- ec2_vpc_endpoint_info
- ec2_vpc_endpoint_service_info
- ec2_vpc_igw
- ec2_vpc_igw_info
- ec2_vpc_nat_gateway
- ec2_vpc_nat_gateway_info
- ec2_vpc_net
- ec2_vpc_net_info
- ec2_vpc_route_table
- ec2_vpc_route_table_info
- ec2_vpc_subnet
- ec2_vpc_subnet_info
- elb_application_lb
- elb_application_lb_info
- elb_classic_lb
- execute_lambda
- iam_instance_profile
- iam_instance_profile_info
- iam_policy
- iam_policy_info
- iam_user
- iam_user_info
- kms_key
- kms_key_info
- lambda
- lambda_alias
- lambda_event
- lambda_execute
- lambda_info
- lambda_layer
- lambda_layer_info
- lambda_policy
- rds_cluster
- rds_cluster_info
- rds_cluster_snapshot
- rds_instance
- rds_instance_info
- rds_instance_snapshot
- rds_option_group
- rds_option_group_info
- rds_param_group
- rds_snapshot_info
- rds_subnet_group
- route53
- route53_health_check
- route53_info
- route53_zone
- s3_bucket
- s3_object
- s3_object_info
- autoscaling_group
- autoscaling_group_info
- aws_az_info
- aws_caller_info
- aws_region_info
- aws_s3
- aws_s3_bucket_info
- backup_plan
- backup_plan_info
- backup_selection
- backup_selection_info
- backup_tag
- backup_tag_info
- backup_vault
- backup_vault_info
- cloudformation
- cloudformation_info
- cloudtrail
- cloudtrail_info
- cloudwatch_metric_alarm
- cloudwatch_metric_alarm_info
- cloudwatchevent_rule
- cloudwatchevent_rule
- cloudwatchlogs_log_group
- cloudwatchlogs_log_group_info
- cloudwatchlogs_log_group_metric_filter
- ec2_ami
- ec2_ami_info
- ec2_eip
- ec2_eip_info
- ec2_elb_lb
- ec2_eni
- ec2_eni_info
- ec2_group
- ec2_group_info
- ec2_instance
- ec2_instance_info
- ec2_key
- ec2_key_info
- ec2_security_group
- ec2_security_group_info
- ec2_snapshot
- ec2_snapshot_info
- ec2_spot_instance
- ec2_spot_instance_info
- ec2_tag
- ec2_tag_info
- ec2_vol
- ec2_vol_info
- ec2_vpc_dhcp_option
- ec2_vpc_dhcp_option_info
- ec2_vpc_endpoint
- ec2_vpc_endpoint_info
- ec2_vpc_endpoint_service_info
- ec2_vpc_igw
- ec2_vpc_igw_info
- ec2_vpc_nat_gateway
- ec2_vpc_nat_gateway_info
- ec2_vpc_net
- ec2_vpc_net_info
- ec2_vpc_route_table
- ec2_vpc_route_table_info
- ec2_vpc_subnet
- ec2_vpc_subnet_info
- elb_application_lb
- elb_application_lb_info
- elb_classic_lb
- execute_lambda
- iam_access_key
- iam_access_key_info
- iam_group
- iam_instance_profile
- iam_instance_profile_info
- iam_managed_policy
- iam_mfa_device_info
- iam_password_policy
- iam_policy
- iam_policy_info
- iam_role
- iam_role_info
- iam_user
- iam_user_info
- kms_key
- kms_key_info
- lambda
- lambda_alias
- lambda_event
- lambda_execute
- lambda_info
- lambda_layer
- lambda_layer_info
- lambda_policy
- rds_cluster
- rds_cluster_info
- rds_cluster_snapshot
- rds_instance
- rds_instance_info
- rds_instance_snapshot
- rds_option_group
- rds_option_group_info
- rds_param_group
- rds_snapshot_info
- rds_subnet_group
- route53
- route53_health_check
- route53_info
- route53_zone
- s3_bucket
- s3_bucket_info
- s3_object
- s3_object_info
- sts_assume_role
plugin_routing:
action:
aws_s3:
@@ -116,6 +128,9 @@ plugin_routing:
aws_s3:
# Deprecation for this alias should not *start* prior to 2024-09-01
redirect: amazon.aws.s3_object
aws_s3_bucket_info:
# Deprecation for this alias should not *start* prior to 2024-09-01
redirect: amazon.aws.s3_bucket_info
ec2_asg:
# Deprecation for this alias should not *start* prior to 2024-09-01
redirect: amazon.aws.autoscaling_group
@@ -143,4 +158,4 @@ plugin_routing:
redirect: amazon.aws.ssm_parameter
aws_secret:
# Deprecation for this alias should not *start* prior to 2024-09-01
redirect: amazon.aws.secretsmanager_secret
redirect: amazon.aws.secretsmanager_secret
5 changes: 4 additions & 1 deletion plugins/action/s3_object.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,10 @@

import os

from ansible.errors import AnsibleError, AnsibleAction, AnsibleActionFail, AnsibleFileNotFound
from ansible.errors import AnsibleAction
from ansible.errors import AnsibleActionFail
from ansible.errors import AnsibleError
from ansible.errors import AnsibleFileNotFound
from ansible.module_utils._text import to_text
from ansible.plugins.action import ActionBase
from ansible.utils.vars import merge_hash
2 changes: 1 addition & 1 deletion plugins/callback/aws_resource_actions.py
Original file line number Diff line number Diff line change
@@ -33,8 +33,8 @@
#
"""

from ansible.plugins.callback import CallbackBase
from ansible.module_utils._text import to_native
from ansible.plugins.callback import CallbackBase


class CallbackModule(CallbackBase):
4 changes: 1 addition & 3 deletions plugins/inventory/aws_ec2.py
Original file line number Diff line number Diff line change
@@ -275,13 +275,11 @@
from ansible.module_utils._text import to_text
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict


from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.plugin_utils.inventory import AWSInventoryBase


# The mappings give an array of keys to get from the filter name to the value
# returned by boto3's EC2 describe_instances method.

3 changes: 1 addition & 2 deletions plugins/inventory/aws_rds.py
Original file line number Diff line number Diff line change
@@ -87,9 +87,8 @@
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict

from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.plugin_utils.inventory import AWSInventoryBase


4 changes: 2 additions & 2 deletions plugins/lookup/aws_service_ip_ranges.py
Original file line number Diff line number Diff line change
@@ -46,12 +46,12 @@
import json

from ansible.errors import AnsibleLookupError
from ansible.module_utils._text import to_native
from ansible.module_utils.six.moves.urllib.error import HTTPError
from ansible.module_utils.six.moves.urllib.error import URLError
from ansible.module_utils._text import to_native
from ansible.module_utils.urls import ConnectionError
from ansible.module_utils.urls import open_url
from ansible.module_utils.urls import SSLValidationError
from ansible.module_utils.urls import open_url
from ansible.plugins.lookup import LookupBase


3 changes: 1 addition & 2 deletions plugins/lookup/secretsmanager_secret.py
Original file line number Diff line number Diff line change
@@ -127,13 +127,12 @@
pass # Handled by AWSLookupBase

from ansible.errors import AnsibleLookupError
from ansible.module_utils.six import string_types
from ansible.module_utils._text import to_native
from ansible.module_utils.six import string_types

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

from ansible_collections.amazon.aws.plugins.plugin_utils.lookup import AWSLookupBase


5 changes: 2 additions & 3 deletions plugins/lookup/ssm_parameter.py
Original file line number Diff line number Diff line change
@@ -132,13 +132,12 @@

from ansible.errors import AnsibleLookupError
from ansible.module_utils._text import to_native
from ansible.utils.display import Display
from ansible.module_utils.six import string_types
from ansible.utils.display import Display

from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry

from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.plugin_utils.lookup import AWSLookupBase

display = Display()
3 changes: 2 additions & 1 deletion plugins/module_utils/acm.py
Original file line number Diff line number Diff line change
@@ -16,7 +16,8 @@
"""

try:
from botocore.exceptions import BotoCoreError, ClientError
from botocore.exceptions import BotoCoreError
from botocore.exceptions import ClientError
except ImportError:
pass

1 change: 1 addition & 0 deletions plugins/module_utils/backup.py
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
pass # Handled by HAS_BOTO3

from typing import Union

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict


7 changes: 4 additions & 3 deletions plugins/module_utils/botocore.py
Original file line number Diff line number Diff line change
@@ -60,12 +60,12 @@
from ansible.module_utils.six import binary_type
from ansible.module_utils.six import text_type

from .common import get_collection_info
from .exceptions import AnsibleBotocoreError
from .retries import AWSRetry
from .common import get_collection_info

MINIMUM_BOTOCORE_VERSION = "1.25.0"
MINIMUM_BOTO3_VERSION = "1.22.0"
MINIMUM_BOTOCORE_VERSION = "1.29.0"
MINIMUM_BOTO3_VERSION = "1.26.0"


def _get_user_agent_string():
@@ -412,6 +412,7 @@ def enable_placebo(session):
pill.record()
if "_ANSIBLE_PLACEBO_REPLAY" in os.environ:
import shutil

import placebo

existing_entries = sorted([int(i) for i in os.listdir(os.environ["_ANSIBLE_PLACEBO_REPLAY"])])
2 changes: 1 addition & 1 deletion plugins/module_utils/cloud.py
Original file line number Diff line number Diff line change
@@ -27,9 +27,9 @@
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import time
import functools
import random
import time


class BackoffIterator:
3 changes: 2 additions & 1 deletion plugins/module_utils/cloudfront_facts.py
Original file line number Diff line number Diff line change
@@ -22,9 +22,10 @@
except ImportError:
pass

from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict

from .retries import AWSRetry
from .tagging import boto3_tag_list_to_ansible_dict
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict


class CloudFrontFactsServiceManagerFailure(Exception):
2 changes: 1 addition & 1 deletion plugins/module_utils/core.py
Original file line number Diff line number Diff line change
@@ -42,9 +42,9 @@

# Used to live here, moved into ansible_collections.amazon.aws.plugins.module_utils.botocore
from .botocore import HAS_BOTO3 # pylint: disable=unused-import
from .botocore import get_boto3_client_method_parameters # pylint: disable=unused-import
from .botocore import is_boto3_error_code # pylint: disable=unused-import
from .botocore import is_boto3_error_message # pylint: disable=unused-import
from .botocore import get_boto3_client_method_parameters # pylint: disable=unused-import
from .botocore import normalize_boto3_result # pylint: disable=unused-import

# Used to live here, moved into ansible_collections.amazon.aws.plugins.module_utils.exceptions
25 changes: 12 additions & 13 deletions plugins/module_utils/ec2.py
Original file line number Diff line number Diff line change
@@ -40,26 +40,25 @@
import re

from ansible.module_utils.ansible_release import __version__
from ansible.module_utils.six import string_types
from ansible.module_utils.six import integer_types

# Used to live here, moved into ansible.module_utils.common.dict_transformations
from ansible.module_utils.common.dict_transformations import _camel_to_snake # pylint: disable=unused-import
from ansible.module_utils.common.dict_transformations import _snake_to_camel # pylint: disable=unused-import
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict # pylint: disable=unused-import
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict # pylint: disable=unused-import
from ansible.module_utils.six import integer_types
from ansible.module_utils.six import string_types

# Used to live here, moved into # ansible_collections.amazon.aws.plugins.module_utils.arn
# Used to live here, moved into ansible_collections.amazon.aws.plugins.module_utils.arn
from .arn import is_outpost_arn as is_outposts_arn # pylint: disable=unused-import

# Used to live here, moved into ansible_collections.amazon.aws.plugins.module_utils.botocore
from .botocore import HAS_BOTO3 # pylint: disable=unused-import
from .botocore import boto3_conn # pylint: disable=unused-import
from .botocore import boto3_inventory_conn # pylint: disable=unused-import
from .botocore import boto_exception # pylint: disable=unused-import
from .botocore import get_aws_region # pylint: disable=unused-import
from .botocore import get_aws_connection_info # pylint: disable=unused-import

from .botocore import get_aws_region # pylint: disable=unused-import
from .botocore import paginated_query_with_retries

# Used to live here, moved into ansible_collections.amazon.aws.plugins.module_utils.exceptions
@@ -70,6 +69,14 @@
from .modules import _aws_common_argument_spec as aws_common_argument_spec # pylint: disable=unused-import
from .modules import aws_argument_spec as ec2_argument_spec # pylint: disable=unused-import

# Used to live here, moved into ansible_collections.amazon.aws.plugins.module_utils.policy
from .policy import _py3cmp as py3cmp # pylint: disable=unused-import
from .policy import compare_policies # pylint: disable=unused-import
from .policy import sort_json_policy_dict # pylint: disable=unused-import

# Used to live here, moved into ansible_collections.amazon.aws.plugins.module_utils.retries
from .retries import AWSRetry # pylint: disable=unused-import

# Used to live here, moved into ansible_collections.amazon.aws.plugins.module_utils.tagging
from .tagging import ansible_dict_to_boto3_tag_list # pylint: disable=unused-import
from .tagging import boto3_tag_list_to_ansible_dict # pylint: disable=unused-import
@@ -79,14 +86,6 @@
from .transformation import ansible_dict_to_boto3_filter_list # pylint: disable=unused-import
from .transformation import map_complex_type # pylint: disable=unused-import

# Used to live here, moved into # ansible_collections.amazon.aws.plugins.module_utils.policy
from .policy import _py3cmp as py3cmp # pylint: disable=unused-import
from .policy import compare_policies # pylint: disable=unused-import
from .policy import sort_json_policy_dict # pylint: disable=unused-import

# Used to live here, moved into # ansible_collections.amazon.aws.plugins.module_utils.retries
from .retries import AWSRetry # pylint: disable=unused-import

try:
import botocore
except ImportError:
3 changes: 2 additions & 1 deletion plugins/module_utils/elb_utils.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

try:
from botocore.exceptions import BotoCoreError, ClientError
from botocore.exceptions import BotoCoreError
from botocore.exceptions import ClientError
except ImportError:
pass

9 changes: 5 additions & 4 deletions plugins/module_utils/elbv2.py
Original file line number Diff line number Diff line change
@@ -7,17 +7,18 @@
from copy import deepcopy

try:
from botocore.exceptions import BotoCoreError, ClientError
from botocore.exceptions import BotoCoreError
from botocore.exceptions import ClientError
except ImportError:
pass

from .retries import AWSRetry
from .tagging import ansible_dict_to_boto3_tag_list
from .tagging import boto3_tag_list_to_ansible_dict
from .ec2 import get_ec2_security_group_ids_from_names
from .elb_utils import convert_tg_name_to_arn
from .elb_utils import get_elb
from .elb_utils import get_elb_listener
from .retries import AWSRetry
from .tagging import ansible_dict_to_boto3_tag_list
from .tagging import boto3_tag_list_to_ansible_dict
from .waiters import get_waiter


6 changes: 3 additions & 3 deletions plugins/module_utils/modules.py
Original file line number Diff line number Diff line change
@@ -48,19 +48,19 @@
# Python 3
from io import StringIO

from ansible.module_utils._text import to_native
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import env_fallback
from ansible.module_utils.basic import missing_required_lib
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible.module_utils._text import to_native

from .botocore import boto3_conn
from .botocore import boto3_at_least
from .botocore import boto3_conn
from .botocore import botocore_at_least
from .botocore import check_sdk_version_supported
from .botocore import gather_sdk_versions
from .botocore import get_aws_connection_info
from .botocore import get_aws_region
from .botocore import gather_sdk_versions
from .exceptions import AnsibleBotocoreError
from .retries import RetryingBotoClientWrapper

3 changes: 1 addition & 2 deletions plugins/module_utils/policy.py
Original file line number Diff line number Diff line change
@@ -30,12 +30,11 @@

from functools import cmp_to_key

import ansible.module_utils.common.warnings as ansible_warnings
from ansible.module_utils._text import to_text
from ansible.module_utils.six import binary_type
from ansible.module_utils.six import string_types

import ansible.module_utils.common.warnings as ansible_warnings


def _canonify_root_arn(arn):
# There are multiple ways to specifiy delegation of access to an account
6 changes: 5 additions & 1 deletion plugins/module_utils/rds.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,9 @@
from time import sleep

try:
from botocore.exceptions import BotoCoreError, ClientError, WaiterError
from botocore.exceptions import BotoCoreError
from botocore.exceptions import ClientError
from botocore.exceptions import WaiterError
except ImportError:
pass

@@ -123,6 +125,8 @@ def get_rds_method_attribute(method_name, module):
waiter = "role_disassociated"
elif method_name == "promote_read_replica":
waiter = "read_replica_promoted"
elif method_name == "db_cluster_promoting":
waiter = "db_cluster_promoting"
else:
waiter = "db_instance_available"
# Handle retry codes
2 changes: 1 addition & 1 deletion plugins/module_utils/transformation.py
Original file line number Diff line number Diff line change
@@ -28,8 +28,8 @@
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from ansible.module_utils.six import string_types
from ansible.module_utils.six import integer_types
from ansible.module_utils.six import string_types


def ansible_dict_to_boto3_filter_list(filters_dict):
1 change: 0 additions & 1 deletion plugins/module_utils/waf.py
Original file line number Diff line number Diff line change
@@ -41,7 +41,6 @@
from .retries import AWSRetry
from .waiters import get_waiter


MATCH_LOOKUP = {
"byte": {
"method": "byte_match_set",
19 changes: 18 additions & 1 deletion plugins/module_utils/waiters.py
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@

from ansible_collections.amazon.aws.plugins.module_utils.retries import RetryingBotoClientWrapper


ec2_data = {
"version": 2,
"waiters": {
@@ -547,6 +546,19 @@
rds_data = {
"version": 2,
"waiters": {
"DBClusterPromoting": {
"delay": 5,
"maxAttempts": 60,
"operation": "DescribeDBClusters",
"acceptors": [
{
"state": "success",
"matcher": "pathAll",
"argument": "DBClusters[].Status",
"expected": "promoting",
},
],
},
"DBInstanceStopped": {
"delay": 20,
"maxAttempts": 60,
@@ -911,6 +923,11 @@ def route53_model(name):
elbv2_model("LoadBalancersDeleted"),
core_waiter.NormalizedOperationMethod(elbv2.describe_load_balancers),
),
("RDS", "db_cluster_promoting"): lambda rds: core_waiter.Waiter(
"db_cluster_promoting",
rds_model("DBClusterPromoting"),
core_waiter.NormalizedOperationMethod(rds.describe_db_clusters),
),
("RDS", "db_instance_stopped"): lambda rds: core_waiter.Waiter(
"db_instance_stopped",
rds_model("DBInstanceStopped"),
8 changes: 4 additions & 4 deletions plugins/modules/autoscaling_group.py
Original file line number Diff line number Diff line change
@@ -660,13 +660,13 @@
pass # Handled by AnsibleAWSModule

from ansible.module_utils._text import to_native
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.transformation import scrub_none_parameters
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import scrub_none_parameters

ASG_ATTRIBUTES = (
"AvailabilityZones",
2 changes: 1 addition & 1 deletion plugins/modules/autoscaling_group_info.py
Original file line number Diff line number Diff line change
@@ -247,8 +247,8 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule


def match_asg_tags(tags_to_match, asg):
3 changes: 2 additions & 1 deletion plugins/modules/aws_az_info.py
Original file line number Diff line number Diff line change
@@ -142,7 +142,8 @@
"""

try:
from botocore.exceptions import ClientError, BotoCoreError
from botocore.exceptions import BotoCoreError
from botocore.exceptions import ClientError
except ImportError:
pass # Handled by AnsibleAWSModule

3 changes: 2 additions & 1 deletion plugins/modules/aws_caller_info.py
Original file line number Diff line number Diff line change
@@ -57,7 +57,8 @@
"""

try:
from botocore.exceptions import BotoCoreError, ClientError
from botocore.exceptions import BotoCoreError
from botocore.exceptions import ClientError
except ImportError:
pass # Handled by AnsibleAWSModule

98 changes: 98 additions & 0 deletions plugins/modules/aws_region_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

DOCUMENTATION = r"""
module: aws_region_info
short_description: Gather information about AWS regions
version_added: 1.0.0
version_added_collection: community.aws
description:
- Gather information about AWS regions.
author:
- 'Henrique Rodrigues (@Sodki)'
options:
filters:
description:
- A dict of filters to apply.
- Each dict item consists of a filter key and a filter value.
- See U(https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeRegions.html) for possible filters.
- Filter names and values are case sensitive.
- You can use underscores instead of dashes (-) in the filter keys.
- Filter keys with underscores will take precedence in case of conflict.
default: {}
type: dict
extends_documentation_fragment:
- amazon.aws.common.modules
- amazon.aws.region.modules
- amazon.aws.boto3
"""

EXAMPLES = r"""
# Note: These examples do not set authentication details, see the AWS Guide for details.
# Gather information about all regions
- amazon.aws.aws_region_info:
# Gather information about a single region
- amazon.aws.aws_region_info:
filters:
region-name: eu-west-1
"""

RETURN = r"""
regions:
returned: on success
description: >
Regions that match the provided filters. Each element consists of a dict with all the information related
to that region.
type: list
sample: "[{
'endpoint': 'ec2.us-west-1.amazonaws.com',
'region_name': 'us-west-1'
}]"
"""

try:
from botocore.exceptions import BotoCoreError
from botocore.exceptions import ClientError
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


def main():
argument_spec = dict(
filters=dict(default={}, type="dict"),
)

module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True)

connection = module.client("ec2", retry_decorator=AWSRetry.jittered_backoff())

# Replace filter key underscores with dashes, for compatibility
sanitized_filters = dict(module.params.get("filters"))
for k in module.params.get("filters").keys():
if "_" in k:
sanitized_filters[k.replace("_", "-")] = sanitized_filters[k]
del sanitized_filters[k]

try:
regions = connection.describe_regions(
aws_retry=True, Filters=ansible_dict_to_boto3_filter_list(sanitized_filters)
)
except (BotoCoreError, ClientError) as e:
module.fail_json_aws(e, msg="Unable to describe regions.")

module.exit_json(regions=[camel_dict_to_snake_dict(r) for r in regions["Regions"]])


if __name__ == "__main__":
main()
4 changes: 3 additions & 1 deletion plugins/modules/backup_plan.py
Original file line number Diff line number Diff line change
@@ -257,13 +257,15 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict

from ansible_collections.amazon.aws.plugins.module_utils.backup import get_plan_details
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.tagging import compare_aws_tags
from ansible_collections.amazon.aws.plugins.module_utils.transformation import scrub_none_parameters

try:
from botocore.exceptions import ClientError, BotoCoreError
from botocore.exceptions import BotoCoreError
from botocore.exceptions import ClientError
except ImportError:
pass # Handled by AnsibleAWSModule

2 changes: 1 addition & 1 deletion plugins/modules/backup_plan_info.py
Original file line number Diff line number Diff line change
@@ -105,9 +105,9 @@
pass # Handled by AnsibleAWSModule


from ansible_collections.amazon.aws.plugins.module_utils.backup import get_plan_details
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.backup import get_plan_details


def get_backup_plan_detail(client, module):
2 changes: 0 additions & 2 deletions plugins/modules/backup_restore_job_info.py
Original file line number Diff line number Diff line change
@@ -214,8 +214,6 @@ def main():

backup_client = module.client("backup")

module.require_botocore_at_least("1.25.13", reason="to list restore jobs info")

request_args = build_request_args(
account_id=module.params["account_id"],
status=module.params["status"],
11 changes: 6 additions & 5 deletions plugins/modules/backup_selection.py
Original file line number Diff line number Diff line change
@@ -223,12 +223,13 @@
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.backup import get_selection_details
from ansible_collections.amazon.aws.plugins.module_utils.backup import get_plan_details
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict

from ansible_collections.amazon.aws.plugins.module_utils.backup import get_plan_details
from ansible_collections.amazon.aws.plugins.module_utils.backup import get_selection_details
from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry


def check_for_update(current_selection, backup_selection_data, iam_role_arn):
5 changes: 3 additions & 2 deletions plugins/modules/backup_selection_info.py
Original file line number Diff line number Diff line change
@@ -111,10 +111,11 @@
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.backup import get_selection_details
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.backup import get_selection_details
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict


def main():
5 changes: 3 additions & 2 deletions plugins/modules/backup_tag.py
Original file line number Diff line number Diff line change
@@ -107,13 +107,14 @@
"""

try:
from botocore.exceptions import ClientError, BotoCoreError
from botocore.exceptions import BotoCoreError
from botocore.exceptions import ClientError
except ImportError:
pass # caught by AnsibleAWSModule

from ansible_collections.amazon.aws.plugins.module_utils.backup import get_backup_resource_tags
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.tagging import compare_aws_tags
from ansible_collections.amazon.aws.plugins.module_utils.backup import get_backup_resource_tags


def manage_tags(module, backup_client):
2 changes: 1 addition & 1 deletion plugins/modules/backup_tag_info.py
Original file line number Diff line number Diff line change
@@ -42,8 +42,8 @@
type: dict
"""

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.backup import get_backup_resource_tags
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule


def main():
10 changes: 6 additions & 4 deletions plugins/modules/backup_vault.py
Original file line number Diff line number Diff line change
@@ -92,14 +92,16 @@
"""


from ansible_collections.amazon.aws.plugins.module_utils.tagging import compare_aws_tags
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.backup import get_backup_resource_tags
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.tagging import compare_aws_tags

try:
from botocore.exceptions import ClientError, BotoCoreError
from botocore.exceptions import BotoCoreError
from botocore.exceptions import ClientError
except ImportError:
pass # Handled by AnsibleAWSModule

2 changes: 1 addition & 1 deletion plugins/modules/backup_vault_info.py
Original file line number Diff line number Diff line change
@@ -103,10 +103,10 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.backup import get_backup_resource_tags
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.backup import get_backup_resource_tags


def get_backup_vaults(connection, module):
4 changes: 2 additions & 2 deletions plugins/modules/cloudformation.py
Original file line number Diff line number Diff line change
@@ -333,11 +333,11 @@
from ansible.module_utils._text import to_bytes
from ansible.module_utils._text import to_native

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import boto_exception
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_message
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.tagging import ansible_dict_to_boto3_tag_list
from ansible_collections.amazon.aws.plugins.module_utils.botocore import boto_exception

# Set a default, mostly for our integration tests. This will be overridden in
# the main() loop to match the parameters we're passed
2 changes: 1 addition & 1 deletion plugins/modules/cloudformation_info.py
Original file line number Diff line number Diff line change
@@ -296,8 +296,8 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_message
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict

3 changes: 2 additions & 1 deletion plugins/modules/cloudtrail.py
Original file line number Diff line number Diff line change
@@ -244,7 +244,8 @@
"""

try:
from botocore.exceptions import ClientError, BotoCoreError
from botocore.exceptions import BotoCoreError
from botocore.exceptions import ClientError
except ImportError:
pass # Handled by AnsibleAWSModule

3 changes: 2 additions & 1 deletion plugins/modules/cloudwatch_metric_alarm.py
Original file line number Diff line number Diff line change
@@ -303,10 +303,11 @@
from botocore.exceptions import ClientError
except ImportError:
pass # protected by AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule


def create_metric_alarm(connection, module, params):
alarms = connection.describe_alarms(AlarmNames=[params["AlarmName"]])
3 changes: 2 additions & 1 deletion plugins/modules/cloudwatch_metric_alarm_info.py
Original file line number Diff line number Diff line change
@@ -227,9 +227,10 @@
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict


@AWSRetry.jittered_backoff(retries=10)
2 changes: 1 addition & 1 deletion plugins/modules/cloudwatchevent_rule.py
Original file line number Diff line number Diff line change
@@ -190,8 +190,8 @@
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.transformation import scrub_none_parameters


2 changes: 1 addition & 1 deletion plugins/modules/cloudwatchlogs_log_group.py
Original file line number Diff line number Diff line change
@@ -134,8 +134,8 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.tagging import compare_aws_tags


2 changes: 1 addition & 1 deletion plugins/modules/cloudwatchlogs_log_group_info.py
Original file line number Diff line number Diff line change
@@ -80,8 +80,8 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule


def describe_log_group(client, log_group_name, module):
14 changes: 5 additions & 9 deletions plugins/modules/ec2_ami.py
Original file line number Diff line number Diff line change
@@ -135,13 +135,13 @@
type: list
elements: str
required: false
version_added: 6.4.0
version_added: 6.5.0
org_unit_arns:
description: List of The Amazon Resource Name(s) (ARN) of an organizational unit(s) (OU).
type: list
elements: str
required: false
version_added: 6.4.0
version_added: 6.5.0
image_location:
description:
- The S3 location of an image to use for the AMI.
@@ -427,11 +427,11 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
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
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import add_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_specifications
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter
@@ -558,10 +558,6 @@ def validate_params(
if not (image_id or name):
module.fail_json("one of the following is required: name, image_id")

if tpm_support or uefi_data:
module.require_botocore_at_least(
"1.26.0", reason="required for ec2.register_image with tpm_support or uefi_data"
)
if tpm_support and boot_mode != "uefi":
module.fail_json("To specify 'tpm_support', 'boot_mode' must be 'uefi'.")

7 changes: 4 additions & 3 deletions plugins/modules/ec2_ami_info.py
Original file line number Diff line number Diff line change
@@ -200,17 +200,18 @@
"""

try:
from botocore.exceptions import ClientError, BotoCoreError
from botocore.exceptions import BotoCoreError
from botocore.exceptions import ClientError
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


class AmiInfoFailure(Exception):
4 changes: 2 additions & 2 deletions plugins/modules/ec2_eip.py
Original file line number Diff line number Diff line change
@@ -221,11 +221,11 @@
except ImportError:
pass # caught by AnsibleAWSModule

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags


class EipError(Exception):
5 changes: 3 additions & 2 deletions plugins/modules/ec2_eip_info.py
Original file line number Diff line number Diff line change
@@ -95,16 +95,17 @@
"""

try:
from botocore.exceptions import BotoCoreError, ClientError
from botocore.exceptions import BotoCoreError
from botocore.exceptions import ClientError
except ImportError:
pass # caught by imported AnsibleAWSModule

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


def get_eips_details(module):
6 changes: 3 additions & 3 deletions plugins/modules/ec2_eni.py
Original file line number Diff line number Diff line change
@@ -282,13 +282,13 @@
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
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
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_ec2_security_group_ids_from_names
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_specifications
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter


4 changes: 2 additions & 2 deletions plugins/modules/ec2_eni_info.py
Original file line number Diff line number Diff line change
@@ -196,11 +196,11 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


def build_request_args(eni_id, filters):
2 changes: 1 addition & 1 deletion plugins/modules/ec2_instance.py
Original file line number Diff line number Diff line change
@@ -960,9 +960,9 @@
sample: vpc-0011223344
"""

from collections import namedtuple
import time
import uuid
from collections import namedtuple

try:
import botocore
2 changes: 1 addition & 1 deletion plugins/modules/ec2_instance_info.py
Original file line number Diff line number Diff line change
@@ -558,8 +558,8 @@

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


@AWSRetry.jittered_backoff()
10 changes: 5 additions & 5 deletions plugins/modules/ec2_key.py
Original file line number Diff line number Diff line change
@@ -161,8 +161,8 @@
version_added: 3.1.0
"""

import uuid
import os
import uuid

try:
import botocore
@@ -171,13 +171,13 @@

from ansible.module_utils._text import to_bytes

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.transformation import scrub_none_parameters
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_specifications
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_specifications
from ansible_collections.amazon.aws.plugins.module_utils.transformation import scrub_none_parameters


class Ec2KeyFailure(Exception):
4 changes: 2 additions & 2 deletions plugins/modules/ec2_key_info.py
Original file line number Diff line number Diff line change
@@ -115,11 +115,11 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


def list_ec2_key_pairs(connection, module):
4 changes: 2 additions & 2 deletions plugins/modules/ec2_metadata_facts.py
Original file line number Diff line number Diff line change
@@ -440,10 +440,10 @@
import time
import zlib

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_text
from ansible.module_utils.urls import fetch_url
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib.parse import quote
from ansible.module_utils.urls import fetch_url

socket.setdefaulttimeout(5)

12 changes: 6 additions & 6 deletions plugins/modules/ec2_security_group.py
Original file line number Diff line number Diff line change
@@ -481,7 +481,8 @@

try:
import botocore
from botocore.exceptions import BotoCoreError, ClientError
from botocore.exceptions import BotoCoreError
from botocore.exceptions import ClientError
except ImportError:
pass # Handled by AnsibleAWSModule

@@ -491,18 +492,17 @@
from ansible.module_utils.common.network import to_subnet
from ansible.module_utils.six import string_types

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.iam import get_aws_account_id
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.tagging import compare_aws_tags
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.iam import get_aws_account_id
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.transformation import scrub_none_parameters
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter


Rule = namedtuple("Rule", ["port_range", "protocol", "target", "target_type", "description"])
TARGET_TYPES_ALL = {"ipv4", "ipv6", "group", "ip_prefix"}
SOURCE_TYPES_ALL = {"cidr_ip", "cidr_ipv6", "group_id", "group_name", "ip_prefix"}
5 changes: 3 additions & 2 deletions plugins/modules/ec2_security_group_info.py
Original file line number Diff line number Diff line change
@@ -248,16 +248,17 @@
"""

try:
from botocore.exceptions import BotoCoreError, ClientError
from botocore.exceptions import BotoCoreError
from botocore.exceptions import ClientError
except ImportError:
pass # caught by AnsibleAWSModule

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


def main():
4 changes: 2 additions & 2 deletions plugins/modules/ec2_snapshot.py
Original file line number Diff line number Diff line change
@@ -211,12 +211,12 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import ansible_dict_to_boto3_tag_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter


7 changes: 4 additions & 3 deletions plugins/modules/ec2_snapshot_info.py
Original file line number Diff line number Diff line change
@@ -210,17 +210,18 @@
"""

try:
from botocore.exceptions import BotoCoreError, ClientError
from botocore.exceptions import BotoCoreError
from botocore.exceptions import ClientError
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


def build_request_args(snapshot_ids, owner_ids, restorable_by_user_ids, filters, max_results, next_token_id):
7 changes: 4 additions & 3 deletions plugins/modules/ec2_spot_instance.py
Original file line number Diff line number Diff line change
@@ -413,13 +413,14 @@
import botocore
except ImportError:
pass # Handled by AnsibleAWSModule
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict

from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible_collections.amazon.aws.plugins.module_utils.tagging import ansible_dict_to_boto3_tag_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code


def build_launch_specification(launch_spec):
3 changes: 2 additions & 1 deletion plugins/modules/ec2_spot_instance_info.py
Original file line number Diff line number Diff line change
@@ -240,9 +240,10 @@
import botocore
except ImportError:
pass # Handled by AnsibleAWSModule
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


4 changes: 2 additions & 2 deletions plugins/modules/ec2_tag.py
Original file line number Diff line number Diff line change
@@ -112,11 +112,11 @@
type: dict
"""

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.tagging import compare_aws_tags
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import remove_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.tagging import compare_aws_tags


def main():
2 changes: 1 addition & 1 deletion plugins/modules/ec2_tag_info.py
Original file line number Diff line number Diff line change
@@ -49,8 +49,8 @@
type: dict
"""

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule


def main():
12 changes: 6 additions & 6 deletions plugins/modules/ec2_vol.py
Original file line number Diff line number Diff line change
@@ -248,17 +248,17 @@

import time

from ansible_collections.amazon.aws.plugins.module_utils.arn import is_outpost_arn
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list

from ansible_collections.amazon.aws.plugins.module_utils.arn import is_outpost_arn
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_specifications

from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list

try:
import botocore
2 changes: 1 addition & 1 deletion plugins/modules/ec2_vol_info.py
Original file line number Diff line number Diff line change
@@ -133,8 +133,8 @@

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


def get_volume_info(volume, region):
11 changes: 6 additions & 5 deletions plugins/modules/ec2_vpc_dhcp_option.py
Original file line number Diff line number Diff line change
@@ -235,15 +235,16 @@
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
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
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import normalize_ec2_vpc_dhcp_config

from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_specifications
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import normalize_ec2_vpc_dhcp_config
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.tagging import ansible_dict_to_boto3_tag_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_specifications


def fetch_dhcp_options_for_vpc(client, module, vpc_id):
4 changes: 2 additions & 2 deletions plugins/modules/ec2_vpc_dhcp_option_info.py
Original file line number Diff line number Diff line change
@@ -156,11 +156,11 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.ec2 import normalize_ec2_vpc_dhcp_config
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import normalize_ec2_vpc_dhcp_config
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


def get_dhcp_options_info(dhcp_option):
10 changes: 5 additions & 5 deletions plugins/modules/ec2_vpc_endpoint.py
Original file line number Diff line number Diff line change
@@ -191,16 +191,16 @@
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible.module_utils.six import string_types
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible.module_utils.six import string_types

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import normalize_boto3_result
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter
from ansible_collections.amazon.aws.plugins.module_utils.botocore import normalize_boto3_result
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_specifications
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter


def get_endpoints(client, module, endpoint_id=None):
2 changes: 1 addition & 1 deletion plugins/modules/ec2_vpc_endpoint_info.py
Original file line number Diff line number Diff line change
@@ -179,9 +179,9 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.botocore import normalize_boto3_result
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list

4 changes: 2 additions & 2 deletions plugins/modules/ec2_vpc_endpoint_service_info.py
Original file line number Diff line number Diff line change
@@ -119,9 +119,9 @@
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


# We're using a paginator so we can't use the client decorators
9 changes: 5 additions & 4 deletions plugins/modules/ec2_vpc_igw.py
Original file line number Diff line number Diff line change
@@ -93,13 +93,14 @@
except ImportError:
pass # caught by AnsibleAWSModule

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter


@AWSRetry.jittered_backoff(retries=10, delay=10)
5 changes: 3 additions & 2 deletions plugins/modules/ec2_vpc_igw_info.py
Original file line number Diff line number Diff line change
@@ -114,12 +114,13 @@
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict


def get_internet_gateway_info(internet_gateway, convert_tags):
9 changes: 5 additions & 4 deletions plugins/modules/ec2_vpc_nat_gateway.py
Original file line number Diff line number Diff line change
@@ -250,14 +250,15 @@
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_specifications
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter


@AWSRetry.jittered_backoff(retries=10)
9 changes: 5 additions & 4 deletions plugins/modules/ec2_vpc_nat_gateway_info.py
Original file line number Diff line number Diff line change
@@ -149,13 +149,14 @@
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict

from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.botocore import normalize_boto3_result
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


@AWSRetry.jittered_backoff(retries=10)
6 changes: 3 additions & 3 deletions plugins/modules/ec2_vpc_net.py
Original file line number Diff line number Diff line change
@@ -207,16 +207,16 @@
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible.module_utils.common.network import to_subnet
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible.module_utils.common.network import to_subnet

from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import ansible_dict_to_boto3_tag_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_specifications
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter


4 changes: 2 additions & 2 deletions plugins/modules/ec2_vpc_net_info.py
Original file line number Diff line number Diff line change
@@ -152,11 +152,11 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


def describe_vpcs(connection, module):
8 changes: 4 additions & 4 deletions plugins/modules/ec2_vpc_route_table.py
Original file line number Diff line number Diff line change
@@ -287,8 +287,8 @@
"""

import re
from time import sleep
from ipaddress import ip_network
from time import sleep

try:
import botocore
@@ -298,12 +298,12 @@
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter


4 changes: 2 additions & 2 deletions plugins/modules/ec2_vpc_route_table_info.py
Original file line number Diff line number Diff line change
@@ -194,11 +194,11 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


@AWSRetry.jittered_backoff()
6 changes: 3 additions & 3 deletions plugins/modules/ec2_vpc_subnet.py
Original file line number Diff line number Diff line change
@@ -215,12 +215,12 @@
from ansible.module_utils._text import to_text
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.arn import is_outpost_arn
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.arn import is_outpost_arn
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter


2 changes: 1 addition & 1 deletion plugins/modules/ec2_vpc_subnet_info.py
Original file line number Diff line number Diff line change
@@ -153,8 +153,8 @@

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


@AWSRetry.exponential_backoff()
19 changes: 9 additions & 10 deletions plugins/modules/elb_application_lb.py
Original file line number Diff line number Diff line change
@@ -526,20 +526,19 @@
except ImportError:
pass # caught by AnsibleAWSModule

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.elb_utils import get_elb_listener_rules
from ansible_collections.amazon.aws.plugins.module_utils.elbv2 import ApplicationLoadBalancer
from ansible_collections.amazon.aws.plugins.module_utils.elbv2 import ELBListener
from ansible_collections.amazon.aws.plugins.module_utils.elbv2 import ELBListenerRule
from ansible_collections.amazon.aws.plugins.module_utils.elbv2 import ELBListenerRules
from ansible_collections.amazon.aws.plugins.module_utils.elbv2 import ELBListeners
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible_collections.amazon.aws.plugins.module_utils.tagging import compare_aws_tags
from ansible_collections.amazon.aws.plugins.module_utils.elbv2 import (
ApplicationLoadBalancer,
ELBListener,
ELBListenerRule,
ELBListenerRules,
ELBListeners,
)
from ansible_collections.amazon.aws.plugins.module_utils.elb_utils import get_elb_listener_rules
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


@AWSRetry.jittered_backoff()
115 changes: 87 additions & 28 deletions plugins/modules/elb_application_lb_info.py
Original file line number Diff line number Diff line change
@@ -27,6 +27,28 @@
required: false
type: list
elements: str
include_attributes:
description:
- Whether or not to include load balancer attributes in the response.
required: false
type: bool
default: true
version_added: 7.0.0
include_listeners:
description:
- Whether or not to include load balancer listeners in the response.
required: false
type: bool
default: true
version_added: 7.0.0
include_listener_rules:
description:
- Whether or not to include load balancer listener rules in the response.
- Implies I(include_listeners=true)
required: false
type: bool
default: true
version_added: 7.0.0

extends_documentation_fragment:
- amazon.aws.common.modules
@@ -40,6 +62,13 @@
- name: Gather information about all ALBs
amazon.aws.elb_application_lb_info:

# Equivalent to aws elbv2 describe-load-balancers
- name: Gather minimal information about all ALBs
amazon.aws.elb_application_lb_info:
include_attributes: false
include_listeners: false
include_listener_rules: false

- name: Gather information about a particular ALB given its ARN
amazon.aws.elb_application_lb_info:
load_balancer_arns:
@@ -68,14 +97,17 @@
contains:
access_logs_s3_bucket:
description: The name of the S3 bucket for the access logs.
returned: when include_attributes is true
type: str
sample: "mys3bucket"
access_logs_s3_enabled:
description: Indicates whether access logs stored in Amazon S3 are enabled.
returned: when include_attributes is true
type: bool
sample: true
access_logs_s3_prefix:
description: The prefix for the location in the S3 bucket.
returned: when include_attributes is true
type: str
sample: "my/logs"
availability_zones:
@@ -92,6 +124,7 @@
sample: "2015-02-12T02:14:02+00:00"
deletion_protection_enabled:
description: Indicates whether deletion protection is enabled.
returned: when include_attributes is true
type: bool
sample: true
dns_name:
@@ -100,6 +133,7 @@
sample: "internal-my-alb-123456789.ap-southeast-2.elb.amazonaws.com"
idle_timeout_timeout_seconds:
description: The idle timeout value, in seconds.
returned: when include_attributes is true
type: int
sample: 60
ip_address_type:
@@ -108,6 +142,7 @@
sample: "ipv4"
listeners:
description: Information about the listeners.
returned: when include_listeners or include_listener_rules is true
type: complex
contains:
listener_arn:
@@ -126,6 +161,11 @@
description: The protocol for connections from clients to the load balancer.
type: str
sample: "HTTPS"
rules:
description: List of listener rules.
returned: when include_listener_rules is true
type: list
sample: ""
certificates:
description: The SSL server certificate.
type: complex
@@ -158,24 +198,34 @@
description: The name of the load balancer.
type: str
sample: "my-alb"
load_balancing_cross_zone_enabled:
description: Indicates whether or not cross-zone load balancing is enabled.
returned: when include_attributes is true
type: bool
sample: true
routing_http2_enabled:
description: Indicates whether HTTP/2 is enabled.
returned: when include_attributes is true
type: bool
sample: true
routing_http_desync_mitigation_mode:
description: Determines how the load balancer handles requests that might pose a security risk to an application.
returned: when include_attributes is true
type: str
sample: "defensive"
routing_http_drop_invalid_header_fields_enabled:
description: Indicates whether HTTP headers with invalid header fields are removed by the load balancer (true) or routed to targets (false).
returned: when include_attributes is true
type: bool
sample: false
routing_http_x_amzn_tls_version_and_cipher_suite_enabled:
description: Indicates whether the two headers are added to the client request before sending it to the target.
returned: when include_attributes is true
type: bool
sample: false
routing_http_xff_client_port_enabled:
description: Indicates whether the X-Forwarded-For header should preserve the source port that the client used to connect to the load balancer.
returned: when include_attributes is true
type: bool
sample: false
scheme:
@@ -207,6 +257,7 @@
waf_fail_open_enabled:
description: Indicates whether to allow a AWS WAF-enabled load balancer to route requests to targets
if it is unable to forward the request to AWS WAF.
returned: when include_attributes is true
type: bool
sample: false
"""
@@ -218,8 +269,8 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict

@@ -232,23 +283,31 @@ def get_paginator(connection, **kwargs):

def get_alb_listeners(connection, module, alb_arn):
try:
return connection.describe_listeners(LoadBalancerArn=alb_arn)["Listeners"]
return connection.describe_listeners(
aws_retry=True,
LoadBalancerArn=alb_arn,
)["Listeners"]
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Failed to describe alb listeners")


def get_listener_rules(connection, module, listener_arn):
try:
return connection.describe_rules(ListenerArn=listener_arn)["Rules"]
return connection.describe_rules(
aws_retry=True,
ListenerArn=listener_arn,
)["Rules"]
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Failed to describe listener rules")


def get_load_balancer_attributes(connection, module, load_balancer_arn):
try:
load_balancer_attributes = boto3_tag_list_to_ansible_dict(
connection.describe_load_balancer_attributes(LoadBalancerArn=load_balancer_arn)["Attributes"]
)
attributes = connection.describe_load_balancer_attributes(
aws_retry=True,
LoadBalancerArn=load_balancer_arn,
)["Attributes"]
load_balancer_attributes = boto3_tag_list_to_ansible_dict(attributes)
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Failed to describe load balancer attributes")

@@ -262,25 +321,21 @@ def get_load_balancer_attributes(connection, module, load_balancer_arn):

def get_load_balancer_tags(connection, module, load_balancer_arn):
try:
return boto3_tag_list_to_ansible_dict(
connection.describe_tags(ResourceArns=[load_balancer_arn])["TagDescriptions"][0]["Tags"]
)
tag_descriptions = connection.describe_tags(
aws_retry=True,
ResourceArns=[load_balancer_arn],
)["TagDescriptions"]
return boto3_tag_list_to_ansible_dict(tag_descriptions[0]["Tags"])
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Failed to describe load balancer tags")


def get_load_balancer_ipaddresstype(connection, module, load_balancer_arn):
try:
return connection.describe_load_balancers(LoadBalancerArns=[load_balancer_arn])["LoadBalancers"][0][
"IpAddressType"
]
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Failed to describe load balancer ip address type")


def list_load_balancers(connection, module):
load_balancer_arns = module.params.get("load_balancer_arns")
names = module.params.get("names")
include_attributes = module.params.get("include_attributes")
include_listeners = module.params.get("include_listeners")
include_listener_rules = module.params.get("include_listener_rules")

try:
if not load_balancer_arns and not names:
@@ -299,19 +354,17 @@ def list_load_balancers(connection, module):

for load_balancer in load_balancers["LoadBalancers"]:
# Get the attributes for each alb
load_balancer.update(get_load_balancer_attributes(connection, module, load_balancer["LoadBalancerArn"]))
if include_attributes:
load_balancer.update(get_load_balancer_attributes(connection, module, load_balancer["LoadBalancerArn"]))

# Get the listeners for each alb
load_balancer["listeners"] = get_alb_listeners(connection, module, load_balancer["LoadBalancerArn"])
if include_listeners or include_listener_rules:
load_balancer["listeners"] = get_alb_listeners(connection, module, load_balancer["LoadBalancerArn"])

# For each listener, get listener rules
for listener in load_balancer["listeners"]:
listener["rules"] = get_listener_rules(connection, module, listener["ListenerArn"])

# Get ALB ip address type
load_balancer["IpAddressType"] = get_load_balancer_ipaddresstype(
connection, module, load_balancer["LoadBalancerArn"]
)
if include_listener_rules:
for listener in load_balancer["listeners"]:
listener["rules"] = get_listener_rules(connection, module, listener["ListenerArn"])

# Turn the boto3 result in to ansible_friendly_snaked_names
snaked_load_balancers = [
@@ -328,7 +381,13 @@ def list_load_balancers(connection, module):


def main():
argument_spec = dict(load_balancer_arns=dict(type="list", elements="str"), names=dict(type="list", elements="str"))
argument_spec = dict(
load_balancer_arns=dict(type="list", elements="str"),
names=dict(type="list", elements="str"),
include_attributes=dict(default=True, type="bool"),
include_listeners=dict(default=True, type="bool"),
include_listener_rules=dict(default=True, type="bool"),
)

module = AnsibleAWSModule(
argument_spec=argument_spec,
14 changes: 7 additions & 7 deletions plugins/modules/elb_classic_lb.py
Original file line number Diff line number Diff line change
@@ -675,18 +675,18 @@
except ImportError:
pass # Taken care of by AnsibleAWSModule

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict

from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.transformation import scrub_none_parameters
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_ec2_security_group_ids_from_names
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import ansible_dict_to_boto3_tag_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible_collections.amazon.aws.plugins.module_utils.tagging import compare_aws_tags
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict

from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_ec2_security_group_ids_from_names
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.transformation import scrub_none_parameters
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter


314 changes: 314 additions & 0 deletions plugins/modules/iam_access_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,314 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (c) 2021 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

DOCUMENTATION = r"""
---
module: iam_access_key
version_added: 2.1.0
version_added_collection: community.aws
short_description: Manage AWS IAM User access keys
description:
- Manage AWS IAM user access keys.
author:
- Mark Chappell (@tremble)
options:
user_name:
description:
- The name of the IAM User to which the key belongs.
required: true
type: str
aliases: ['username']
id:
description:
- The ID of the access key.
- Required when I(state=absent).
- Mutually exclusive with I(rotate_keys).
required: false
type: str
state:
description:
- Create or remove the access key.
- When I(state=present) and I(id) is not defined a new key will be created.
required: false
type: str
default: 'present'
choices: [ 'present', 'absent' ]
active:
description:
- Whether the key should be enabled or disabled.
- Defaults to C(true) when creating a new key.
required: false
type: bool
aliases: ['enabled']
rotate_keys:
description:
- When there are already 2 access keys attached to the IAM user the oldest
key will be removed and a new key created.
- Ignored if I(state=absent)
- Mutually exclusive with I(id).
required: false
type: bool
default: false
notes:
- For security reasons, this module should be used with B(no_log=true) and (register) functionalities
when creating new access key.
extends_documentation_fragment:
- amazon.aws.common.modules
- amazon.aws.region.modules
- amazon.aws.boto3
"""

EXAMPLES = r"""
# Note: These examples do not set authentication details, see the AWS Guide for details.

- name: Create a new access key
amazon.aws.iam_access_key:
user_name: example_user
state: present
no_log: true

- name: Delete the access_key
amazon.aws.iam_access_key:
user_name: example_user
id: AKIA1EXAMPLE1EXAMPLE
state: absent
"""

RETURN = r"""
access_key:
description: A dictionary containing all the access key information.
returned: When the key exists.
type: complex
contains:
access_key_id:
description: The ID for the access key.
returned: success
type: str
sample: AKIA1EXAMPLE1EXAMPLE
create_date:
description: The date and time, in ISO 8601 date-time format, when the access key was created.
returned: success
type: str
sample: "2021-10-09T13:25:42+00:00"
user_name:
description: The name of the IAM user to which the key is attached.
returned: success
type: str
sample: example_user
status:
description:
- The status of the key.
- C(Active) means it can be used.
- C(Inactive) means it can not be used.
returned: success
type: str
sample: Inactive
secret_access_key:
description:
- The secret access key.
- A secret access key is the equivalent of a password which can not be changed and as such should be considered sensitive data.
- Secret access keys can only be accessed at creation time.
returned: When a new key is created.
type: str
sample: example/Example+EXAMPLE+example/Example
deleted_access_key_id:
description:
- The access key deleted during rotation.
returned: When a key was deleted during the rotation of access keys
type: str
sample: AKIA1EXAMPLE1EXAMPLE
"""

try:
import botocore
except ImportError:
pass # caught by AnsibleAWSModule

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.botocore import normalize_boto3_result
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import scrub_none_parameters


def delete_access_key(access_keys, user, access_key_id):
if not access_key_id:
return False

if access_key_id not in access_keys:
return False

if module.check_mode:
return True

try:
client.delete_access_key(
aws_retry=True,
UserName=user,
AccessKeyId=access_key_id,
)
except is_boto3_error_code("NoSuchEntityException"):
# Generally occurs when race conditions have happened and someone
# deleted the key while we were checking to see if it existed.
return False
except (
botocore.exceptions.ClientError,
botocore.exceptions.BotoCoreError,
) as e: # pylint: disable=duplicate-except
module.fail_json_aws(e, msg=f'Failed to delete access key "{access_key_id}" for user "{user}"')

return True


def update_access_key(access_keys, user, access_key_id, enabled):
if access_key_id not in access_keys:
module.fail_json(
msg=f'Access key "{access_key_id}" not found attached to User "{user}"',
)

changes = dict()
access_key = access_keys.get(access_key_id)

if enabled is not None:
desired_status = "Active" if enabled else "Inactive"
if access_key.get("status") != desired_status:
changes["Status"] = desired_status

if not changes:
return False

if module.check_mode:
return True

try:
client.update_access_key(aws_retry=True, UserName=user, AccessKeyId=access_key_id, **changes)
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(
e,
changes=changes,
msg=f'Failed to update access key "{access_key_id}" for user "{user}"',
)
return True


def create_access_key(access_keys, user, rotate_keys, enabled):
changed = False
oldest_key = False

if len(access_keys) > 1 and rotate_keys:
sorted_keys = sorted(list(access_keys), key=lambda k: access_keys[k].get("create_date", None))
oldest_key = sorted_keys[0]
changed |= delete_access_key(access_keys, user, oldest_key)

if module.check_mode:
if changed:
return dict(deleted_access_key=oldest_key)
return True

try:
results = client.create_access_key(aws_retry=True, UserName=user)
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg=f'Failed to create access key for user "{user}"')
results = camel_dict_to_snake_dict(results)
access_key = results.get("access_key")
access_key = normalize_boto3_result(access_key)

# Update settings which can't be managed on creation
if enabled is False:
access_key_id = access_key["access_key_id"]
access_keys = {access_key_id: access_key}
update_access_key(access_keys, user, access_key_id, enabled)
access_key["status"] = "Inactive"

if oldest_key:
access_key["deleted_access_key"] = oldest_key

return access_key


def get_access_keys(user):
try:
results = client.list_access_keys(aws_retry=True, UserName=user)
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg=f'Failed to get access keys for user "{user}"')
if not results:
return None

results = camel_dict_to_snake_dict(results)
access_keys = results.get("access_key_metadata", [])
if not access_keys:
return []

access_keys = normalize_boto3_result(access_keys)
access_keys = {k["access_key_id"]: k for k in access_keys}
return access_keys


def main():
global module
global client

argument_spec = dict(
user_name=dict(required=True, type="str", aliases=["username"]),
id=dict(required=False, type="str"),
state=dict(required=False, choices=["present", "absent"], default="present"),
active=dict(required=False, type="bool", aliases=["enabled"]),
rotate_keys=dict(required=False, type="bool", default=False),
)

required_if = [
["state", "absent", ("id",)],
]
mutually_exclusive = [
["rotate_keys", "id"],
]

module = AnsibleAWSModule(
argument_spec=argument_spec,
supports_check_mode=True,
)

client = module.client("iam", retry_decorator=AWSRetry.jittered_backoff())

changed = False
state = module.params.get("state")
user = module.params.get("user_name")
access_key_id = module.params.get("id")
rotate_keys = module.params.get("rotate_keys")
enabled = module.params.get("active")

access_keys = get_access_keys(user)
results = dict()

if state == "absent":
changed |= delete_access_key(access_keys, user, access_key_id)
else:
# If we have an ID then we should try to update it
if access_key_id:
changed |= update_access_key(access_keys, user, access_key_id, enabled)
access_keys = get_access_keys(user)
results["access_key"] = access_keys.get(access_key_id, None)
# Otherwise we try to create a new one
else:
secret_key = create_access_key(access_keys, user, rotate_keys, enabled)
if isinstance(secret_key, bool):
changed |= secret_key
else:
changed = True
results["access_key_id"] = secret_key.get("access_key_id", None)
results["secret_access_key"] = secret_key.pop("secret_access_key", None)
results["deleted_access_key_id"] = secret_key.pop("deleted_access_key", None)
if secret_key:
results["access_key"] = secret_key
results = scrub_none_parameters(results)

module.exit_json(changed=changed, **results)


if __name__ == "__main__":
main()
122 changes: 122 additions & 0 deletions plugins/modules/iam_access_key_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (c) 2021 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

DOCUMENTATION = r"""
---
module: iam_access_key_info
version_added: 2.1.0
version_added_collection: community.aws
short_description: fetch information about AWS IAM User access keys
description:
- 'Fetches information AWS IAM user access keys.'
- 'Note: It is not possible to fetch the secret access key.'
author:
- Mark Chappell (@tremble)
options:
user_name:
description:
- The name of the IAM User to which the keys belong.
required: true
type: str
aliases: ['username']

extends_documentation_fragment:
- amazon.aws.common.modules
- amazon.aws.region.modules
- amazon.aws.boto3
"""

EXAMPLES = r"""
# Note: These examples do not set authentication details, see the AWS Guide for details.

- name: Fetch Access keys for a user
amazon.aws.iam_access_key_info:
user_name: example_user
"""

RETURN = r"""
access_key:
description: A dictionary containing all the access key information.
returned: When the key exists.
type: list
elements: dict
contains:
access_key_id:
description: The ID for the access key.
returned: success
type: str
sample: AKIA1EXAMPLE1EXAMPLE
create_date:
description: The date and time, in ISO 8601 date-time format, when the access key was created.
returned: success
type: str
sample: "2021-10-09T13:25:42+00:00"
user_name:
description: The name of the IAM user to which the key is attached.
returned: success
type: str
sample: example_user
status:
description:
- The status of the key.
- C(Active) means it can be used.
- C(Inactive) means it can not be used.
returned: success
type: str
sample: Inactive
"""

try:
import botocore
except ImportError:
pass # caught by AnsibleAWSModule

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ansible_collections.amazon.aws.plugins.module_utils.botocore import normalize_boto3_result
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry


def get_access_keys(user):
try:
results = client.list_access_keys(aws_retry=True, UserName=user)
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg=f'Failed to get access keys for user "{user}"')
if not results:
return None

results = camel_dict_to_snake_dict(results)
access_keys = results.get("access_key_metadata", [])
if not access_keys:
return []

access_keys = normalize_boto3_result(access_keys)
access_keys = sorted(access_keys, key=lambda d: d.get("create_date", None))
return access_keys


def main():
global module
global client

argument_spec = dict(
user_name=dict(required=True, type="str", aliases=["username"]),
)

module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True)

client = module.client("iam", retry_decorator=AWSRetry.jittered_backoff())

changed = False
user = module.params.get("user_name")
access_keys = get_access_keys(user)

module.exit_json(changed=changed, access_keys=access_keys)


if __name__ == "__main__":
main()
Loading

0 comments on commit f66be46

Please sign in to comment.