Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug to handle duplicate subnet across different vpc networks #560

Open
jimmycgz opened this issue Mar 2, 2023 · 0 comments · May be fixed by #561
Open

Bug to handle duplicate subnet across different vpc networks #560

jimmycgz opened this issue Mar 2, 2023 · 0 comments · May be fixed by #561
Labels
bug Something isn't working

Comments

@jimmycgz
Copy link

jimmycgz commented Mar 2, 2023

SUMMARY

GCP doesn't allow to create any subnet with the same name in the same region if already exists in any other VPC network, and the original module doesn't throw error. This PR suggests adding a condition check and error out for this scenario.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

plugins/modules/gcp_compute_subnetwork.py

ANSIBLE VERSION
ansible [core 2.14.2]
  config file = /Users/x/proj/hands-on/ansible/sbn-bug-ansible/playbooks/ansible.cfg
  configured module search path = ['/Users/x/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/x/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.16 (main, Dec  7 2022, 10:16:11) [Clang 14.0.0 (clang-1400.0.29.202)] (/usr/local/opt/[email protected]/bin/python3.9)
  jinja version = 3.0.1
  libyaml = True

COLLECTION VERSION
nothing special, just local ansible.cfg
CONFIGURATION
ansible [core 2.14.2]
OS / ENVIRONMENT

MacOS 13.0 (22A380)

STEPS TO REPRODUCE

#A1: create a network vpc-a
#A2: create a subnetwork subnet-a in vpc-a
#B1: create another network vpc-b
#B2: create a same-name subnetwork subnet-a in vpc-b

---
- name: Define variables
  set_fact:
    project: your-project-name
    region: us-east4
    gcp_auth_kind: application

- name: "#A1: create a network vpc-a"
  google.cloud.gcp_compute_network:
    name: "vpc-a"
    auto_create_subnetworks: 'false'
    project: "{{ project }}"
    auth_kind: "{{ gcp_auth_kind }}"
    state: present
  register: network_a

- name: "#A2: create a subnetwork subnet-a in vpc-a"
  google.cloud.gcp_compute_subnetwork:
    name: "subnet-a"
    region: "{{ region }}"
    network: "{{ network_a }}"
    ip_cidr_range: 172.16.0.0/20
    project: "{{ project }}"
    auth_kind: "{{ gcp_auth_kind }}"
    state: present

- name: "#B1: create another network vpc-b"
  google.cloud.gcp_compute_network:
    name: "vpc-b"
    auto_create_subnetworks: 'false'
    project: "{{ project }}"
    auth_kind: "{{ gcp_auth_kind }}"
    state: present
  register: network_b

- name: "#B2: create a same name subnetwork subnet-a in vpc-b"
  google.cloud.gcp_compute_subnetwork:
    name: "subnet-a"
    region: "{{ region }}"
    network: "{{ network_b }}"
    ip_cidr_range: 172.16.0.0/20
    project: "{{ project }}"
    auth_kind: "{{ gcp_auth_kind }}"
    state: present    
EXPECTED RESULTS

Task #B2 should throw an error saying the same name subnet already exists in another VPC network (vpc-a).

ACTUAL RESULTS

The original module finds the subnet and shows it on a different VPC network (vpc-a), and continues to call the Update() function and actually does nothing. No any error and no any subnet created at vpc-b.

changed: [localhost] => {
    "changed": true,
    "creationTimestamp": "2023-03-02T05:37:59.024-08:00",
    "fingerprint": "HQ6lQkX4WFI=",
    "gatewayAddress": "172.16.0.1",
    "id": "8170811963898402904",
    "invocation": {
        "module_args": {
            "auth_kind": "application",
            "description": null,
            "env_type": null,
            "ip_cidr_range": "172.16.0.0/13",
            "name": "subnet-a",
            "network": {
                "ansible_facts": {
                    "discovered_interpreter_python": "/usr/local/bin/python3.11"
                },
                "autoCreateSubnetworks": false,
                "changed": false,
                "creationTimestamp": "2023-03-01T08:54:08.590-08:00",
                "failed": false,
                "id": "2564930274501737951",
                "kind": "compute#network",
                "name": "vpc-b",
                "networkFirewallPolicyEnforcementOrder": "AFTER_CLASSIC_FIREWALL",
                "routingConfig": {
                    "routingMode": "REGIONAL"
                },
                "selfLink": "https://www.googleapis.com/compute/v1/projects/xx-demo/global/networks/vpc-b",
                "selfLinkWithId": "https://www.googleapis.com/compute/v1/projects/xx-demo/global/networks/2564930274501737951",
                "subnetworks": [
                ],
                "warnings": [
                    ..
                ]
            },
            "private_ip_google_access": false,
            "private_ipv6_google_access": null,
            "project": "xx-demo",
            "region": "us-east4",
            "scopes": [
                "https://www.googleapis.com/auth/compute"
            ],
            "secondary_ip_ranges": null,
            "service_account_contents": null,
            "service_account_email": null,
            "service_account_file": null,
            "state": "present"
        }
    },
    "ipCidrRange": "172.16.0.0/14",
    "kind": "compute#subnetwork",
    "name": "subnet-a",
    "network": "https://www.googleapis.com/compute/v1/projects/xx-demo/global/networks/vpc-a",
    "privateIpGoogleAccess": false,
    "privateIpv6GoogleAccess": "DISABLE_GOOGLE_ACCESS",
    "purpose": "PRIVATE",
    "region": "https://www.googleapis.com/compute/v1/projects/xx-demo/regions/us-east4",
    "selfLink": "https://www.googleapis.com/compute/v1/projects/xx-demo/regions/us-east4/subnetworks/subnet-a",
    "stackType": "IPV4_ONLY"
}
@toumorokoshi toumorokoshi added the bug Something isn't working label Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants