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.33k stars 1.74k forks source link

Provider v5 upgrade wants to replace `google_project_service`s #16284

Open matalo33 opened 1 year ago

matalo33 commented 1 year ago

Community Note

Terraform Version

terraform 1.6.1 provider 5.0.0

Affected Resource(s)

Terraform Configuration Files

resource "google_project" "this" {
  name                = "cicd-agents-dev"
  project_id          = "cicd-agents-dev-abcd"
  folder_id           = var.folder_id
  billing_account     = var.billing_account
}

resource "google_project_service" "core" {
  for_each = toset([
    "cloudapis.googleapis.com",
    "compute.googleapis.com",
  ])
  project                    = google_project.this.id
  service                    = each.key
  disable_dependent_services = true
}

Expected Behavior

no-op

Actual Behavior

  # module.project.google_project_service.core["compute.googleapis.com"] must be replaced
-/+ resource "google_project_service" "core" {
      ~ id                         = "cicd-agents-dev-abcd/compute.googleapis.com" -> (known after apply)
      ~ project                    = "cicd-agents-dev-abcd" -> "projects/cicd-agents-dev-abcd" # forces replacement
        # (3 unchanged attributes hidden)
    }

Steps to Reproduce

Upgrading the provider to v5 causes terraform to want to recreate all enabled project services. I confirmed running plan & apply does actually disable the APIs before enabling them again.

It seems this might be because the id attribute of the google_project has changed from <project id> to projects/<project id>

This does not appear to be mentioned in the change log, or the v5 upgrade guide.

Have we done something wrong here, or is this behaviour that others are experiencing? Lastly, what is the best way to work around this issue? Running this apply is obviously very disruptive.

b/306360723

edwardmedia commented 1 year ago

CompareResourceNames is used

jrybak0 commented 1 year ago

To workaround I added a lifecycle argument:

lifecycle {

Workaround for https://github.com/hashicorp/terraform-provider-google/issues/16284

ignore_changes = [project]

}

vishesssh commented 6 months ago

As @edwardmedia mentioned CompareResourceNames is used which is actually taking care of always trimming the id. I couldn't reproduce the issue because I have no service created before this change.

I couldn't find any changelog too as you mentioned. Can you please try to reproduce once again?