From caaad8917969cae6190d57f5cb1832cc930b4cf8 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 24 Nov 2023 16:11:02 +0100 Subject: [PATCH] pass TagSpecifications only if tags are set (not {} and not None) --- changelogs/fragments/1843-ec2_vpc_subnet.yml | 2 ++ plugins/modules/ec2_eip.py | 4 ++-- plugins/modules/ec2_vpc_igw.py | 2 +- plugins/modules/ec2_vpc_subnet.py | 6 ++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/changelogs/fragments/1843-ec2_vpc_subnet.yml b/changelogs/fragments/1843-ec2_vpc_subnet.yml index a1f1db6e256..2fce4878c19 100644 --- a/changelogs/fragments/1843-ec2_vpc_subnet.yml +++ b/changelogs/fragments/1843-ec2_vpc_subnet.yml @@ -1,2 +1,4 @@ minor_changes: - ec2_vpc_subnet - use ``ResourceTags`` to set initial tags upon creation (https://github.com/ansible-collections/amazon.aws/issues/1843) +- ec2_vpc_subnet - the default value for ``tags`` has been changed from ``{}`` to ``None``, to remove tags from a subnet an empty map must + be explicitly passed to the module (https://github.com/ansible-collections/amazon.aws/pull/1876). diff --git a/plugins/modules/ec2_eip.py b/plugins/modules/ec2_eip.py index c22fa739f3e..38bf32c87a3 100644 --- a/plugins/modules/ec2_eip.py +++ b/plugins/modules/ec2_eip.py @@ -392,7 +392,7 @@ def allocate_address( ) params = {"Domain": domain} - if tags is not None: + if tags: params["TagSpecifications"] = boto3_tag_specifications(tags, types="elastic-ip") try: @@ -538,7 +538,7 @@ def allocate_address_from_pool( if public_ipv4_pool is not None: params["PublicIpv4Pool"] = public_ipv4_pool - if tags is not None: + if tags: params["TagSpecifications"] = boto3_tag_specifications(tags, types="elastic-ip") try: diff --git a/plugins/modules/ec2_vpc_igw.py b/plugins/modules/ec2_vpc_igw.py index 11c8e551938..428de396e1f 100644 --- a/plugins/modules/ec2_vpc_igw.py +++ b/plugins/modules/ec2_vpc_igw.py @@ -313,7 +313,7 @@ def ensure_igw_present(self, igw_id, vpc_id, tags, purge_tags, force_attach, det try: create_params = {} - if tags is not None: + if tags: create_params["TagSpecifications"] = boto3_tag_specifications(tags, types="internet-gateway") response = self._connection.create_internet_gateway(aws_retry=True, **create_params) diff --git a/plugins/modules/ec2_vpc_subnet.py b/plugins/modules/ec2_vpc_subnet.py index 877f9d236f9..ad064fd9350 100644 --- a/plugins/modules/ec2_vpc_subnet.py +++ b/plugins/modules/ec2_vpc_subnet.py @@ -72,8 +72,6 @@ - Ignored unless I(wait=True). default: 300 type: int - tags: - default: {} extends_documentation_fragment: - amazon.aws.common.modules - amazon.aws.region.modules @@ -280,7 +278,7 @@ def create_subnet(conn, module, vpc_id, cidr, tags, ipv6_cidr=None, outpost_arn= if az: params["AvailabilityZone"] = az - if tags is not None: + if tags: params["TagSpecifications"] = boto3_tag_specifications(tags, types="subnet") if outpost_arn: @@ -554,7 +552,7 @@ def main(): ipv6_cidr=dict(default="", required=False), outpost_arn=dict(default="", type="str", required=False), state=dict(default="present", choices=["present", "absent"]), - tags=dict(default={}, required=False, type="dict", aliases=["resource_tags"]), + tags=dict(required=False, type="dict", aliases=["resource_tags"]), vpc_id=dict(required=True), map_public=dict(default=False, required=False, type="bool"), assign_instances_ipv6=dict(default=False, required=False, type="bool"),