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.29k stars 1.72k forks source link

Permadiff on google_cloud_quotas_quota_preference with multiple fields #19202

Open roaks3 opened 3 weeks ago

roaks3 commented 3 weeks ago

Community Note

Terraform Version & Provider Version(s)

Terraform vX.X.X on

Affected Resource(s)

google_cloud_quotas_quota_preference

Terraform Configuration

resource "google_cloud_quotas_quota_preference" "preference" {
  parent        = "projects/${google_project.proj.project_id}"
  service       = "aiplatform.googleapis.com"
  quota_id      = "FeatureStoreOnlineServingNodes"
  dimensions    = { region = "us-central1" }
  contact_email = "example@gmail.com"
  quota_config {
    preferred_value = 60
  }
}

Debug Output

No response

Expected Behavior

  1. terraform apply creates the Quota preference
  2. next terraform apply shows no changes

Actual Behavior

  1. terraform apply creates the Quota preference
  2. next terraform apply shows diff:

    ~ resource "google_cloud_quotas_quota_preference" "preference" {
      ~ dimensions           = {
          + "region" = "us-central1"
        }
        id                   = "projects/myproj/locations/global/quotaPreferences/"
      + quota_id             = "FeatureStoreOnlineServingNodes"
      + service              = "aiplatform.googleapis.com"
        # (4 unchanged attributes hidden)
    
      + quota_config {
          + preferred_value = "60"
        }
    }

Steps to reproduce

  1. terraform apply

Important Factoids

These fields should most likely be changed to ignore_read: true, as I assume they aren't returned in the API.

However, the workaround is to use ignore_changes:

resource "google_cloud_quotas_quota_preference" "preference" {
  ...
  lifecycle {
    ignore_changes = [
      dimensions["region"],
      quota_id,
      service,
      quota_config
    ]
  }
}

References

No response

b/361347182

derhally commented 3 weeks ago

I just ran into this today with TPG 5.30.0 and the following example

resource "google_cloud_quotas_quota_preference" "ssd_storage" {
  parent        = "projects/${var.project_id}"
  service       = "compute.googleapis.com"
  quota_id      = "SSD-TOTAL-GB-per-project-region"
  dimensions    = { region = "us-east4" }
  contact_email = "foo@bar.com"
  quota_config {
    preferred_value = 100000
  }
}

received similar permadiff

  # google_cloud_quotas_quota_preference.ssd_storage will be updated in-place
  ~ resource "google_cloud_quotas_quota_preference" "ssd_storage" {
      ~ dimensions           = {
          + "region" = "us-east4"
        }
        id                   = "projects/redacted-proj-id/locations/global/quotaPreferences/"
      + quota_id             = "SSD-TOTAL-GB-per-project-region"
      + service              = "compute.googleapis.com"
        # (4 unchanged attributes hidden)

      + quota_config {
          + preferred_value = "100000"
        }
    }

Terraform state shows incorrect values for several arguments.

{
      "mode": "managed",
      "type": "google_cloud_quotas_quota_preference",
      "name": "ssd_storage",
      "provider": "provider[\"registry.terraform.io/hashicorp/google\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "contact_email": "<redacted>",
            "create_time": "",
            "dimensions": {},
            "etag": "",
            "id": "projects/<redacted>/locations/global/quotaPreferences/",
            "ignore_safety_checks": "QUOTA_SAFETY_CHECK_UNSPECIFIED",
            "justification": null,
            "name": "",
            "parent": "projects/<redacted>",
            "quota_config": [],
            "quota_id": "",
            "reconciling": false,
            "service": "",
            "timeouts": null,
            "update_time": ""
          },
          "sensitive_attributes": [],
          "private": "<redacted>"
        }
      ]
    }