-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
google_compute_instance resource churn when setting network_interface.subnetwork to a subnetwork name #19339
google_compute_instance resource churn when setting network_interface.subnetwork to a subnetwork name #19339
Comments
The
Couldn't simply recreate this with something like data "google_compute_subnetwork" "default" {
name = "default"
project = var.project_id
}
resource "google_compute_instance" "default" {
name = "test"
machine_type = "n2-standard-2"
zone = var.zone
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
}
}
network_interface {
subnetwork = data.google_compute_subnetwork.default.self_link
}
} Doing something like this shows all of the expected values output "data" {
value = data.google_compute_subnetwork.default.self_link
}
output "instance" {
value = google_compute_instance.default.network_interface.0.subnetwork
} Tried to replicate this on newest provider versions and on 5.43.1 and couldn't hit this issue. Juding by this I'd say that this is an issue caused by something in your environment. Most likely the fact that your Have you tried applying this configuration? If so does the diff persist? TF_LOG=DEBUG terraform plan
TF_LOG=DEBUG terraform apply
#etc. |
@karolgorc oh yes you're right, it's actually the other way around (I'll put that on working late 😂), we are actually setting it to the name of the subnet (with
Yes, we get the diff again after applying.
It's an existing configuration, it happened when upgrading from v5.42 to v5.43.
I'll look at the debug logs tomorrow. 🙏🏻 |
A quick fix that will get rid of the diff would be to replace This happens because the Google API translates the name to self_link outside of terraform when an Instance is created and we suppress that diff here. "subnetwork": {
Type: schema.TypeString,
Optional: true,
Computed: true,
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, // <----- here
Description: `The name or self_link of the subnetwork attached to this interface.`,
}, This suppression works when i'm trying to simulate this provider upgrade and produces an empty plan. My only guess for why it doesn't happen on your configuration is that somehow the state got corrupted when upgrading, not really sure tough. I wonder if you can reproduce this in a sterile environment with a clean configuration. If that quick fix isn't enough for you then providing a clean config with steps to recreate the issue would be ideal 🙂 |
Ok I managed to reproduce it with a simple example, it seems to happen only if you also set terraform {
required_version = "~> 1.9"
required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.43.0"
}
}
}
variable "project_id" {
type = string
default = "my-project"
}
variable "region" {
type = string
default = "us-east1"
}
variable "zone" {
type = string
default = "us-east1-b"
}
provider "google" {
project = var.project_id
}
data "google_compute_subnetwork" "default" {
name = "default"
project = var.project_id
region = var.region
}
resource "google_compute_instance" "default" {
name = "test"
machine_type = "n2-standard-2"
zone = var.zone
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
}
}
network_interface {
subnetwork = data.google_compute_subnetwork.default.name
network_ip = ""
}
}
No diff if I remove |
So it's likely related to #19135 |
It works fine with setting it to |
Yes, we actually have a conditional value on it, which is why it was set to network_interface {
subnetwork = var.subnetwork_name != "" ? var.subnetwork_name : one(google_compute_subnetwork.subnetwork[*].name)
subnetwork_project = var.project
network_ip = var.static_private_ip ? google_compute_address.static-ip-address[count.index].address : ""
} |
Confirmed permadiff issue with the shared configuration |
EDIT: found the issue in our code. not really sure how to explain it but it works after some changes 😄
Fixes to apply until the PR is merged
Will submit a PR with the fix in a few moments |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Community Note
Terraform Version & Provider Version(s)
Terraform v1.9.5
on
amd64
Affected Resource(s)
google_compute_instance
Terraform Configuration
Debug Output
No response
Expected Behavior
No diff for existing
google_compute_instance
resources.Actual Behavior
Steps to reproduce
terraform apply
terraform plan
Important Factoids
No diff with v5.42.0, there was a diff too with v5.43.0 though.
References
Subnetwork names are a valid value according to the documentation: https://registry.terraform.io/providers/hashicorp/google/5.43.1/docs/resources/compute_instance#subnetwork
b/364903020
The text was updated successfully, but these errors were encountered: