Open teyuchang opened 2 months ago
Hi @teyuchang!
I used exactly your same code, terraform version(0.13.7) and Google provider version(4.84.0) and followed your steps to reproduce this issue:
But I didn't get any error or the behavior you commented. Are there other configurations or resources involved, or do I need to wait more than a minute after creation to run `terraform destroy?
Thank you for testing. Unfortunately, this bug is flaky and may not happen every time. The key factor in reproducing it is the time it takes to delete the router – a longer deletion time makes it more likely to happen. To consistently reproduce it, you can use a test stub instead of actual GCP endpoints and intentionally delay the router deletion process.
Here's a simplified version of how the Terraform example works:
Creation(terraform apply
):
Deletion(terraform destroy
):
delete_swg_autogen_router_on_destroy
is set to true).The problem occurs during step 1 of the deletion process. Terraform attempts to delete the router but doesn't wait for the long-running operation to finish. This means the router might still exist when Terraform tries to delete the VPC in step 3, causing the VPC deletion to fail.
The relevant code is in deleteSWGAutoGenRouter. The response is ignored using _
. Instead, it should be handled similarly to the code in resourceNetworkServicesGatewayDelete, where the response is captured in a res
variable and the operation is waited upon, as shown here.
Confirmed issue, as the user reports the more time we wait to delete the resources triggers this behavior. After waiting more than 12 hrs and running a terraform destroy
it returns the specified message:
Error: Error waiting for Deleting Network: The network resource 'projects/xxx/global/networks/my-network' is already being used by 'projects/xxx/regions/us-central1/routers/swg-autogen-router-1234567890'
Community Note
Terraform Version & Provider Version(s)
Terraform v0.13.7 on linux/amd64
Affected Resource(s)
google_network_services_gateway
Terraform Configuration
Debug Output
No response
Expected Behavior
The function deleteSWGAutoGenRouter should wait until the operation finishes.
Actual Behavior
deleteSWGAutoGenRouter returns immediately after it sends a Delete request without waiting the operation to finish. It sometimes results in
terraform destroy
failureSteps to reproduce
terraform apply
terraform destroy
Important Factoids
No response
References
No response
b/342170266