From 67936e07af3768df4ce87e920843617a8d1f88e0 Mon Sep 17 00:00:00 2001 From: jillr Date: Mon, 2 Mar 2020 19:25:18 +0000 Subject: [PATCH 01/18] Initial commit This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/eb75681585a23ea79e642b86a0f8e64e0f40a6d7 --- plugins/modules/rds_subnet_group.py | 202 ++++++++++++++++ .../targets/rds_subnet_group/aliases | 2 + .../rds_subnet_group/defaults/main.yml | 8 + .../targets/rds_subnet_group/meta/main.yml | 3 + .../targets/rds_subnet_group/tasks/main.yml | 113 +++++++++ .../targets/rds_subnet_group/tasks/params.yml | 62 +++++ .../targets/rds_subnet_group/tasks/tests.yml | 221 ++++++++++++++++++ 7 files changed, 611 insertions(+) create mode 100644 plugins/modules/rds_subnet_group.py create mode 100644 tests/integration/targets/rds_subnet_group/aliases create mode 100644 tests/integration/targets/rds_subnet_group/defaults/main.yml create mode 100644 tests/integration/targets/rds_subnet_group/meta/main.yml create mode 100644 tests/integration/targets/rds_subnet_group/tasks/main.yml create mode 100644 tests/integration/targets/rds_subnet_group/tasks/params.yml create mode 100644 tests/integration/targets/rds_subnet_group/tasks/tests.yml diff --git a/plugins/modules/rds_subnet_group.py b/plugins/modules/rds_subnet_group.py new file mode 100644 index 00000000000..1bba28dfbce --- /dev/null +++ b/plugins/modules/rds_subnet_group.py @@ -0,0 +1,202 @@ +#!/usr/bin/python +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['stableinterface'], + 'supported_by': 'community'} + + +DOCUMENTATION = ''' +--- +module: rds_subnet_group +short_description: manage RDS database subnet groups +description: + - Creates, modifies, and deletes RDS database subnet groups. This module has a dependency on python-boto >= 2.5. +options: + state: + description: + - Specifies whether the subnet should be present or absent. + required: true + choices: [ 'present' , 'absent' ] + type: str + name: + description: + - Database subnet group identifier. + required: true + type: str + description: + description: + - Database subnet group description. + - Required when I(state=present). + type: str + subnets: + description: + - List of subnet IDs that make up the database subnet group. + - Required when I(state=present). + type: list +author: "Scott Anderson (@tastychutney)" +extends_documentation_fragment: +- ansible.amazon.aws +- ansible.amazon.ec2 + +''' + +EXAMPLES = ''' +# Add or change a subnet group +- rds_subnet_group: + state: present + name: norwegian-blue + description: My Fancy Ex Parrot Subnet Group + subnets: + - subnet-aaaaaaaa + - subnet-bbbbbbbb + +# Remove a subnet group +- rds_subnet_group: + state: absent + name: norwegian-blue +''' + +RETURN = ''' +subnet_group: + description: Dictionary of DB subnet group values + returned: I(state=present) + type: complex + contains: + name: + description: The name of the DB subnet group + returned: I(state=present) + type: str + description: + description: The description of the DB subnet group + returned: I(state=present) + type: str + vpc_id: + description: The VpcId of the DB subnet group + returned: I(state=present) + type: str + subnet_ids: + description: Contains a list of Subnet IDs + returned: I(state=present) + type: list + status: + description: The status of the DB subnet group + returned: I(state=present) + type: str +''' + +try: + import boto.rds + from boto.exception import BotoServerError + HAS_BOTO = True +except ImportError: + HAS_BOTO = False + +from ansible.module_utils.basic import AnsibleModule +from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import HAS_BOTO, connect_to_aws, ec2_argument_spec, get_aws_connection_info + + +def get_subnet_group_info(subnet_group): + return dict( + name=subnet_group.name, + description=subnet_group.description, + vpc_id=subnet_group.vpc_id, + subnet_ids=subnet_group.subnet_ids, + status=subnet_group.status + ) + + +def create_result(changed, subnet_group=None): + if subnet_group is None: + return dict( + changed=changed + ) + else: + return dict( + changed=changed, + subnet_group=get_subnet_group_info(subnet_group) + ) + + +def main(): + argument_spec = ec2_argument_spec() + argument_spec.update(dict( + state=dict(required=True, choices=['present', 'absent']), + name=dict(required=True), + description=dict(required=False), + subnets=dict(required=False, type='list'), + ) + ) + module = AnsibleModule(argument_spec=argument_spec) + + if not HAS_BOTO: + module.fail_json(msg='boto required for this module') + + state = module.params.get('state') + group_name = module.params.get('name').lower() + group_description = module.params.get('description') + group_subnets = module.params.get('subnets') or {} + + if state == 'present': + for required in ['description', 'subnets']: + if not module.params.get(required): + module.fail_json(msg=str("Parameter %s required for state='present'" % required)) + else: + for not_allowed in ['description', 'subnets']: + if module.params.get(not_allowed): + module.fail_json(msg=str("Parameter %s not allowed for state='absent'" % not_allowed)) + + # Retrieve any AWS settings from the environment. + region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module) + + if not region: + module.fail_json(msg=str("Either region or AWS_REGION or EC2_REGION environment variable or boto config aws_region or ec2_region must be set.")) + + try: + conn = connect_to_aws(boto.rds, region, **aws_connect_kwargs) + except BotoServerError as e: + module.fail_json(msg=e.error_message) + + try: + exists = False + result = create_result(False) + + try: + matching_groups = conn.get_all_db_subnet_groups(group_name, max_records=100) + exists = len(matching_groups) > 0 + except BotoServerError as e: + if e.error_code != 'DBSubnetGroupNotFoundFault': + module.fail_json(msg=e.error_message) + + if state == 'absent': + if exists: + conn.delete_db_subnet_group(group_name) + result = create_result(True) + else: + if not exists: + new_group = conn.create_db_subnet_group(group_name, desc=group_description, subnet_ids=group_subnets) + result = create_result(True, new_group) + else: + # Sort the subnet groups before we compare them + matching_groups[0].subnet_ids.sort() + group_subnets.sort() + if (matching_groups[0].name != group_name or + matching_groups[0].description != group_description or + matching_groups[0].subnet_ids != group_subnets): + changed_group = conn.modify_db_subnet_group(group_name, description=group_description, subnet_ids=group_subnets) + result = create_result(True, changed_group) + else: + result = create_result(False, matching_groups[0]) + except BotoServerError as e: + module.fail_json(msg=e.error_message) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/tests/integration/targets/rds_subnet_group/aliases b/tests/integration/targets/rds_subnet_group/aliases new file mode 100644 index 00000000000..6e3860bee23 --- /dev/null +++ b/tests/integration/targets/rds_subnet_group/aliases @@ -0,0 +1,2 @@ +cloud/aws +shippable/aws/group2 diff --git a/tests/integration/targets/rds_subnet_group/defaults/main.yml b/tests/integration/targets/rds_subnet_group/defaults/main.yml new file mode 100644 index 00000000000..07e0fe93f8e --- /dev/null +++ b/tests/integration/targets/rds_subnet_group/defaults/main.yml @@ -0,0 +1,8 @@ +vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/16' +subnet_a: '10.{{ 256 | random(seed=resource_prefix) }}.10.0/24' +subnet_b: '10.{{ 256 | random(seed=resource_prefix) }}.11.0/24' +subnet_c: '10.{{ 256 | random(seed=resource_prefix) }}.12.0/24' +subnet_d: '10.{{ 256 | random(seed=resource_prefix) }}.13.0/24' + +group_description: 'Created by integration test : {{ resource_prefix }}' +group_description_changed: 'Created by integration test : {{ resource_prefix }} - changed' diff --git a/tests/integration/targets/rds_subnet_group/meta/main.yml b/tests/integration/targets/rds_subnet_group/meta/main.yml new file mode 100644 index 00000000000..9d91be1705b --- /dev/null +++ b/tests/integration/targets/rds_subnet_group/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: +- prepare_tests +- setup_ec2 diff --git a/tests/integration/targets/rds_subnet_group/tasks/main.yml b/tests/integration/targets/rds_subnet_group/tasks/main.yml new file mode 100644 index 00000000000..44184e302db --- /dev/null +++ b/tests/integration/targets/rds_subnet_group/tasks/main.yml @@ -0,0 +1,113 @@ +--- +# Tests for rds_subnet_group +# +# Note: (From Amazon's documentation) +# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rds.html#RDS.Client.modify_db_subnet_group +# DB subnet groups must contain at least one subnet in at least two AZs in the +# AWS Region. + +- module_defaults: + group/aws: + aws_access_key: '{{ aws_access_key }}' + aws_secret_key: '{{ aws_secret_key }}' + security_token: '{{ security_token | default(omit) }}' + region: '{{ aws_region }}' + block: + + # ============================================================ + + - name: 'Fetch AZ availability' + aws_az_info: + register: az_info + + - name: 'Assert that we have multiple AZs available to us' + assert: + that: az_info.availability_zones | length >= 2 + + - name: 'Pick AZs' + set_fact: + az_one: '{{ az_info.availability_zones[0].zone_name }}' + az_two: '{{ az_info.availability_zones[1].zone_name }}' + + # ============================================================ + + - name: 'Create a VPC' + ec2_vpc_net: + state: present + cidr_block: '{{ vpc_cidr }}' + name: '{{ resource_prefix }}' + register: vpc + + - name: 'Create subnets' + ec2_vpc_subnet: + state: present + cidr: '{{ item.cidr }}' + az: '{{ item.az }}' + vpc_id: '{{ vpc.vpc.id }}' + tags: + Name: '{{ item.name }}' + with_items: + - cidr: '{{ subnet_a }}' + az: '{{ az_one }}' + name: '{{ resource_prefix }}-subnet-a' + - cidr: '{{ subnet_b }}' + az: '{{ az_two }}' + name: '{{ resource_prefix }}-subnet-b' + - cidr: '{{ subnet_c }}' + az: '{{ az_one }}' + name: '{{ resource_prefix }}-subnet-c' + - cidr: '{{ subnet_d }}' + az: '{{ az_two }}' + name: '{{ resource_prefix }}-subnet-d' + register: subnets + + - set_fact: + subnet_ids: '{{ subnets | json_query("results[].subnet.id") | list }}' + + # ============================================================ + + - include_tasks: 'params.yml' + + - include_tasks: 'tests.yml' + + # ============================================================ + + always: + - name: 'Remove subnet group' + rds_subnet_group: + state: absent + name: '{{ resource_prefix }}' + ignore_errors: yes + + - name: 'Remove subnets' + ec2_vpc_subnet: + state: absent + cidr: '{{ item.cidr }}' + vpc_id: '{{ vpc.vpc.id }}' + with_items: + - cidr: '{{ subnet_a }}' + name: '{{ resource_prefix }}-subnet-a' + - cidr: '{{ subnet_b }}' + name: '{{ resource_prefix }}-subnet-b' + - cidr: '{{ subnet_c }}' + name: '{{ resource_prefix }}-subnet-c' + - cidr: '{{ subnet_d }}' + name: '{{ resource_prefix }}-subnet-d' + ignore_errors: yes + register: removed_subnets + until: removed_subnets is succeeded + retries: 5 + delay: 5 + + - name: 'Remove the VPC' + ec2_vpc_net: + state: absent + cidr_block: '{{ vpc_cidr }}' + name: '{{ resource_prefix }}' + ignore_errors: yes + register: removed_vpc + until: removed_vpc is success + retries: 5 + delay: 5 + + # ============================================================ diff --git a/tests/integration/targets/rds_subnet_group/tasks/params.yml b/tests/integration/targets/rds_subnet_group/tasks/params.yml new file mode 100644 index 00000000000..74da381ff7a --- /dev/null +++ b/tests/integration/targets/rds_subnet_group/tasks/params.yml @@ -0,0 +1,62 @@ +--- +# Try creating without a description +- name: 'Create a subnet group (no description)' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + ignore_errors: yes + register: create_missing_param +- assert: + that: + - create_missing_param is failed + - "'description' in create_missing_param.msg" + - "\"required for state='present'\" in create_missing_param.msg" + +# Try creating without subnets +- name: 'Create a subnet group (no subnets)' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description }}' + ignore_errors: yes + register: create_missing_param +- assert: + that: + - create_missing_param is failed + - "'subnets' in create_missing_param.msg" + - "\"required for state='present'\" in create_missing_param.msg" + +# XXX This feels like a bad pattern +# Try deleting with subnets +- name: 'Delete a subnet group (with subnets)' + rds_subnet_group: + state: absent + name: '{{ resource_prefix }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + ignore_errors: yes + register: delete_extra_param +- assert: + that: + - delete_extra_param is failed + - "'subnets' in delete_extra_param.msg" + - "\"not allowed for state='absent'\" in delete_extra_param.msg" + +# XXX This feels like a bad pattern +# Try deleting with a description +- name: 'Create a subnet group (with description)' + rds_subnet_group: + state: absent + name: '{{ resource_prefix }}' + description: '{{ group_description }}' + ignore_errors: yes + register: delete_extra_param +- assert: + that: + - delete_extra_param is failed + - "'description' in delete_extra_param.msg" + - "\"not allowed for state='absent'\" in delete_extra_param.msg" diff --git a/tests/integration/targets/rds_subnet_group/tasks/tests.yml b/tests/integration/targets/rds_subnet_group/tasks/tests.yml new file mode 100644 index 00000000000..0b4e3d1b52a --- /dev/null +++ b/tests/integration/targets/rds_subnet_group/tasks/tests.yml @@ -0,0 +1,221 @@ +--- +# XXX rds_subnet_group doesn't support check_mode yet + +# ============================================================ +# Basic creation +- name: 'Create a subnet group' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + register: result + +- assert: + that: + - result is changed + - result.subnet_group.description == group_description + - result.subnet_group.name == resource_prefix + - result.subnet_group.vpc_id == vpc.vpc.id + - result.subnet_group.subnet_ids | length == 2 + - subnet_ids[0] in result.subnet_group.subnet_ids + - subnet_ids[1] in result.subnet_group.subnet_ids + +- name: 'Create a subnet group (idempotency)' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + register: result + +- assert: + that: + - result is not changed + - result.subnet_group.description == group_description + - result.subnet_group.name == resource_prefix + - result.subnet_group.vpc_id == vpc.vpc.id + - result.subnet_group.subnet_ids | length == 2 + - subnet_ids[0] in result.subnet_group.subnet_ids + - subnet_ids[1] in result.subnet_group.subnet_ids + +# ============================================================ +# Update description + +- name: 'Update subnet group description' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description_changed }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + register: result + +- assert: + that: + - result is changed + - result.subnet_group.description == group_description_changed + - result.subnet_group.name == resource_prefix + - result.subnet_group.vpc_id == vpc.vpc.id + - result.subnet_group.subnet_ids | length == 2 + - subnet_ids[0] in result.subnet_group.subnet_ids + - subnet_ids[1] in result.subnet_group.subnet_ids + +- name: 'Update subnet group description (idempotency)' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description_changed }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + register: result + +- assert: + that: + - result is not changed + - result.subnet_group.description == group_description_changed + - result.subnet_group.name == resource_prefix + - result.subnet_group.vpc_id == vpc.vpc.id + - result.subnet_group.subnet_ids | length == 2 + - subnet_ids[0] in result.subnet_group.subnet_ids + - subnet_ids[1] in result.subnet_group.subnet_ids + +- name: 'Restore subnet group description' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + register: result + +- assert: + that: + - result is changed + - result.subnet_group.description == group_description + - result.subnet_group.name == resource_prefix + - result.subnet_group.vpc_id == vpc.vpc.id + - result.subnet_group.subnet_ids | length == 2 + - subnet_ids[0] in result.subnet_group.subnet_ids + - subnet_ids[1] in result.subnet_group.subnet_ids + +# ============================================================ +# Update subnets + +- name: 'Update subnet group list' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description }}' + subnets: + - '{{ subnet_ids[2] }}' + - '{{ subnet_ids[3] }}' + register: result + +- assert: + that: + - result is changed + - result.subnet_group.description == group_description + - result.subnet_group.name == resource_prefix + - result.subnet_group.vpc_id == vpc.vpc.id + - result.subnet_group.subnet_ids | length == 2 + - subnet_ids[2] in result.subnet_group.subnet_ids + - subnet_ids[3] in result.subnet_group.subnet_ids + +- name: 'Update subnet group list (idempotency)' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description }}' + subnets: + - '{{ subnet_ids[2] }}' + - '{{ subnet_ids[3] }}' + register: result + +- assert: + that: + - result is not changed + - result.subnet_group.description == group_description + - result.subnet_group.name == resource_prefix + - result.subnet_group.vpc_id == vpc.vpc.id + - result.subnet_group.subnet_ids | length == 2 + - subnet_ids[2] in result.subnet_group.subnet_ids + - subnet_ids[3] in result.subnet_group.subnet_ids + +- name: 'Add more subnets subnet group list' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + - '{{ subnet_ids[2] }}' + - '{{ subnet_ids[3] }}' + register: result + +- assert: + that: + - result is changed + - result.subnet_group.description == group_description + - result.subnet_group.name == resource_prefix + - result.subnet_group.vpc_id == vpc.vpc.id + - result.subnet_group.subnet_ids | length == 4 + - subnet_ids[0] in result.subnet_group.subnet_ids + - subnet_ids[1] in result.subnet_group.subnet_ids + - subnet_ids[2] in result.subnet_group.subnet_ids + - subnet_ids[3] in result.subnet_group.subnet_ids + +- name: 'Add more members to subnet group list (idempotency)' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + - '{{ subnet_ids[2] }}' + - '{{ subnet_ids[3] }}' + register: result + +- assert: + that: + - result is not changed + - result.subnet_group.description == group_description + - result.subnet_group.name == resource_prefix + - result.subnet_group.vpc_id == vpc.vpc.id + - result.subnet_group.subnet_ids | length == 4 + - subnet_ids[0] in result.subnet_group.subnet_ids + - subnet_ids[1] in result.subnet_group.subnet_ids + - subnet_ids[2] in result.subnet_group.subnet_ids + - subnet_ids[3] in result.subnet_group.subnet_ids + +# ============================================================ +# Deletion + +- name: 'Delete a subnet group' + rds_subnet_group: + state: absent + name: '{{ resource_prefix }}' + register: result + +- assert: + that: + - result is changed + +- name: 'Delete a subnet group (idempotency)' + rds_subnet_group: + state: absent + name: '{{ resource_prefix }}' + register: result + +- assert: + that: + - result is not changed From 1ec9356757341f7360819be860c306a0903e5990 Mon Sep 17 00:00:00 2001 From: jillr Date: Tue, 3 Mar 2020 19:43:21 +0000 Subject: [PATCH 02/18] migration test cleanup This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/13b104b912784bb31a0bff23eed4c27b0f5e0283 --- tests/integration/targets/rds_subnet_group/tasks/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/integration/targets/rds_subnet_group/tasks/main.yml b/tests/integration/targets/rds_subnet_group/tasks/main.yml index 44184e302db..11a677e283d 100644 --- a/tests/integration/targets/rds_subnet_group/tasks/main.yml +++ b/tests/integration/targets/rds_subnet_group/tasks/main.yml @@ -12,6 +12,8 @@ aws_secret_key: '{{ aws_secret_key }}' security_token: '{{ security_token | default(omit) }}' region: '{{ aws_region }}' + collections: + - ansible.amazon block: # ============================================================ @@ -62,7 +64,7 @@ register: subnets - set_fact: - subnet_ids: '{{ subnets | json_query("results[].subnet.id") | list }}' + subnet_ids: '{{ subnets | community.general.json_query("results[].subnet.id") | list }}' # ============================================================ From dbede80038b61e0cf85930a420d63f4e1ccf6968 Mon Sep 17 00:00:00 2001 From: Jill R <4121322+jillr@users.noreply.github.com> Date: Wed, 25 Mar 2020 15:39:40 -0700 Subject: [PATCH 03/18] Rename collection (#12) * Rename core collection Rename references to ansible.amazon to amazon.aws. * Rename community.amazon to community.aws Fix pep8 line lengths for rewritten amazon.aws imports * Missed a path in shippable.sh * Dependency repos moved This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/235c5db571cc45db5839476c94356c9b91e1f228 --- plugins/modules/rds_subnet_group.py | 6 +++--- tests/integration/targets/rds_subnet_group/tasks/main.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/modules/rds_subnet_group.py b/plugins/modules/rds_subnet_group.py index 1bba28dfbce..b0fb417a28f 100644 --- a/plugins/modules/rds_subnet_group.py +++ b/plugins/modules/rds_subnet_group.py @@ -41,8 +41,8 @@ type: list author: "Scott Anderson (@tastychutney)" extends_documentation_fragment: -- ansible.amazon.aws -- ansible.amazon.ec2 +- amazon.aws.aws +- amazon.aws.ec2 ''' @@ -98,7 +98,7 @@ HAS_BOTO = False from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import HAS_BOTO, connect_to_aws, ec2_argument_spec, get_aws_connection_info +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import HAS_BOTO, connect_to_aws, ec2_argument_spec, get_aws_connection_info def get_subnet_group_info(subnet_group): diff --git a/tests/integration/targets/rds_subnet_group/tasks/main.yml b/tests/integration/targets/rds_subnet_group/tasks/main.yml index 11a677e283d..664d78edeee 100644 --- a/tests/integration/targets/rds_subnet_group/tasks/main.yml +++ b/tests/integration/targets/rds_subnet_group/tasks/main.yml @@ -13,7 +13,7 @@ security_token: '{{ security_token | default(omit) }}' region: '{{ aws_region }}' collections: - - ansible.amazon + - amazon.aws block: # ============================================================ From 215e3bb375f27ac5701079ceabe445b9390e2ca1 Mon Sep 17 00:00:00 2001 From: Jill R <4121322+jillr@users.noreply.github.com> Date: Tue, 19 May 2020 16:06:12 -0700 Subject: [PATCH 04/18] Remove METADATA and cleanup galaxy.yml (#70) * Remove ANSIBLE_METADATA entirely, see ansible/ansible/pull/69454. Remove `license` field from galaxy.yml, in favor of `license_file`. This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/05672a64e2362cc2d865b5af6a57da6bc3cd08e3 --- plugins/modules/rds_subnet_group.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/plugins/modules/rds_subnet_group.py b/plugins/modules/rds_subnet_group.py index b0fb417a28f..99bfb002752 100644 --- a/plugins/modules/rds_subnet_group.py +++ b/plugins/modules/rds_subnet_group.py @@ -6,11 +6,6 @@ __metaclass__ = type -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['stableinterface'], - 'supported_by': 'community'} - - DOCUMENTATION = ''' --- module: rds_subnet_group From 33028e847f87d40403143c918146161873e0f6e8 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Wed, 17 Jun 2020 01:24:54 +0530 Subject: [PATCH 05/18] Update Examples with FQCN (#67) Updated module examples with FQCN Signed-off-by: Abhijeet Kasurde This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/98173aefbbceed7fc0d9db62687b73f96a55a999 --- plugins/modules/rds_subnet_group.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/modules/rds_subnet_group.py b/plugins/modules/rds_subnet_group.py index 99bfb002752..f913d41f296 100644 --- a/plugins/modules/rds_subnet_group.py +++ b/plugins/modules/rds_subnet_group.py @@ -42,8 +42,8 @@ ''' EXAMPLES = ''' -# Add or change a subnet group -- rds_subnet_group: +- name: Add or change a subnet group + community.aws.rds_subnet_group: state: present name: norwegian-blue description: My Fancy Ex Parrot Subnet Group @@ -51,8 +51,8 @@ - subnet-aaaaaaaa - subnet-bbbbbbbb -# Remove a subnet group -- rds_subnet_group: +- name: Remove a subnet group + community.aws.rds_subnet_group: state: absent name: norwegian-blue ''' From 7e0a5c92351cbc2bc6e9f61c0e89af420d590c85 Mon Sep 17 00:00:00 2001 From: Jill R <4121322+jillr@users.noreply.github.com> Date: Wed, 17 Jun 2020 09:31:32 -0700 Subject: [PATCH 06/18] Update docs (#99) * Update docs Remove .git from repo url so links in readme will generate correctly Add required ansible version Run latest version of add_docs.py Add version_added string to modules * galaxy.yml was missing authors This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/96ee268e5267f5b12c3d59892bc1279f75aa3135 --- plugins/modules/rds_subnet_group.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/rds_subnet_group.py b/plugins/modules/rds_subnet_group.py index f913d41f296..3e207468e8e 100644 --- a/plugins/modules/rds_subnet_group.py +++ b/plugins/modules/rds_subnet_group.py @@ -9,6 +9,7 @@ DOCUMENTATION = ''' --- module: rds_subnet_group +version_added: 1.0.0 short_description: manage RDS database subnet groups description: - Creates, modifies, and deletes RDS database subnet groups. This module has a dependency on python-boto >= 2.5. From f9fc3908187f3b5163eb854ecae26c86cb65e0fe Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Thu, 16 Jul 2020 01:31:41 +0530 Subject: [PATCH 07/18] Docs: sanity fixes (#133) Signed-off-by: Abhijeet Kasurde This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/059cf9efc95bb976de21ab4f8e4d9ddd001983fc --- plugins/modules/rds_subnet_group.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/modules/rds_subnet_group.py b/plugins/modules/rds_subnet_group.py index 3e207468e8e..818b46bd6fe 100644 --- a/plugins/modules/rds_subnet_group.py +++ b/plugins/modules/rds_subnet_group.py @@ -6,7 +6,7 @@ __metaclass__ = type -DOCUMENTATION = ''' +DOCUMENTATION = r''' --- module: rds_subnet_group version_added: 1.0.0 @@ -35,6 +35,7 @@ - List of subnet IDs that make up the database subnet group. - Required when I(state=present). type: list + elements: str author: "Scott Anderson (@tastychutney)" extends_documentation_fragment: - amazon.aws.aws @@ -42,7 +43,7 @@ ''' -EXAMPLES = ''' +EXAMPLES = r''' - name: Add or change a subnet group community.aws.rds_subnet_group: state: present @@ -58,7 +59,7 @@ name: norwegian-blue ''' -RETURN = ''' +RETURN = r''' subnet_group: description: Dictionary of DB subnet group values returned: I(state=present) @@ -125,7 +126,7 @@ def main(): state=dict(required=True, choices=['present', 'absent']), name=dict(required=True), description=dict(required=False), - subnets=dict(required=False, type='list'), + subnets=dict(required=False, type='list', elements='str'), ) ) module = AnsibleModule(argument_spec=argument_spec) From ab0b18566d199e1393b8b5c08cbc2a9161158045 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Wed, 12 Aug 2020 13:06:35 +0200 Subject: [PATCH 08/18] Bulk migration to AnsibleAWSModule (#173) * Update comments to reference AnsibleAWSModule rather than AnsibleModule * Bulk re-order imports and split onto one from import per-line. * Add AnsibleAWSModule imports * Migrate boto 2 based modules to AnsibleAWSModule * Move boto3-only modules over to AnsibleAWSModule * Remove extra ec2_argument_spec calls - not needed now we're using AnsibleAWSModule * Remove most HAS_BOTO3 code, it's handled by AnsibleAWSModule * Handle missing Boto 2 consistently (HAS_BOTO) * Remove AnsibleModule imports * Changelog fragment This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/818c6d2faa046974a9bdfa9346122d11e5bef3b1 --- plugins/modules/rds_subnet_group.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/plugins/modules/rds_subnet_group.py b/plugins/modules/rds_subnet_group.py index 818b46bd6fe..daa35abd0ad 100644 --- a/plugins/modules/rds_subnet_group.py +++ b/plugins/modules/rds_subnet_group.py @@ -90,12 +90,13 @@ try: import boto.rds from boto.exception import BotoServerError - HAS_BOTO = True except ImportError: - HAS_BOTO = False + pass # Handled by HAS_BOTO -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import HAS_BOTO, connect_to_aws, ec2_argument_spec, get_aws_connection_info +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import HAS_BOTO +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import connect_to_aws +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info def get_subnet_group_info(subnet_group): @@ -121,15 +122,13 @@ def create_result(changed, subnet_group=None): def main(): - argument_spec = ec2_argument_spec() - argument_spec.update(dict( + argument_spec = dict( state=dict(required=True, choices=['present', 'absent']), name=dict(required=True), description=dict(required=False), subnets=dict(required=False, type='list', elements='str'), ) - ) - module = AnsibleModule(argument_spec=argument_spec) + module = AnsibleAWSModule(argument_spec=argument_spec) if not HAS_BOTO: module.fail_json(msg='boto required for this module') From 5f3d5bbdedddfbc2b990d1742074dfbbb82cfd72 Mon Sep 17 00:00:00 2001 From: Pascal Morin Date: Thu, 10 Sep 2020 10:46:36 +0200 Subject: [PATCH 09/18] #223 Port rds_subnet_group to boto3 (#224) * Port rds_subnet_group to boto3 * Linting fixes * Add more meaningful error messages, add changelog fragment * Remove test on mandatory args for state absent This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/c19d479c1b95e496279d25565b5a20d07d4ef1e0 --- plugins/modules/rds_subnet_group.py | 185 ++++++++++-------- .../targets/rds_subnet_group/tasks/params.yml | 58 ++---- 2 files changed, 119 insertions(+), 124 deletions(-) diff --git a/plugins/modules/rds_subnet_group.py b/plugins/modules/rds_subnet_group.py index daa35abd0ad..bb0cc685a8a 100644 --- a/plugins/modules/rds_subnet_group.py +++ b/plugins/modules/rds_subnet_group.py @@ -1,8 +1,11 @@ #!/usr/bin/python +# -*- coding: utf-8 -*- + # Copyright: Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -66,10 +69,18 @@ type: complex contains: name: + description: The name of the DB subnet group (maintained for backward compatibility) + returned: I(state=present) + type: str + db_subnet_group_name: description: The name of the DB subnet group returned: I(state=present) type: str description: + description: The description of the DB subnet group (maintained for backward compatibility) + returned: I(state=present) + type: str + db_subnet_group_description: description: The description of the DB subnet group returned: I(state=present) type: str @@ -81,32 +92,32 @@ description: Contains a list of Subnet IDs returned: I(state=present) type: list + subnets: + description: Contains a list of Subnet elements (@see https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rds.html#RDS.Client.describe_db_subnet_groups) # noqa + returned: I(state=present) + type: list status: + description: The status of the DB subnet group (maintained for backward compatibility) + returned: I(state=present) + type: str + subnet_group_status: description: The status of the DB subnet group returned: I(state=present) type: str + db_subnet_group_arn: + description: The ARN of the DB subnet group + returned: I(state=present) + type: str ''' -try: - import boto.rds - from boto.exception import BotoServerError -except ImportError: - pass # Handled by HAS_BOTO +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import HAS_BOTO -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import connect_to_aws -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info - -def get_subnet_group_info(subnet_group): - return dict( - name=subnet_group.name, - description=subnet_group.description, - vpc_id=subnet_group.vpc_id, - subnet_ids=subnet_group.subnet_ids, - status=subnet_group.status - ) +try: + import botocore +except ImportError: + pass # Handled by AnsibleAWSModule def create_result(changed, subnet_group=None): @@ -114,11 +125,34 @@ def create_result(changed, subnet_group=None): return dict( changed=changed ) - else: - return dict( - changed=changed, - subnet_group=get_subnet_group_info(subnet_group) - ) + result_subnet_group = dict(camel_dict_to_snake_dict(subnet_group)) + result_subnet_group['name'] = result_subnet_group.get( + 'db_subnet_group_name') + result_subnet_group['description'] = result_subnet_group.get( + 'db_subnet_group_description') + result_subnet_group['status'] = result_subnet_group.get( + 'subnet_group_status') + result_subnet_group['subnet_ids'] = create_subnet_list( + subnet_group.get('Subnets')) + return dict( + changed=changed, + subnet_group=result_subnet_group + ) + + +def create_subnet_list(subnets): + ''' + Construct a list of subnet ids from a list of subnets dicts returned by boto. + Parameters: + subnets (list): A list of subnets definitions. + @see https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rds.html#RDS.Client.describe_db_subnet_groups + Returns: + (list): List of subnet ids (str) + ''' + subnets_ids = [] + for subnet in subnets: + subnets_ids.append(subnet.get('SubnetIdentifier')) + return subnets_ids def main(): @@ -128,70 +162,63 @@ def main(): description=dict(required=False), subnets=dict(required=False, type='list', elements='str'), ) - module = AnsibleAWSModule(argument_spec=argument_spec) - - if not HAS_BOTO: - module.fail_json(msg='boto required for this module') - + required_if = [('state', 'present', ['description', 'subnets'])] + module = AnsibleAWSModule( + argument_spec=argument_spec, required_if=required_if) state = module.params.get('state') group_name = module.params.get('name').lower() group_description = module.params.get('description') - group_subnets = module.params.get('subnets') or {} - - if state == 'present': - for required in ['description', 'subnets']: - if not module.params.get(required): - module.fail_json(msg=str("Parameter %s required for state='present'" % required)) - else: - for not_allowed in ['description', 'subnets']: - if module.params.get(not_allowed): - module.fail_json(msg=str("Parameter %s not allowed for state='absent'" % not_allowed)) - - # Retrieve any AWS settings from the environment. - region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module) - - if not region: - module.fail_json(msg=str("Either region or AWS_REGION or EC2_REGION environment variable or boto config aws_region or ec2_region must be set.")) + group_subnets = module.params.get('subnets') or [] try: - conn = connect_to_aws(boto.rds, region, **aws_connect_kwargs) - except BotoServerError as e: - module.fail_json(msg=e.error_message) + conn = module.client('rds') + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: + module.fail_json_aws(e, 'Failed to instantiate AWS connection') + # Default. + result = create_result(False) try: - exists = False - result = create_result(False) - + matching_groups = conn.describe_db_subnet_groups( + DBSubnetGroupName=group_name, MaxRecords=100).get('DBSubnetGroups') + except is_boto3_error_code('DBSubnetGroupNotFoundFault'): + # No existing subnet, create it if needed, else we can just exit. + if state == 'present': + try: + new_group = conn.create_db_subnet_group( + DBSubnetGroupName=group_name, DBSubnetGroupDescription=group_description, SubnetIds=group_subnets) + result = create_result(True, new_group.get('DBSubnetGroup')) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: + module.fail_json_aws(e, 'Failed to create a new subnet group') + module.exit_json(**result) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except + module.fail_json_aws(e, 'Failed to get subnet groups description') + # We have one or more subnets at this point. + if state == 'absent': try: - matching_groups = conn.get_all_db_subnet_groups(group_name, max_records=100) - exists = len(matching_groups) > 0 - except BotoServerError as e: - if e.error_code != 'DBSubnetGroupNotFoundFault': - module.fail_json(msg=e.error_message) - - if state == 'absent': - if exists: - conn.delete_db_subnet_group(group_name) - result = create_result(True) - else: - if not exists: - new_group = conn.create_db_subnet_group(group_name, desc=group_description, subnet_ids=group_subnets) - result = create_result(True, new_group) - else: - # Sort the subnet groups before we compare them - matching_groups[0].subnet_ids.sort() - group_subnets.sort() - if (matching_groups[0].name != group_name or - matching_groups[0].description != group_description or - matching_groups[0].subnet_ids != group_subnets): - changed_group = conn.modify_db_subnet_group(group_name, description=group_description, subnet_ids=group_subnets) - result = create_result(True, changed_group) - else: - result = create_result(False, matching_groups[0]) - except BotoServerError as e: - module.fail_json(msg=e.error_message) - - module.exit_json(**result) + conn.delete_db_subnet_group(DBSubnetGroupName=group_name) + result = create_result(True) + module.exit_json(**result) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: + module.fail_json_aws(e, 'Failed to delete a subnet group') + + # Sort the subnet groups before we compare them + existing_subnets = create_subnet_list(matching_groups[0].get('Subnets')) + existing_subnets.sort() + group_subnets.sort() + # See if anything changed. + if (matching_groups[0].get('DBSubnetGroupName') == group_name and + matching_groups[0].get('DBSubnetGroupDescription') == group_description and + existing_subnets == group_subnets): + result = create_result(False, matching_groups[0]) + module.exit_json(**result) + # Modify existing group. + try: + changed_group = conn.modify_db_subnet_group( + DBSubnetGroupName=group_name, DBSubnetGroupDescription=group_description, SubnetIds=group_subnets) + result = create_result(True, changed_group.get('DBSubnetGroup')) + module.exit_json(**result) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: + module.fail_json_aws(e, 'Failed to update a subnet group') if __name__ == '__main__': diff --git a/tests/integration/targets/rds_subnet_group/tasks/params.yml b/tests/integration/targets/rds_subnet_group/tasks/params.yml index 74da381ff7a..e6b042f7a2f 100644 --- a/tests/integration/targets/rds_subnet_group/tasks/params.yml +++ b/tests/integration/targets/rds_subnet_group/tasks/params.yml @@ -1,62 +1,30 @@ --- # Try creating without a description -- name: 'Create a subnet group (no description)' +- name: "Create a subnet group (no description)" rds_subnet_group: state: present - name: '{{ resource_prefix }}' + name: "{{ resource_prefix }}" subnets: - - '{{ subnet_ids[0] }}' - - '{{ subnet_ids[1] }}' + - "{{ subnet_ids[0] }}" + - "{{ subnet_ids[1] }}" ignore_errors: yes register: create_missing_param - assert: that: - - create_missing_param is failed - - "'description' in create_missing_param.msg" - - "\"required for state='present'\" in create_missing_param.msg" + - create_missing_param is failed + - "'description' in create_missing_param.msg" + - "'state is present but all of the following are missing' in create_missing_param.msg" # Try creating without subnets -- name: 'Create a subnet group (no subnets)' +- name: "Create a subnet group (no subnets)" rds_subnet_group: state: present - name: '{{ resource_prefix }}' - description: '{{ group_description }}' + name: "{{ resource_prefix }}" + description: "{{ group_description }}" ignore_errors: yes register: create_missing_param - assert: that: - - create_missing_param is failed - - "'subnets' in create_missing_param.msg" - - "\"required for state='present'\" in create_missing_param.msg" - -# XXX This feels like a bad pattern -# Try deleting with subnets -- name: 'Delete a subnet group (with subnets)' - rds_subnet_group: - state: absent - name: '{{ resource_prefix }}' - subnets: - - '{{ subnet_ids[0] }}' - - '{{ subnet_ids[1] }}' - ignore_errors: yes - register: delete_extra_param -- assert: - that: - - delete_extra_param is failed - - "'subnets' in delete_extra_param.msg" - - "\"not allowed for state='absent'\" in delete_extra_param.msg" - -# XXX This feels like a bad pattern -# Try deleting with a description -- name: 'Create a subnet group (with description)' - rds_subnet_group: - state: absent - name: '{{ resource_prefix }}' - description: '{{ group_description }}' - ignore_errors: yes - register: delete_extra_param -- assert: - that: - - delete_extra_param is failed - - "'description' in delete_extra_param.msg" - - "\"not allowed for state='absent'\" in delete_extra_param.msg" + - create_missing_param is failed + - "'subnets' in create_missing_param.msg" + - "'state is present but all of the following are missing' in create_missing_param.msg" From 5b8b3f08bea51bf0f638f9c4231b2a6540d651bf Mon Sep 17 00:00:00 2001 From: jillr Date: Thu, 29 Apr 2021 21:58:50 +0000 Subject: [PATCH 10/18] Remove shippable references from repo This collection has been operating on Zuul CI for some weeks now This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/4e0d83c65568a99a24307e37a14e6e0b173c948b --- tests/integration/targets/rds_subnet_group/aliases | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/targets/rds_subnet_group/aliases b/tests/integration/targets/rds_subnet_group/aliases index 6e3860bee23..4ef4b2067d0 100644 --- a/tests/integration/targets/rds_subnet_group/aliases +++ b/tests/integration/targets/rds_subnet_group/aliases @@ -1,2 +1 @@ cloud/aws -shippable/aws/group2 From c34acbf75bbac5598afcf5bdd48d7d4e549be698 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Tue, 12 Oct 2021 09:20:51 +0200 Subject: [PATCH 11/18] Remove inaccurate references to boto This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/63ec3b0a80abf4e6cd9790d146b65316fc569251 --- plugins/modules/rds_subnet_group.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/rds_subnet_group.py b/plugins/modules/rds_subnet_group.py index bb0cc685a8a..7d789481c43 100644 --- a/plugins/modules/rds_subnet_group.py +++ b/plugins/modules/rds_subnet_group.py @@ -15,7 +15,7 @@ version_added: 1.0.0 short_description: manage RDS database subnet groups description: - - Creates, modifies, and deletes RDS database subnet groups. This module has a dependency on python-boto >= 2.5. + - Creates, modifies, and deletes RDS database subnet groups. options: state: description: @@ -142,7 +142,7 @@ def create_result(changed, subnet_group=None): def create_subnet_list(subnets): ''' - Construct a list of subnet ids from a list of subnets dicts returned by boto. + Construct a list of subnet ids from a list of subnets dicts returned by boto3. Parameters: subnets (list): A list of subnets definitions. @see https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rds.html#RDS.Client.describe_db_subnet_groups From 8db7a9a9f46ddad9fdaea6c4700ce21442ba8cad Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Tue, 29 Mar 2022 15:10:42 +0200 Subject: [PATCH 12/18] rds_subnet_group: Add tags feature and enable check_mode (#562) rds_subnet_group: Add tags feature and enable check_mode SUMMARY rds_subnet_group: Add tags feature and enable check_mode Fixes: #552 Depends-On: ansible-collections/amazon.aws#553 ISSUE TYPE Feature Pull Request COMPONENT NAME rds_subnet_group Reviewed-by: Jill R Reviewed-by: Mark Chappell Reviewed-by: Alina Buzachis Reviewed-by: Mark Woolley Reviewed-by: Markus Bergholz This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/ce599bdf68bbd05b23ac4ed6cc46ae37208c698c --- plugins/modules/rds_subnet_group.py | 249 ++++++++-- .../targets/rds_subnet_group/tasks/main.yml | 2 +- .../targets/rds_subnet_group/tasks/tests.yml | 459 +++++++++++++++++- 3 files changed, 658 insertions(+), 52 deletions(-) diff --git a/plugins/modules/rds_subnet_group.py b/plugins/modules/rds_subnet_group.py index 7d789481c43..b0a9f8ae806 100644 --- a/plugins/modules/rds_subnet_group.py +++ b/plugins/modules/rds_subnet_group.py @@ -39,7 +39,21 @@ - Required when I(state=present). type: list elements: str -author: "Scott Anderson (@tastychutney)" + tags: + description: + - A hash/dictionary of tags to add to the new RDS subnet group or to add/remove from an existing one. + type: dict + version_added: 3.2.0 + purge_tags: + description: + - Whether or not to remove tags assigned to the RDS subnet group if not specified in the playbook. + - To remove all tags set I(tags) to an empty dictionary in conjunction with this. + default: True + type: bool + version_added: 3.2.0 +author: + - "Scott Anderson (@tastychutney)" + - "Alina Buzachis (@alinabuzachis)" extends_documentation_fragment: - amazon.aws.aws - amazon.aws.ec2 @@ -56,6 +70,18 @@ - subnet-aaaaaaaa - subnet-bbbbbbbb +- name: Add or change a subnet group and associate tags + community.aws.rds_subnet_group: + state: present + name: norwegian-blue + description: My Fancy Ex Parrot Subnet Group + subnets: + - subnet-aaaaaaaa + - subnet-bbbbbbbb + tags: + tag1: Tag1 + tag2: Tag2 + - name: Remove a subnet group community.aws.rds_subnet_group: state: absent @@ -63,6 +89,11 @@ ''' RETURN = r''' +changed: + description: True if listing the RDS subnet group succeeds. + type: bool + returned: always + sample: "false" subnet_group: description: Dictionary of DB subnet group values returned: I(state=present) @@ -72,46 +103,95 @@ description: The name of the DB subnet group (maintained for backward compatibility) returned: I(state=present) type: str + sample: "ansible-test-mbp-13950442" db_subnet_group_name: description: The name of the DB subnet group returned: I(state=present) type: str + sample: "ansible-test-mbp-13950442" description: description: The description of the DB subnet group (maintained for backward compatibility) returned: I(state=present) type: str + sample: "Simple description." db_subnet_group_description: description: The description of the DB subnet group returned: I(state=present) type: str + sample: "Simple description." vpc_id: description: The VpcId of the DB subnet group returned: I(state=present) type: str + sample: "vpc-0acb0ba033ff2119c" subnet_ids: description: Contains a list of Subnet IDs returned: I(state=present) type: list + sample: + "subnet-08c94870f4480797e" subnets: description: Contains a list of Subnet elements (@see https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rds.html#RDS.Client.describe_db_subnet_groups) # noqa returned: I(state=present) type: list + contains: + subnet_availability_zone: + description: Contains Availability Zone information. + returned: I(state=present) + type: dict + version_added: 3.2.0 + sample: + name: "eu-north-1b" + subnet_identifier: + description: The identifier of the subnet. + returned: I(state=present) + type: str + version_added: 3.2.0 + sample: "subnet-08c94870f4480797e" + subnet_outpost: + description: This value specifies the Outpost. + returned: I(state=present) + type: dict + version_added: 3.2.0 + sample: {} + subnet_status: + description: The status of the subnet. + returned: I(state=present) + type: str + version_added: 3.2.0 + sample: "Active" status: description: The status of the DB subnet group (maintained for backward compatibility) returned: I(state=present) type: str + sample: "Complete" subnet_group_status: description: The status of the DB subnet group returned: I(state=present) type: str + sample: "Complete" db_subnet_group_arn: description: The ARN of the DB subnet group returned: I(state=present) type: str + sample: "arn:aws:rds:eu-north-1:721066863947:subgrp:ansible-test-13950442" + tags: + description: The tags associated with the subnet group + returned: I(state=present) + type: dict + version_added: 3.2.0 + sample: + tag1: Tag1 + tag2: Tag2 ''' from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry +from ansible_collections.amazon.aws.plugins.module_utils.rds import get_tags +from ansible_collections.amazon.aws.plugins.module_utils.rds import ensure_tags try: @@ -125,7 +205,7 @@ def create_result(changed, subnet_group=None): return dict( changed=changed ) - result_subnet_group = dict(camel_dict_to_snake_dict(subnet_group)) + result_subnet_group = dict(subnet_group) result_subnet_group['name'] = result_subnet_group.get( 'db_subnet_group_name') result_subnet_group['description'] = result_subnet_group.get( @@ -133,15 +213,39 @@ def create_result(changed, subnet_group=None): result_subnet_group['status'] = result_subnet_group.get( 'subnet_group_status') result_subnet_group['subnet_ids'] = create_subnet_list( - subnet_group.get('Subnets')) + subnet_group.get('subnets')) return dict( changed=changed, subnet_group=result_subnet_group ) +@AWSRetry.jittered_backoff() +def _describe_db_subnet_groups_with_backoff(client, **kwargs): + paginator = client.get_paginator('describe_db_subnet_groups') + return paginator.paginate(**kwargs).build_full_result() + + +def get_subnet_group(client, module): + params = dict() + params['DBSubnetGroupName'] = module.params.get('name').lower() + + try: + _result = _describe_db_subnet_groups_with_backoff(client, **params) + except is_boto3_error_code('DBSubnetGroupNotFoundFault'): + return None + except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except + module.fail_json_aws(e, msg="Couldn't describe subnet groups.") + + if _result: + result = camel_dict_to_snake_dict(_result['DBSubnetGroups'][0]) + result['tags'] = get_tags(client, module, result['db_subnet_group_arn']) + + return result + + def create_subnet_list(subnets): - ''' + r''' Construct a list of subnet ids from a list of subnets dicts returned by boto3. Parameters: subnets (list): A list of subnets definitions. @@ -151,7 +255,7 @@ def create_subnet_list(subnets): ''' subnets_ids = [] for subnet in subnets: - subnets_ids.append(subnet.get('SubnetIdentifier')) + subnets_ids.append(subnet.get('subnet_identifier')) return subnets_ids @@ -161,64 +265,111 @@ def main(): name=dict(required=True), description=dict(required=False), subnets=dict(required=False, type='list', elements='str'), + tags=dict(required=False, type='dict'), + purge_tags=dict(type='bool', default=True), ) required_if = [('state', 'present', ['description', 'subnets'])] + module = AnsibleAWSModule( - argument_spec=argument_spec, required_if=required_if) + argument_spec=argument_spec, + required_if=required_if, + supports_check_mode=True + ) + state = module.params.get('state') group_name = module.params.get('name').lower() group_description = module.params.get('description') group_subnets = module.params.get('subnets') or [] try: - conn = module.client('rds') + connection = module.client('rds', retry_decorator=AWSRetry.jittered_backoff()) except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: - module.fail_json_aws(e, 'Failed to instantiate AWS connection') + module.fail_json_aws(e, 'Failed to instantiate AWS connection.') + # Default. + changed = None result = create_result(False) + tags_update = False + subnet_update = False - try: - matching_groups = conn.describe_db_subnet_groups( - DBSubnetGroupName=group_name, MaxRecords=100).get('DBSubnetGroups') - except is_boto3_error_code('DBSubnetGroupNotFoundFault'): - # No existing subnet, create it if needed, else we can just exit. - if state == 'present': + if module.params.get("tags") is not None: + _tags = ansible_dict_to_boto3_tag_list(module.params.get("tags")) + else: + _tags = list() + + matching_groups = get_subnet_group(connection, module) + + if state == 'present': + if matching_groups: + # We have one or more subnets at this point. + + # Check if there is any tags update + tags_update = ensure_tags( + connection, + module, + matching_groups['db_subnet_group_arn'], + matching_groups['tags'], + module.params.get("tags"), + module.params['purge_tags'] + ) + + # Sort the subnet groups before we compare them + existing_subnets = create_subnet_list(matching_groups['subnets']) + existing_subnets.sort() + group_subnets.sort() + + # See if anything changed. + if ( + matching_groups['db_subnet_group_name'] != group_name or + matching_groups['db_subnet_group_description'] != group_description or + existing_subnets != group_subnets + ): + if not module.check_mode: + # Modify existing group. + try: + connection.modify_db_subnet_group( + aws_retry=True, + DBSubnetGroupName=group_name, + DBSubnetGroupDescription=group_description, + SubnetIds=group_subnets + ) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: + module.fail_json_aws(e, 'Failed to update a subnet group.') + subnet_update = True + else: + if not module.check_mode: + try: + connection.create_db_subnet_group( + aws_retry=True, + DBSubnetGroupName=group_name, + DBSubnetGroupDescription=group_description, + SubnetIds=group_subnets, + Tags=_tags + ) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: + module.fail_json_aws(e, 'Failed to create a new subnet group.') + subnet_update = True + elif state == 'absent': + if not module.check_mode: try: - new_group = conn.create_db_subnet_group( - DBSubnetGroupName=group_name, DBSubnetGroupDescription=group_description, SubnetIds=group_subnets) - result = create_result(True, new_group.get('DBSubnetGroup')) - except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: - module.fail_json_aws(e, 'Failed to create a new subnet group') - module.exit_json(**result) - except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except - module.fail_json_aws(e, 'Failed to get subnet groups description') - # We have one or more subnets at this point. - if state == 'absent': - try: - conn.delete_db_subnet_group(DBSubnetGroupName=group_name) - result = create_result(True) + connection.delete_db_subnet_group(aws_retry=True, DBSubnetGroupName=group_name) + except is_boto3_error_code('DBSubnetGroupNotFoundFault'): + module.exit_json(**result) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except + module.fail_json_aws(e, 'Failed to delete a subnet group.') + else: + subnet_group = get_subnet_group(connection, module) + if subnet_group: + subnet_update = True + result = create_result(subnet_update, subnet_group) module.exit_json(**result) - except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: - module.fail_json_aws(e, 'Failed to delete a subnet group') - - # Sort the subnet groups before we compare them - existing_subnets = create_subnet_list(matching_groups[0].get('Subnets')) - existing_subnets.sort() - group_subnets.sort() - # See if anything changed. - if (matching_groups[0].get('DBSubnetGroupName') == group_name and - matching_groups[0].get('DBSubnetGroupDescription') == group_description and - existing_subnets == group_subnets): - result = create_result(False, matching_groups[0]) - module.exit_json(**result) - # Modify existing group. - try: - changed_group = conn.modify_db_subnet_group( - DBSubnetGroupName=group_name, DBSubnetGroupDescription=group_description, SubnetIds=group_subnets) - result = create_result(True, changed_group.get('DBSubnetGroup')) - module.exit_json(**result) - except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: - module.fail_json_aws(e, 'Failed to update a subnet group') + + subnet_update = True + + subnet_group = get_subnet_group(connection, module) + changed = tags_update or subnet_update + result = create_result(changed, subnet_group) + module.exit_json(**result) if __name__ == '__main__': diff --git a/tests/integration/targets/rds_subnet_group/tasks/main.yml b/tests/integration/targets/rds_subnet_group/tasks/main.yml index 664d78edeee..ff31d014673 100644 --- a/tests/integration/targets/rds_subnet_group/tasks/main.yml +++ b/tests/integration/targets/rds_subnet_group/tasks/main.yml @@ -64,7 +64,7 @@ register: subnets - set_fact: - subnet_ids: '{{ subnets | community.general.json_query("results[].subnet.id") | list }}' + subnet_ids: '{{ subnets.results | map(attribute="subnet.id") | list }}' # ============================================================ diff --git a/tests/integration/targets/rds_subnet_group/tasks/tests.yml b/tests/integration/targets/rds_subnet_group/tasks/tests.yml index 0b4e3d1b52a..7018448c415 100644 --- a/tests/integration/targets/rds_subnet_group/tasks/tests.yml +++ b/tests/integration/targets/rds_subnet_group/tasks/tests.yml @@ -1,8 +1,21 @@ --- -# XXX rds_subnet_group doesn't support check_mode yet - # ============================================================ # Basic creation +- name: 'Create a subnet group - CHECK_MODE' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + check_mode: true + register: result + +- assert: + that: + - result is changed + - name: 'Create a subnet group' rds_subnet_group: state: present @@ -23,6 +36,21 @@ - subnet_ids[0] in result.subnet_group.subnet_ids - subnet_ids[1] in result.subnet_group.subnet_ids +- name: 'Create a subnet group (idempotency) - CHECK_MODE' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + check_mode: true + register: result + +- assert: + that: + - result is not changed + - name: 'Create a subnet group (idempotency)' rds_subnet_group: state: present @@ -45,6 +73,20 @@ # ============================================================ # Update description +- name: 'Update subnet group description - CHECK_MODE' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description_changed }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + check_mode: true + register: result + +- assert: + that: + - result is changed - name: 'Update subnet group description' rds_subnet_group: @@ -65,6 +107,21 @@ - result.subnet_group.subnet_ids | length == 2 - subnet_ids[0] in result.subnet_group.subnet_ids - subnet_ids[1] in result.subnet_group.subnet_ids + +- name: 'Update subnet group description (idempotency) - CHECK_MODE' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description_changed }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + check_mode: true + register: result + +- assert: + that: + - result is not changed - name: 'Update subnet group description (idempotency)' rds_subnet_group: @@ -85,6 +142,21 @@ - result.subnet_group.subnet_ids | length == 2 - subnet_ids[0] in result.subnet_group.subnet_ids - subnet_ids[1] in result.subnet_group.subnet_ids + +- name: 'Restore subnet group description - CHECK_MODE' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + check_mode: true + register: result + +- assert: + that: + - result is changed - name: 'Restore subnet group description' rds_subnet_group: @@ -108,6 +180,20 @@ # ============================================================ # Update subnets +- name: 'Update subnet group list - CHECK_MODE' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description }}' + subnets: + - '{{ subnet_ids[2] }}' + - '{{ subnet_ids[3] }}' + check_mode: true + register: result + +- assert: + that: + - result is changed - name: 'Update subnet group list' rds_subnet_group: @@ -129,6 +215,21 @@ - subnet_ids[2] in result.subnet_group.subnet_ids - subnet_ids[3] in result.subnet_group.subnet_ids +- name: 'Update subnet group list (idempotency) - CHECK_MODE' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description }}' + subnets: + - '{{ subnet_ids[2] }}' + - '{{ subnet_ids[3] }}' + check_mode: true + register: result + +- assert: + that: + - result is not changed + - name: 'Update subnet group list (idempotency)' rds_subnet_group: state: present @@ -149,6 +250,23 @@ - subnet_ids[2] in result.subnet_group.subnet_ids - subnet_ids[3] in result.subnet_group.subnet_ids +- name: 'Add more subnets subnet group list - CHECK_MODE' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + - '{{ subnet_ids[2] }}' + - '{{ subnet_ids[3] }}' + check_mode: true + register: result + +- assert: + that: + - result is changed + - name: 'Add more subnets subnet group list' rds_subnet_group: state: present @@ -173,6 +291,23 @@ - subnet_ids[2] in result.subnet_group.subnet_ids - subnet_ids[3] in result.subnet_group.subnet_ids +- name: 'Add more members to subnet group list (idempotency) - CHECK_MODE' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + - '{{ subnet_ids[2] }}' + - '{{ subnet_ids[3] }}' + check_mode: true + register: result + +- assert: + that: + - result is not changed + - name: 'Add more members to subnet group list (idempotency)' rds_subnet_group: state: present @@ -197,8 +332,317 @@ - subnet_ids[2] in result.subnet_group.subnet_ids - subnet_ids[3] in result.subnet_group.subnet_ids +# ============================================================ +# Add tags to subnets +- name: 'Update subnet with tags - CHECK_MODE' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description_changed }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + tags: + tag_one: '{{ resource_prefix }} One' + "Tag Two": 'two {{ resource_prefix }}' + check_mode: true + register: result + +- assert: + that: + - result is changed + +- name: 'Update subnet with tags' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description_changed }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + tags: + tag_one: '{{ resource_prefix }} One' + "Tag Two": 'two {{ resource_prefix }}' + register: result + +- assert: + that: + - result is changed + - result.subnet_group.description == group_description_changed + - result.subnet_group.name == resource_prefix + - result.subnet_group.vpc_id == vpc.vpc.id + - result.subnet_group.subnet_ids | length == 2 + - subnet_ids[0] in result.subnet_group.subnet_ids + - subnet_ids[1] in result.subnet_group.subnet_ids + - '"tags" in result.subnet_group' + - result.subnet_group.tags | length == 2 + - result.subnet_group.tags["tag_one"] == '{{ resource_prefix }} One' + - result.subnet_group.tags["Tag Two"] == 'two {{ resource_prefix }}' + +- name: 'Update subnet with tags (idempotency) - CHECK_MODE' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description_changed }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + tags: + tag_one: '{{ resource_prefix }} One' + "Tag Two": 'two {{ resource_prefix }}' + check_mode: true + register: result + +- assert: + that: + - result is not changed + +- name: 'Update subnet with tags (idempotency)' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description_changed }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + tags: + tag_one: '{{ resource_prefix }} One' + "Tag Two": 'two {{ resource_prefix }}' + register: result + +- assert: + that: + - result is not changed + - result.subnet_group.description == group_description_changed + - result.subnet_group.name == resource_prefix + - result.subnet_group.vpc_id == vpc.vpc.id + - result.subnet_group.subnet_ids | length == 2 + - subnet_ids[0] in result.subnet_group.subnet_ids + - subnet_ids[1] in result.subnet_group.subnet_ids + - '"tags" in result.subnet_group' + - result.subnet_group.tags | length == 2 + - result.subnet_group.tags["tag_one"] == '{{ resource_prefix }} One' + - result.subnet_group.tags["Tag Two"] == 'two {{ resource_prefix }}' + +- name: 'Update (add/remove) tags - CHECK_MODE' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description_changed }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + tags: + tag_three: '{{ resource_prefix }} Three' + "Tag Two": 'two {{ resource_prefix }}' + check_mode: true + register: result + +- assert: + that: + - result is changed + +- name: 'Update (add/remove) tags' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description_changed }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + tags: + tag_three: '{{ resource_prefix }} Three' + "Tag Two": 'two {{ resource_prefix }}' + register: result + +- assert: + that: + - result is changed + - result.subnet_group.description == group_description_changed + - result.subnet_group.name == resource_prefix + - result.subnet_group.vpc_id == vpc.vpc.id + - result.subnet_group.subnet_ids | length == 2 + - subnet_ids[0] in result.subnet_group.subnet_ids + - subnet_ids[1] in result.subnet_group.subnet_ids + - '"tags" in result.subnet_group' + - result.subnet_group.tags | length == 2 + - result.subnet_group.tags["tag_three"] == '{{ resource_prefix }} Three' + - result.subnet_group.tags["Tag Two"] == 'two {{ resource_prefix }}' + +- name: 'Update tags without purge - CHECK_MODE' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description_changed }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + purge_tags: no + tags: + tag_one: '{{ resource_prefix }} One' + check_mode: true + register: result + +- assert: + that: + - result is changed + +- name: 'Update tags without purge' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description_changed }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + purge_tags: no + tags: + tag_one: '{{ resource_prefix }} One' + register: result + +- assert: + that: + - result is changed + - result.subnet_group.description == group_description_changed + - result.subnet_group.name == resource_prefix + - result.subnet_group.vpc_id == vpc.vpc.id + - result.subnet_group.subnet_ids | length == 2 + - subnet_ids[0] in result.subnet_group.subnet_ids + - subnet_ids[1] in result.subnet_group.subnet_ids + - '"tags" in result.subnet_group' + - result.subnet_group.tags | length == 3 + - result.subnet_group.tags["tag_three"] == '{{ resource_prefix }} Three' + - result.subnet_group.tags["Tag Two"] == 'two {{ resource_prefix }}' + - result.subnet_group.tags["tag_one"] == '{{ resource_prefix }} One' + +- name: 'Remove all the tags - CHECK_MODE' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description_changed }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + tags: {} + check_mode: true + register: result + +- assert: + that: + - result is changed + +- name: 'Remove all the tags' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description_changed }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + tags: {} + register: result + +- assert: + that: + - result is changed + - result.subnet_group.description == group_description_changed + - result.subnet_group.name == resource_prefix + - result.subnet_group.vpc_id == vpc.vpc.id + - result.subnet_group.subnet_ids | length == 2 + - subnet_ids[0] in result.subnet_group.subnet_ids + - subnet_ids[1] in result.subnet_group.subnet_ids + - '"tags" in result.subnet_group' + +- name: 'Update with CamelCase tags - CHECK_MODE' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description_changed }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + tags: + "lowercase spaced": 'hello cruel world' + "Title Case": 'Hello Cruel World' + CamelCase: 'SimpleCamelCase' + snake_case: 'simple_snake_case' + check_mode: true + register: result + +- assert: + that: + - result is changed + +- name: 'Update with CamelCase tags' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description_changed }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + tags: + "lowercase spaced": 'hello cruel world' + "Title Case": 'Hello Cruel World' + CamelCase: 'SimpleCamelCase' + snake_case: 'simple_snake_case' + register: result + +- assert: + that: + - result is changed + - result.subnet_group.description == group_description_changed + - result.subnet_group.name == resource_prefix + - result.subnet_group.vpc_id == vpc.vpc.id + - result.subnet_group.subnet_ids | length == 2 + - subnet_ids[0] in result.subnet_group.subnet_ids + - subnet_ids[1] in result.subnet_group.subnet_ids + - '"tags" in result.subnet_group' + - result.subnet_group.tags | length == 4 + - result.subnet_group.tags["lowercase spaced"] == 'hello cruel world' + - result.subnet_group.tags["Title Case"] == 'Hello Cruel World' + - result.subnet_group.tags["CamelCase"] == 'SimpleCamelCase' + - result.subnet_group.tags["snake_case"] == 'simple_snake_case' + +- name: 'Do not specify any tag to ensure previous tags are not removed' + rds_subnet_group: + state: present + name: '{{ resource_prefix }}' + description: '{{ group_description_changed }}' + subnets: + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' + register: result + +- assert: + that: + - result is not changed + - result.subnet_group.description == group_description_changed + - result.subnet_group.name == resource_prefix + - result.subnet_group.vpc_id == vpc.vpc.id + - result.subnet_group.subnet_ids | length == 2 + - subnet_ids[0] in result.subnet_group.subnet_ids + - subnet_ids[1] in result.subnet_group.subnet_ids + - '"tags" in result.subnet_group' + - result.subnet_group.tags | length == 4 + - result.subnet_group.tags["lowercase spaced"] == 'hello cruel world' + - result.subnet_group.tags["Title Case"] == 'Hello Cruel World' + - result.subnet_group.tags["CamelCase"] == 'SimpleCamelCase' + - result.subnet_group.tags["snake_case"] == 'simple_snake_case' + + # ============================================================ # Deletion +- name: 'Delete a subnet group - CHECK_MODE' + rds_subnet_group: + state: absent + name: '{{ resource_prefix }}' + check_mode: true + register: result + +- assert: + that: + - result is changed - name: 'Delete a subnet group' rds_subnet_group: @@ -210,6 +654,17 @@ that: - result is changed +- name: 'Delete a subnet group - CHECK_MODE (idempotency)' + rds_subnet_group: + state: absent + name: '{{ resource_prefix }}' + check_mode: true + register: result + +- assert: + that: + - result is not changed + - name: 'Delete a subnet group (idempotency)' rds_subnet_group: state: absent From fad52afa926d5c3e6ec9090bd9e3c8dcaa377e4e Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 22 Apr 2022 11:44:07 +0200 Subject: [PATCH 13/18] Integration test dependency cleanup (#1086) Integration test dependency cleanup SUMMARY remove dependencies on setup_remote_tmp_dir where it's not used (often just copy & paste from another test) remove setup_ec2 (no main.yml means it's not doing anything) remove prepare_tests (empty main.yml means it's not doing anything) ISSUE TYPE Feature Pull Request COMPONENT NAME tests/integration/targets ADDITIONAL INFORMATION By cleaning up what we have we reduce the chance of people copying things about "because that's what test XYZ did". Reviewed-by: Alina Buzachis Reviewed-by: Mark Woolley This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/dd12046a1e2d5f39692b1890ff07e06c56b3bf0e --- tests/integration/targets/rds_subnet_group/meta/main.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/integration/targets/rds_subnet_group/meta/main.yml b/tests/integration/targets/rds_subnet_group/meta/main.yml index 9d91be1705b..32cf5dda7ed 100644 --- a/tests/integration/targets/rds_subnet_group/meta/main.yml +++ b/tests/integration/targets/rds_subnet_group/meta/main.yml @@ -1,3 +1 @@ -dependencies: -- prepare_tests -- setup_ec2 +dependencies: [] From db1ebc45005b63ee6d3d4a01182c777d3133a2d0 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Wed, 1 Jun 2022 15:03:38 +0200 Subject: [PATCH 14/18] Tagging fragment - Move simplest cases over to the docs fragment. (#1182) Tagging fragment - Move simplest cases over to the docs fragment. Depends-On: ansible-collections/amazon.aws#844 SUMMARY Migrate simplest cases over to the new docs fragment and add resource_tags as an alias to tags. ISSUE TYPE Docs Pull Request Feature Pull Request COMPONENT NAME changelogs/fragments/1182-tagging.yml plugins/modules/aws_glue_job.py plugins/modules/aws_msk_cluster.py plugins/modules/aws_secret.py plugins/modules/aws_step_functions_state_machine.py plugins/modules/dynamodb_table.py plugins/modules/ec2_eip.py plugins/modules/ec2_transit_gateway_vpc_attachment.py plugins/modules/ec2_vpc_peer.py plugins/modules/elb_application_lb.py plugins/modules/elb_network_lb.py plugins/modules/iam_role.py plugins/modules/iam_user.py plugins/modules/networkfirewall.py plugins/modules/networkfirewall_policy.py plugins/modules/networkfirewall_rule_group.py plugins/modules/rds_cluster.py plugins/modules/rds_instance.py plugins/modules/rds_instance_snapshot.py plugins/modules/rds_option_group.py plugins/modules/rds_subnet_group.py plugins/modules/redshift.py ADDITIONAL INFORMATION Reviewed-by: Alina Buzachis This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/b11ffaed2b3450f6fee9721878090da404401021 --- plugins/modules/rds_subnet_group.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/plugins/modules/rds_subnet_group.py b/plugins/modules/rds_subnet_group.py index b0a9f8ae806..3ce90a5d863 100644 --- a/plugins/modules/rds_subnet_group.py +++ b/plugins/modules/rds_subnet_group.py @@ -15,7 +15,7 @@ version_added: 1.0.0 short_description: manage RDS database subnet groups description: - - Creates, modifies, and deletes RDS database subnet groups. + - Creates, modifies, and deletes RDS database subnet groups. options: state: description: @@ -39,24 +39,15 @@ - Required when I(state=present). type: list elements: str - tags: - description: - - A hash/dictionary of tags to add to the new RDS subnet group or to add/remove from an existing one. - type: dict - version_added: 3.2.0 - purge_tags: - description: - - Whether or not to remove tags assigned to the RDS subnet group if not specified in the playbook. - - To remove all tags set I(tags) to an empty dictionary in conjunction with this. - default: True - type: bool - version_added: 3.2.0 +notes: + - Support for I(tags) and I(purge_tags) was added in release 3.2.0. author: - - "Scott Anderson (@tastychutney)" - - "Alina Buzachis (@alinabuzachis)" + - "Scott Anderson (@tastychutney)" + - "Alina Buzachis (@alinabuzachis)" extends_documentation_fragment: -- amazon.aws.aws -- amazon.aws.ec2 + - amazon.aws.aws + - amazon.aws.ec2 + - amazon.aws.tags ''' @@ -265,7 +256,7 @@ def main(): name=dict(required=True), description=dict(required=False), subnets=dict(required=False, type='list', elements='str'), - tags=dict(required=False, type='dict'), + tags=dict(required=False, type='dict', aliases=['resource_tags']), purge_tags=dict(type='bool', default=True), ) required_if = [('state', 'present', ['description', 'subnets'])] From 25c38e055efef87ec100f4336475e9c27b21b06b Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Thu, 22 Sep 2022 12:23:22 +0200 Subject: [PATCH 15/18] Update runtime --- meta/runtime.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/meta/runtime.yml b/meta/runtime.yml index 2864a0f1b1f..d5b1c573ca0 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -79,6 +79,7 @@ action_groups: - rds_option_group_info - rds_param_group - rds_snapshot_info + - rds_subnet_group - route53 - route53_health_check - route53_info From f96f668b0cabb01a2b6411044e67730626e0044f Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Thu, 22 Sep 2022 12:23:22 +0200 Subject: [PATCH 16/18] Update FQDN --- plugins/modules/rds_subnet_group.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/rds_subnet_group.py b/plugins/modules/rds_subnet_group.py index 3ce90a5d863..ebc263f54ab 100644 --- a/plugins/modules/rds_subnet_group.py +++ b/plugins/modules/rds_subnet_group.py @@ -53,7 +53,7 @@ EXAMPLES = r''' - name: Add or change a subnet group - community.aws.rds_subnet_group: + amazon.aws.rds_subnet_group: state: present name: norwegian-blue description: My Fancy Ex Parrot Subnet Group @@ -62,7 +62,7 @@ - subnet-bbbbbbbb - name: Add or change a subnet group and associate tags - community.aws.rds_subnet_group: + amazon.aws.rds_subnet_group: state: present name: norwegian-blue description: My Fancy Ex Parrot Subnet Group @@ -74,7 +74,7 @@ tag2: Tag2 - name: Remove a subnet group - community.aws.rds_subnet_group: + amazon.aws.rds_subnet_group: state: absent name: norwegian-blue ''' From f5fa4e64e2b862848a1cacb8df7e90e1b20825df Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Thu, 22 Sep 2022 12:23:22 +0200 Subject: [PATCH 17/18] Remove collection reference inside the tests --- .../rds_subnet_group/defaults/main.yml | 13 ++- .../targets/rds_subnet_group/tasks/main.yml | 23 ++-- .../targets/rds_subnet_group/tasks/params.yml | 27 +++-- .../targets/rds_subnet_group/tasks/tests.yml | 105 +++++++++--------- 4 files changed, 82 insertions(+), 86 deletions(-) diff --git a/tests/integration/targets/rds_subnet_group/defaults/main.yml b/tests/integration/targets/rds_subnet_group/defaults/main.yml index 07e0fe93f8e..156c9f90381 100644 --- a/tests/integration/targets/rds_subnet_group/defaults/main.yml +++ b/tests/integration/targets/rds_subnet_group/defaults/main.yml @@ -1,8 +1,9 @@ -vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/16' -subnet_a: '10.{{ 256 | random(seed=resource_prefix) }}.10.0/24' -subnet_b: '10.{{ 256 | random(seed=resource_prefix) }}.11.0/24' -subnet_c: '10.{{ 256 | random(seed=resource_prefix) }}.12.0/24' -subnet_d: '10.{{ 256 | random(seed=resource_prefix) }}.13.0/24' +vpc_cidr: 10.{{ 256 | random(seed=resource_prefix) }}.0.0/16 +subnet_a: 10.{{ 256 | random(seed=resource_prefix) }}.10.0/24 +subnet_b: 10.{{ 256 | random(seed=resource_prefix) }}.11.0/24 +subnet_c: 10.{{ 256 | random(seed=resource_prefix) }}.12.0/24 +subnet_d: 10.{{ 256 | random(seed=resource_prefix) }}.13.0/24 group_description: 'Created by integration test : {{ resource_prefix }}' -group_description_changed: 'Created by integration test : {{ resource_prefix }} - changed' +group_description_changed: 'Created by integration test : {{ resource_prefix }} - + changed' diff --git a/tests/integration/targets/rds_subnet_group/tasks/main.yml b/tests/integration/targets/rds_subnet_group/tasks/main.yml index ff31d014673..207b150af16 100644 --- a/tests/integration/targets/rds_subnet_group/tasks/main.yml +++ b/tests/integration/targets/rds_subnet_group/tasks/main.yml @@ -1,4 +1,3 @@ ---- # Tests for rds_subnet_group # # Note: (From Amazon's documentation) @@ -12,35 +11,33 @@ aws_secret_key: '{{ aws_secret_key }}' security_token: '{{ security_token | default(omit) }}' region: '{{ aws_region }}' - collections: - - amazon.aws block: # ============================================================ - - name: 'Fetch AZ availability' + - name: Fetch AZ availability aws_az_info: register: az_info - - name: 'Assert that we have multiple AZs available to us' + - name: Assert that we have multiple AZs available to us assert: that: az_info.availability_zones | length >= 2 - - name: 'Pick AZs' + - name: Pick AZs set_fact: az_one: '{{ az_info.availability_zones[0].zone_name }}' az_two: '{{ az_info.availability_zones[1].zone_name }}' # ============================================================ - - name: 'Create a VPC' + - name: Create a VPC ec2_vpc_net: state: present cidr_block: '{{ vpc_cidr }}' name: '{{ resource_prefix }}' register: vpc - - name: 'Create subnets' + - name: Create subnets ec2_vpc_subnet: state: present cidr: '{{ item.cidr }}' @@ -68,20 +65,20 @@ # ============================================================ - - include_tasks: 'params.yml' + - include_tasks: params.yml - - include_tasks: 'tests.yml' + - include_tasks: tests.yml # ============================================================ always: - - name: 'Remove subnet group' + - name: Remove subnet group rds_subnet_group: state: absent name: '{{ resource_prefix }}' ignore_errors: yes - - name: 'Remove subnets' + - name: Remove subnets ec2_vpc_subnet: state: absent cidr: '{{ item.cidr }}' @@ -101,7 +98,7 @@ retries: 5 delay: 5 - - name: 'Remove the VPC' + - name: Remove the VPC ec2_vpc_net: state: absent cidr_block: '{{ vpc_cidr }}' diff --git a/tests/integration/targets/rds_subnet_group/tasks/params.yml b/tests/integration/targets/rds_subnet_group/tasks/params.yml index e6b042f7a2f..109703f38f1 100644 --- a/tests/integration/targets/rds_subnet_group/tasks/params.yml +++ b/tests/integration/targets/rds_subnet_group/tasks/params.yml @@ -1,30 +1,29 @@ ---- # Try creating without a description -- name: "Create a subnet group (no description)" +- name: Create a subnet group (no description) rds_subnet_group: state: present - name: "{{ resource_prefix }}" + name: '{{ resource_prefix }}' subnets: - - "{{ subnet_ids[0] }}" - - "{{ subnet_ids[1] }}" + - '{{ subnet_ids[0] }}' + - '{{ subnet_ids[1] }}' ignore_errors: yes register: create_missing_param - assert: that: - - create_missing_param is failed - - "'description' in create_missing_param.msg" - - "'state is present but all of the following are missing' in create_missing_param.msg" + - create_missing_param is failed + - "'description' in create_missing_param.msg" + - "'state is present but all of the following are missing' in create_missing_param.msg" # Try creating without subnets -- name: "Create a subnet group (no subnets)" +- name: Create a subnet group (no subnets) rds_subnet_group: state: present - name: "{{ resource_prefix }}" - description: "{{ group_description }}" + name: '{{ resource_prefix }}' + description: '{{ group_description }}' ignore_errors: yes register: create_missing_param - assert: that: - - create_missing_param is failed - - "'subnets' in create_missing_param.msg" - - "'state is present but all of the following are missing' in create_missing_param.msg" + - create_missing_param is failed + - "'subnets' in create_missing_param.msg" + - "'state is present but all of the following are missing' in create_missing_param.msg" diff --git a/tests/integration/targets/rds_subnet_group/tasks/tests.yml b/tests/integration/targets/rds_subnet_group/tasks/tests.yml index 7018448c415..ce710ed3b34 100644 --- a/tests/integration/targets/rds_subnet_group/tasks/tests.yml +++ b/tests/integration/targets/rds_subnet_group/tasks/tests.yml @@ -1,7 +1,6 @@ ---- # ============================================================ # Basic creation -- name: 'Create a subnet group - CHECK_MODE' +- name: Create a subnet group - CHECK_MODE rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -16,7 +15,7 @@ that: - result is changed -- name: 'Create a subnet group' +- name: Create a subnet group rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -36,7 +35,7 @@ - subnet_ids[0] in result.subnet_group.subnet_ids - subnet_ids[1] in result.subnet_group.subnet_ids -- name: 'Create a subnet group (idempotency) - CHECK_MODE' +- name: Create a subnet group (idempotency) - CHECK_MODE rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -51,7 +50,7 @@ that: - result is not changed -- name: 'Create a subnet group (idempotency)' +- name: Create a subnet group (idempotency) rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -73,7 +72,7 @@ # ============================================================ # Update description -- name: 'Update subnet group description - CHECK_MODE' +- name: Update subnet group description - CHECK_MODE rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -88,7 +87,7 @@ that: - result is changed -- name: 'Update subnet group description' +- name: Update subnet group description rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -107,8 +106,8 @@ - result.subnet_group.subnet_ids | length == 2 - subnet_ids[0] in result.subnet_group.subnet_ids - subnet_ids[1] in result.subnet_group.subnet_ids - -- name: 'Update subnet group description (idempotency) - CHECK_MODE' + +- name: Update subnet group description (idempotency) - CHECK_MODE rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -123,7 +122,7 @@ that: - result is not changed -- name: 'Update subnet group description (idempotency)' +- name: Update subnet group description (idempotency) rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -142,8 +141,8 @@ - result.subnet_group.subnet_ids | length == 2 - subnet_ids[0] in result.subnet_group.subnet_ids - subnet_ids[1] in result.subnet_group.subnet_ids - -- name: 'Restore subnet group description - CHECK_MODE' + +- name: Restore subnet group description - CHECK_MODE rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -158,7 +157,7 @@ that: - result is changed -- name: 'Restore subnet group description' +- name: Restore subnet group description rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -180,7 +179,7 @@ # ============================================================ # Update subnets -- name: 'Update subnet group list - CHECK_MODE' +- name: Update subnet group list - CHECK_MODE rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -195,7 +194,7 @@ that: - result is changed -- name: 'Update subnet group list' +- name: Update subnet group list rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -215,7 +214,7 @@ - subnet_ids[2] in result.subnet_group.subnet_ids - subnet_ids[3] in result.subnet_group.subnet_ids -- name: 'Update subnet group list (idempotency) - CHECK_MODE' +- name: Update subnet group list (idempotency) - CHECK_MODE rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -230,7 +229,7 @@ that: - result is not changed -- name: 'Update subnet group list (idempotency)' +- name: Update subnet group list (idempotency) rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -250,7 +249,7 @@ - subnet_ids[2] in result.subnet_group.subnet_ids - subnet_ids[3] in result.subnet_group.subnet_ids -- name: 'Add more subnets subnet group list - CHECK_MODE' +- name: Add more subnets subnet group list - CHECK_MODE rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -267,7 +266,7 @@ that: - result is changed -- name: 'Add more subnets subnet group list' +- name: Add more subnets subnet group list rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -291,7 +290,7 @@ - subnet_ids[2] in result.subnet_group.subnet_ids - subnet_ids[3] in result.subnet_group.subnet_ids -- name: 'Add more members to subnet group list (idempotency) - CHECK_MODE' +- name: Add more members to subnet group list (idempotency) - CHECK_MODE rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -308,7 +307,7 @@ that: - result is not changed -- name: 'Add more members to subnet group list (idempotency)' +- name: Add more members to subnet group list (idempotency) rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -334,7 +333,7 @@ # ============================================================ # Add tags to subnets -- name: 'Update subnet with tags - CHECK_MODE' +- name: Update subnet with tags - CHECK_MODE rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -344,7 +343,7 @@ - '{{ subnet_ids[1] }}' tags: tag_one: '{{ resource_prefix }} One' - "Tag Two": 'two {{ resource_prefix }}' + Tag Two: two {{ resource_prefix }} check_mode: true register: result @@ -352,7 +351,7 @@ that: - result is changed -- name: 'Update subnet with tags' +- name: Update subnet with tags rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -362,7 +361,7 @@ - '{{ subnet_ids[1] }}' tags: tag_one: '{{ resource_prefix }} One' - "Tag Two": 'two {{ resource_prefix }}' + Tag Two: two {{ resource_prefix }} register: result - assert: @@ -378,8 +377,8 @@ - result.subnet_group.tags | length == 2 - result.subnet_group.tags["tag_one"] == '{{ resource_prefix }} One' - result.subnet_group.tags["Tag Two"] == 'two {{ resource_prefix }}' - -- name: 'Update subnet with tags (idempotency) - CHECK_MODE' + +- name: Update subnet with tags (idempotency) - CHECK_MODE rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -389,7 +388,7 @@ - '{{ subnet_ids[1] }}' tags: tag_one: '{{ resource_prefix }} One' - "Tag Two": 'two {{ resource_prefix }}' + Tag Two: two {{ resource_prefix }} check_mode: true register: result @@ -397,7 +396,7 @@ that: - result is not changed -- name: 'Update subnet with tags (idempotency)' +- name: Update subnet with tags (idempotency) rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -407,7 +406,7 @@ - '{{ subnet_ids[1] }}' tags: tag_one: '{{ resource_prefix }} One' - "Tag Two": 'two {{ resource_prefix }}' + Tag Two: two {{ resource_prefix }} register: result - assert: @@ -424,7 +423,7 @@ - result.subnet_group.tags["tag_one"] == '{{ resource_prefix }} One' - result.subnet_group.tags["Tag Two"] == 'two {{ resource_prefix }}' -- name: 'Update (add/remove) tags - CHECK_MODE' +- name: Update (add/remove) tags - CHECK_MODE rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -434,7 +433,7 @@ - '{{ subnet_ids[1] }}' tags: tag_three: '{{ resource_prefix }} Three' - "Tag Two": 'two {{ resource_prefix }}' + Tag Two: two {{ resource_prefix }} check_mode: true register: result @@ -442,7 +441,7 @@ that: - result is changed -- name: 'Update (add/remove) tags' +- name: Update (add/remove) tags rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -452,7 +451,7 @@ - '{{ subnet_ids[1] }}' tags: tag_three: '{{ resource_prefix }} Three' - "Tag Two": 'two {{ resource_prefix }}' + Tag Two: two {{ resource_prefix }} register: result - assert: @@ -469,7 +468,7 @@ - result.subnet_group.tags["tag_three"] == '{{ resource_prefix }} Three' - result.subnet_group.tags["Tag Two"] == 'two {{ resource_prefix }}' -- name: 'Update tags without purge - CHECK_MODE' +- name: Update tags without purge - CHECK_MODE rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -487,7 +486,7 @@ that: - result is changed -- name: 'Update tags without purge' +- name: Update tags without purge rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -515,7 +514,7 @@ - result.subnet_group.tags["Tag Two"] == 'two {{ resource_prefix }}' - result.subnet_group.tags["tag_one"] == '{{ resource_prefix }} One' -- name: 'Remove all the tags - CHECK_MODE' +- name: Remove all the tags - CHECK_MODE rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -531,7 +530,7 @@ that: - result is changed -- name: 'Remove all the tags' +- name: Remove all the tags rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -553,7 +552,7 @@ - subnet_ids[1] in result.subnet_group.subnet_ids - '"tags" in result.subnet_group' -- name: 'Update with CamelCase tags - CHECK_MODE' +- name: Update with CamelCase tags - CHECK_MODE rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -562,10 +561,10 @@ - '{{ subnet_ids[0] }}' - '{{ subnet_ids[1] }}' tags: - "lowercase spaced": 'hello cruel world' - "Title Case": 'Hello Cruel World' - CamelCase: 'SimpleCamelCase' - snake_case: 'simple_snake_case' + lowercase spaced: hello cruel world + Title Case: Hello Cruel World + CamelCase: SimpleCamelCase + snake_case: simple_snake_case check_mode: true register: result @@ -573,7 +572,7 @@ that: - result is changed -- name: 'Update with CamelCase tags' +- name: Update with CamelCase tags rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -582,10 +581,10 @@ - '{{ subnet_ids[0] }}' - '{{ subnet_ids[1] }}' tags: - "lowercase spaced": 'hello cruel world' - "Title Case": 'Hello Cruel World' - CamelCase: 'SimpleCamelCase' - snake_case: 'simple_snake_case' + lowercase spaced: hello cruel world + Title Case: Hello Cruel World + CamelCase: SimpleCamelCase + snake_case: simple_snake_case register: result - assert: @@ -604,7 +603,7 @@ - result.subnet_group.tags["CamelCase"] == 'SimpleCamelCase' - result.subnet_group.tags["snake_case"] == 'simple_snake_case' -- name: 'Do not specify any tag to ensure previous tags are not removed' +- name: Do not specify any tag to ensure previous tags are not removed rds_subnet_group: state: present name: '{{ resource_prefix }}' @@ -633,7 +632,7 @@ # ============================================================ # Deletion -- name: 'Delete a subnet group - CHECK_MODE' +- name: Delete a subnet group - CHECK_MODE rds_subnet_group: state: absent name: '{{ resource_prefix }}' @@ -644,7 +643,7 @@ that: - result is changed -- name: 'Delete a subnet group' +- name: Delete a subnet group rds_subnet_group: state: absent name: '{{ resource_prefix }}' @@ -654,7 +653,7 @@ that: - result is changed -- name: 'Delete a subnet group - CHECK_MODE (idempotency)' +- name: Delete a subnet group - CHECK_MODE (idempotency) rds_subnet_group: state: absent name: '{{ resource_prefix }}' @@ -665,7 +664,7 @@ that: - result is not changed -- name: 'Delete a subnet group (idempotency)' +- name: Delete a subnet group (idempotency) rds_subnet_group: state: absent name: '{{ resource_prefix }}' From e97dcd39ed847f4c861527e19f5035772eb4cfd2 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Thu, 22 Sep 2022 12:23:22 +0200 Subject: [PATCH 18/18] Add changelog fragment --- changelogs/fragments/migrate_rds_subnet_group.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelogs/fragments/migrate_rds_subnet_group.yml diff --git a/changelogs/fragments/migrate_rds_subnet_group.yml b/changelogs/fragments/migrate_rds_subnet_group.yml new file mode 100644 index 00000000000..777aeed4173 --- /dev/null +++ b/changelogs/fragments/migrate_rds_subnet_group.yml @@ -0,0 +1,4 @@ +major_changes: +- rds_subnet_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.rds_subnet_group``.