From 3505b5ac47253e7be1e9961dbfe9c13b080530af Mon Sep 17 00:00:00 2001 From: Jimmy Cui Date: Thu, 2 Mar 2023 15:34:17 -0500 Subject: [PATCH 1/3] fix bug to handle duplicate subnet across different vpc networks --- plugins/modules/gcp_compute_subnetwork.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/modules/gcp_compute_subnetwork.py b/plugins/modules/gcp_compute_subnetwork.py index 3fc7438..7a69d43 100644 --- a/plugins/modules/gcp_compute_subnetwork.py +++ b/plugins/modules/gcp_compute_subnetwork.py @@ -317,6 +317,7 @@ from ansible_collections.google.cloud.plugins.module_utils.gcp_utils import ( ) import json import time +import ipaddress ################################################################################ # Main @@ -353,7 +354,10 @@ def main(): if fetch: if state == 'present': - if is_different(module, fetch): + if module.params['network']['selfLink'] != fetch['network']: # found difference on same subnet within the same VPC network + module.fail_json(msg="Subnet already exists in a different VPC network: %s, please change the name or region" % fetch['network']) + changed = False + elif is_different(module, fetch): update(module, self_link(module), kind, fetch) fetch = fetch_resource(module, self_link(module), kind) changed = True From 46873971a73fad2e8a78006aa3c00c1f6d96026f Mon Sep 17 00:00:00 2001 From: Jimmy Cui Date: Thu, 2 Mar 2023 17:48:35 -0500 Subject: [PATCH 2/3] clean up unneeded import --- plugins/modules/gcp_compute_subnetwork.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/gcp_compute_subnetwork.py b/plugins/modules/gcp_compute_subnetwork.py index 7a69d43..2cd46d5 100644 --- a/plugins/modules/gcp_compute_subnetwork.py +++ b/plugins/modules/gcp_compute_subnetwork.py @@ -317,7 +317,7 @@ from ansible_collections.google.cloud.plugins.module_utils.gcp_utils import ( ) import json import time -import ipaddress + ################################################################################ # Main From 5a2a6f2931120dd5423abd75c83d188a8fc21b8c Mon Sep 17 00:00:00 2001 From: Jimmy CUI <38402619+jimmycgz@users.noreply.github.com> Date: Sat, 4 Mar 2023 13:17:01 -0500 Subject: [PATCH 3/3] Update plugins/modules/gcp_compute_subnetwork.py Co-authored-by: Yusuke Tsutsumi --- plugins/modules/gcp_compute_subnetwork.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/gcp_compute_subnetwork.py b/plugins/modules/gcp_compute_subnetwork.py index 2cd46d5..67beafb 100644 --- a/plugins/modules/gcp_compute_subnetwork.py +++ b/plugins/modules/gcp_compute_subnetwork.py @@ -355,7 +355,7 @@ def main(): if fetch: if state == 'present': if module.params['network']['selfLink'] != fetch['network']: # found difference on same subnet within the same VPC network - module.fail_json(msg="Subnet already exists in a different VPC network: %s, please change the name or region" % fetch['network']) + module.fail_json(msg="Subnet already exists in a different VPC network: %s" % fetch['network']) changed = False elif is_different(module, fetch): update(module, self_link(module), kind, fetch)