-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
When creating a service networking connection resource, check if Create or Update is needed #16697
Comments
Note: we should work w/ the service owners to determine how to untangle these resources. The move from upsert/abandon to create/delete in |
@rileykarson Is there any update on how to fix this. |
Would reverting it to using patch as prior to #15761 be acceptable? |
For now, that is what we're doing. But doing that prevents us from using newer features like datastore scheduled backups. |
Unfortunately, it is a breaking change to revert it and cannot do in the minor release version. |
@Esquire-gh, can you please provide more details what are you doing now and how does it prevent you from using the new features? |
Is there any update on this, this is preventing anyone who recreates service networking connections updating the package past the 5.0 migration |
Forward the ticket to the service team. |
Is there any known workaround? We're just starting to migrate from MySQL to Postgres and this is a hard showstopper for us. |
@muffl0n , only one networking connection is needed between one network and the service producer.
https://cloud.google.com/vpc/docs/configure-private-services-access#creating-connection Once the networking connection exists, you don't need to create another networking connection for the same network. |
Thank you very much for the clarification! Must have misunderstood the scope of this issue. |
Hi, this problem is bugging me also. I hope the check to create or update is coming soon. This is my Terraform plan (it is redacted to not include personal data):
But I got this error all the time now:
I do not understand exactly what is going wrong, because I thought the private Service Networking Connection is not yet existing in the project. So how can it complain about not been able to create? There are no Service network connection's if I look in the console: And I am able to create the one I want Terraform to make, see: Am I missing something, or do I misunderstand something? I would really like to know, thank you. |
For now I've manually fixed the problem by force modify the connection, like so: gcloud services vpc-peerings update --service=servicenetworking.googleapis.com --ranges=service-1-private-ip-block --network=staging-version-2020-network --project=REDACTED --force This resulted in a working configuration: |
Strange thing is that before the forces manual modification, I tried to list the connections but I got an empty list: $ gcloud services vpc-peerings list \
> --network=staging-version-2020-network \
> --project=REDACTED
After the modification it seems alright: $ gcloud services vpc-peerings list \
> --network=staging-version-2020-network \
> --project=REDACTED
---
network: projects/REDACTED/global/networks/staging-version-2020-network
peering: servicenetworking-googleapis-com
reservedPeeringRanges:
- service-1-private-ip-block
service: services/servicenetworking.googleapis.com
I am a bit lost here, what was wrong in the first place then? Why did I get an error saying I could not create the resource but I had to use update the existing resource? It seems to me there was no existing resource! |
After manually fixing the configuration within the Google cloud console, I had to import this into Terraform. After that all was correct again. See: $ terraform import module.network.google_service_networking_connection.private_vpc_connection[0] projects/REDACTED/global/networks/staging-version-2020-network:servicenetworking.googleapis.com
data.google_client_config.default: Reading...
module.network.google_service_networking_connection.private_vpc_connection[0]: Importing from ID "projects/REDACTED/global/networks/staging-version-2020-network:servicenetworking.googleapis.com"...
module.network.google_service_networking_connection.private_vpc_connection[0]: Import prepared!
Prepared google_service_networking_connection for import
module.network.google_service_networking_connection.private_vpc_connection[0]: Refreshing state... [id=projects/REDACTED/global/networks/staging-version-2020-network:servicenetworking.googleapis.com]
data.google_client_config.default: Read complete after 0s [id=projects/"REDACTED"/regions/"europe-REDACTED"/zones/<null>]
Import successful!
The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
|
Not totally as expected... After the import, I tried a module.network.google_service_networking_connection.private_vpc_connection[0]: Refreshing state... [id=projects/REDACTED/global/networks/staging-version-2020-network:servicenetworking.googleapis.com]
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement
Terraform will perform the following actions:
# module.network.google_service_networking_connection.private_vpc_connection[0] must be replaced
-/+ resource "google_service_networking_connection" "private_vpc_connection" {
~ id = "projects/REDACTED/global/networks/staging-version-2020-network:servicenetworking.googleapis.com" -> (known after apply)
~ network = "projects/REDACTED/global/networks/staging-version-2020-network" -> "projects/REDACTED/global/networks/staging-version-2020-network" # forces replacement
~ peering = "servicenetworking-googleapis-com" -> (known after apply)
# (2 unchanged attributes hidden)
}
Plan: 1 to add, 0 to change, 1 to destroy. I am going to try to apply this... YES it works! The connection was first destroyed successfully and after that successfully created! |
Has the private service networking connection with the same network been created and destroyed with terraform? I wonder if that is the reason. There was a bug that the private service networking connection could be abandoned instead of deleted in Terraform provider. |
@rh4ll , only one networking connection is needed between one network and the service producer. |
Hi @zli82016 Thank you for the clarification! Yes indeed, the resource had been created, deleted, and re-created again. And I think the first creation and deletions was done by the provider version 4.x. |
@zli82016 We use service networking connection as part of our config to reserve internal ip addresses. An example config from the docs is show below
Everytime we try to update the reserved perring ranges, we run into the issue of What do you suggest in this case? It would be nice if the resource If these exist and I'm not aware, I would appreciate a link to their docs. Thank you. |
@Esquire-gh, can you run this command to see if the service networking connection already exists?
Or has the service networking connection been created and deleted before with provider 4.x? |
@zli82016 Yes, the service networking connection already exists |
@Esquire-gh , just want to confirm that if the following is your use case? |
@zli82016 Yes, the service networking connection exists in one project (shared network). |
@Esquire-gh , does updating the reserved ip ranges for the service networking connection in the first project (shared network) work? |
@zli82016 No it does not. that is what we are trying to do. |
@Esquire-gh , I don't understand the case completely. If other projects need an ip address reserved in the shared network, can you get the ip address with the data source Can you please provide the configurations in the first project (shared network) and the second project (memorystore) and where you are trying to update the connection? Thanks. |
In my case, the provider has been previously deleted in 4.x version, so what you are saying is it will be impossible to create a service networking connection in a project where it has been deleted in provider <5.0.0? |
@zli82016 Unfortunately the first project was created manually in the console. But in the second project we have a configuration for redis the is similar to this. https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/redis_instance#example-usage---redis-instance-private-service We use this because we want to use internal ip addresses instead of external ips. We also have to set the But becuase there isn't a Manually updating this will be difficult becuase we create several environments in our system al they all have a redis instance on the shared network. |
@rh4ll and @Esquire-gh , I am so sorry for the issue. We plan to make a fix in the provider 6.0. There is a workaround in provider 5.x. Hope it work for your cases.
|
Awesome! Thank you for the work around. I'll give that a go tomorrow. |
@zli82016 Thank you! |
For the service networking connection removed with To handle this case, we consider changing back to use |
@zli82016 Thank you. Looking forward to the upgrade. |
Community Note
Description
After Terraform google provider 5.0, google_service_networking_connection uses the Create endpoint instead of the Patch endpoint during the creation step. If a service networking connection has been already created for the given network, an error is returned from API when creating another service networking connection because only one google_service_networking_connection is allowed for one network.
Error waiting for Create Service Networking Connection: Error code 9, message: Cannot modify allocated ranges in CreateConnection. Please use UpdateConnection.
The improvement can be made that when creating a service networking connection resource, check if Create or Update is needed.
Edit: For the service networking connection removed with
removePeering
with Terraform provider earlier than 5.0, when recreating the connection with the same network and different reserved ranges with Terraform provider 5.x, the error is returned from API side. But it is empty to get/list the connections.Error waiting for Create Service Networking Connection: Error code 9, message: Cannot modify allocated ranges in CreateConnection. Please use UpdateConnection.
To handle this case, we consider changing back to use
PATCH
when creating the resource in Terraform provider 6.0.New or Affected Resource(s)
Potential Terraform Configuration
References
b/331798129
The text was updated successfully, but these errors were encountered: