Skip to content

Conversation

@jimmycgz
Copy link

@jimmycgz 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, but the original ansible module gcp_compute_subnetwork doesn't throw an error. So this PR suggests adding a condition check in the module and error out for this scenario.

Fixes #560

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

plugins/modules/gcp_compute_subnetwork.py

ADDITIONAL INFORMATION

GCP API will throw an error if found a duplicated subnet name on another vpc when you are trying to create a same-name subnet. Refer the API guide for details. https://cloud.google.com/compute/docs/reference/rest/v1/subnetworks/insert
This PR suggests adding a condition check to error out the above-mentioned scenario, by comparing the intended vpc network in the request vs the vpc found for the existing subnet, and throw an error if it's a different vpc network.

After this suggested change, A fatal error will occur to handle the above-mentioned case. Which tells the user to either change the subnet name to unique or change to a different region.

Copy link
Collaborator

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! there's linting errors which is the main blocker for me.

Otherwise a nit that would be nice to fix, but not a blocker.

@jimmycgz
Copy link
Author

jimmycgz commented Mar 4, 2023

Thanks @toumorokoshi for the suggestion. It looked good to me so I committed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug to handle duplicate subnet across different vpc networks

3 participants