Closed eandresr closed 1 week ago
@eandresr I am not super clear about what the problem is. From the title of this issue, it says when updating
. But in the expected behavior, we shold have it with no changes between redeploys
.
Could you please create a simple config (without dynamic code) and detail the steps, so I can repro the issue?
Hello, what I mean is that if we have separated projects (one for compute and other for networking), with vpc's and subnets on the networking project and shared to the compute, we can deploy something like the following:
Key concepts:
resource "google_service_account" "default" {
account_id = "service_account_id"
display_name = "Service Account"
}
resource "google_compute_instance" "default" {
name = "test"
machine_type = "e2-medium"
zone = "us-central1-a"
project = "compute-project-example"
tags = ["foo", "bar"]
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
labels = {
my_label = "value"
}
}
}
network_interface {
subnetwork = "projects/networking-project-example/regions/europe-southwest1/subnetworks/example-subnetwork"
subnetwork_project = "compute-project-example"
access_config {
// Ephemeral public IP
}
}
service_account {
# Google recommends custom service accounts that have cloud-platform scope and permissions granted via IAM Roles.
email = google_service_account.default.email
scopes = ["cloud-platform"]
}
}
Notice:
Well, if we apply this for the first time, the instance will be created as expected, but if we plan again with the same parameters (nothing changed), it will try to change the subnetwork because it will read the subnetwork_project even if we still have the self_link specified in the "subnetwork" attribute. Hopefully it will not change anything but it will restart the instance as it will be recognized as networking change (with no real change). Obviously Terraform will prompt you that the network project will change by the specified en the attribute subnetwork_project (but it won't be changed, just re configured with the same self_link as expected but with an unneccesary stop and start).
the important thing is that the README (the Help Document) says that if we specify self_link in the subnetwork, the attribute subnetwork_project will be ignored, but it is not ignored at all, it is just not used in the final configuration but recognized as change by the provider.
@shuyama1 I am not sure if we continue recommending self_link in the doc. What do you think?
@shuyama1 I am not sure if we continue recommending self_link in the doc. What do you think?
At least it should say that even if self_link is provided, subnetwork_project will be breaded. But the best would be the condition in the provider...
Tried suppressing this diff but it get's complicated because we are trying to suppress a diff on subnetwork_project
based on the value of subnetwork
. This case gets loaded with edge cases when trying to make it work on multiple network interfaces.
The doc change seems reasonable but we should keep in mind that this config isn't really correct. The subnetwork_project
field IS ignored and set to whatever is in the self_link that was provided in subnetwork
but your code still has the wrong project so it will show diff. So i'd say that this works as intended.
Community Note
modular-magician
user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned tohashibot
, a community member has claimed the issue already.Terraform Version
Affected Resource(s)
Terraform Configuration Files
Debug Output
Panic Output
Expected Behavior
If we are using shared VPC's and subnets from a external project, set in the subnetwork as a self_link, and we do not specify the project_id in the subnetwork_project, we shold have it with no changes between redeploys because as the README says:
Actual Behavior
Terraform recognizes changes in the networking because it recognizes the subnetwork_project also and tries to reconfigure it (with the same values configured before, correct ones). Even if the selected subnetwork_project is not the specyfied in the subnetwork self_link it applies the correct in the apply, BUT it restarts the instance. So actually the paragraph in the README saying subnetwork_project is ignored when subnetwork is a self_link is not correct and MAY CAUSE SERVICE INTERRUPTIONS (not configuration problems).
Steps to Reproduce
terraform apply
of a resource with both: subnetwork_project and subnetwork attributes in the network_interface blockImportant Factoids
We have shared VPCs
References
b/309764660