hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.34k stars 1.74k forks source link

google_compute_forwarding_rule should be recreated when used for PSC and target is changing #19189

Open steffencircle opened 2 months ago

steffencircle commented 2 months ago

Community Note

Terraform Version & Provider Version(s)

Terraform v1.5.7 on windows_amd64. linux_amd64

Affected Resource(s)

google_compute_forwarding_rule

Terraform Configuration

resource "google_compute_forwarding_rule" "psc_fwd_rule" {
  name                  = var.psc_consumer_name
  project               = google_compute_address.psc_address.project
  target                = var.psc_consumer_target
  region                = local.landing_zone_region
  network               = data.google_compute_subnetwork.psc_consumer.network
  ip_address            = google_compute_address.psc_address.id
  load_balancing_scheme = ""
}

Debug Output

No response

Expected Behavior

The resource should be re-created when used as a Private Service Connect Endpoint and the value for target gets changed after an initial apply. A Patch is not supported.

From the API docs: For Private Service Connect forwarding rules that forward traffic to managed services, the target must be a service attachment. The target is not mutable once set as a service attachment.

Actual Behavior

The Provider tries to update the resource, which fails with the following error: Error: Error updating ForwardingRule "projects/landing-project/regions/europe-west3/forwardingRules/psc-forwarding-rule-001": googleapi: Error 400: Invalid value for field 'target.target': 'https://compute.googleapis.com/compute/v1/projects/my-project/regions/europe-west3/serviceAttachments/k8s-api-reverse-proxy'. Cross project referencing is not allowed for this resource., invalid

Steps to reproduce

1.) Deploy a Forwarding rule with Target set to a ServiceAttachment 2.) Change the target 3.) Run terraform apply

Important Factoids

No response

References

No response

ggtisc commented 2 months ago

Hi @steffencircle!

You have a couple of things that we don't have access to. To replicate this issue please provide your data, locals and variables values, if they have sensitive information just specify that we can use any value for them. But also consider that by not having this information you will have to double check certain information on your own since we do not have access to those values.

On the other hand: