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.36k stars 1.75k forks source link

Missing `update_mask` field in `google_memorystore_instance` resource #20101

Open Desolar1um opened 3 weeks ago

Desolar1um commented 3 weeks ago

Community Note

Terraform Version & Provider Version(s)

Terraform v1.8.5

Affected Resource(s)

google_memorystore_instance

Terraform Configuration

resource "google_memorystore_instance" "valkey-cluster" {
  provider = google-beta
  for_each = local.valkey_clusters

  instance_id = "valkey-${each.key}"
  shard_count = lookup(each.value, "shard_count", 3)
  desired_psc_auto_connections {
    network    = data.google_compute_network.network.id
    project_id = data.google_project.project.project_id
  }
  location                = "europe-west2"
  replica_count           = lookup(each.value, "replica_count", 1)
  node_type               = lookup(each.value, "node_type", "SHARED_CORE_NANO")
  transit_encryption_mode = "TRANSIT_ENCRYPTION_DISABLED"
  authorization_mode      = "AUTH_DISABLED"

  zone_distribution_config {
    mode = "MULTI_ZONE"
  }
  engine_version              = lookup(each.value, "version", "VALKEY_8_0")
  deletion_protection_enabled = false

  labels = {
    redacted
  }
}

data "google_compute_network" "network" {
  name = "network"
}

data "google_project" "project" {
  provider = google
}

Debug Output

│ Error: Error updating Instance "projects/<project>/locations/europe-west2/instances/valkey-cluster": googleapi: Error 400: exactly 1 update_mask field must be specified per update request
│ Details:
│ [
│   {
│     "@type": "type.googleapis.com/google.rpc.BadRequest",
│     "fieldViolations": [
│       {
│         "field": "update_mask"
│       }
│     ]
│   }
│ ]

Expected Behavior

My Valkey cluster should've been decreased from 3 shards 1 replica to 1 shard 0 replicas

Actual Behavior

│ Error: Error updating Instance "projects/<project>/locations/europe-west2/instances/valkey-cluster": googleapi: Error 400: exactly 1 update_mask field must be specified per update request
│ Details:
│ [
│   {
│     "@type": "type.googleapis.com/google.rpc.BadRequest",
│     "fieldViolations": [
│       {
│         "field": "update_mask"
│       }
│     ]
│   }
│ ]

Steps to reproduce

  1. Create valkey cluster using google_memorystore_instance
  2. Attempt to update google_memorystore_instance resource with terraform apply

Important Factoids

No response

References

No response

b/378145653

ggtisc commented 2 weeks ago

Hi @Desolar1um!

I'm trying to replicate this issue but I'm not getting any errors. Because I do not have access to the variables you are using, this was the code I used:

data "google_compute_network" "cn_20101" {
  name = "cn-20101"
}

data "google_project" "project_20101" {
  provider = google-beta
}

resource "google_compute_subnetwork" "subnetwork_20101" {
  provider      = google-beta
  name          = "subnetwork-20101"
  ip_cidr_range = "10.0.0.248/29"
  region        = "us-central1"
  network       = data.google_compute_network.cn_20101.id
}

resource "google_network_connectivity_service_connection_policy" "service_connection_policy_20101" {
  provider      = google-beta
  name          = "service-connection-policy-20101"
  location      = "us-central1"
  service_class = "gcp-memorystore"
  description   = "something"
  network       = data.google_compute_network.cn_20101.id

  psc_config {
    subnetworks = [google_compute_subnetwork.subnetwork_20101.id]
  }
}

resource "google_memorystore_instance" "memorystore_instance_20101" {
  provider = google-beta
  instance_id = "memorystore-instance-20101"
  shard_count = 3

  desired_psc_auto_connections {
    network    = data.google_compute_network.cn_20101.id
    project_id = data.google_project.project_20101.project_id
  }

  location                = "us-central1"
  replica_count           = 1
  node_type               = "SHARED_CORE_NANO"
  transit_encryption_mode = "TRANSIT_ENCRYPTION_DISABLED"
  authorization_mode      = "AUTH_DISABLED"

  zone_distribution_config {
    mode = "MULTI_ZONE"
  }

  engine_version              = "VALKEY_8_0"
  deletion_protection_enabled = false

  labels = {
    "foo" : "bar"
  }
}

Please check it and confirm if it works, I added all necessary resources to use a google_memorystore_instance, like the google_network_connectivity_service_connection_policy. Because if you don't attach it like in the example I'm sharing it is possible that you could get errors when creating the google_memorystore_instance.

If after trying again with these configurations you still have issues please share with us your complete code with the values of the variables and locals you are using to make a new try. You don't need to share sensitive information, for this situations you could use examples like:

Desolar1um commented 2 weeks ago

Hi @ggtisc , thanks for taking the time to look at this!

I don't have problems creating instances, this error occurs when I try to update an instance. Please try decreasing the number of shards/replicas on your instance and let me know if it works.

ggtisc commented 1 week ago

Confirmed issue!

When trying to update labels it returns the following error:

Error updating Instance "projects/my-project/locations/us-central1/instances/memorystore-instance-20101": googleapi: Error 400: exactly 1 update_mask field must be specified per update request

And when trying to decrease the shard_count from 3 to 2 or 1 it returns the following error:

Error updating Instance "projects/my-project/locations/us-central1/instances/memorystore-instance-20101": googleapi: Error 400: 2 shard cluster is not yet supported: invalid argument

himanikh commented 1 week ago

Error updating Instance "projects/my-project/locations/us-central1/instances/memorystore-instance-20101": googleapi: Error 400: exactly 1 update_mask field must be specified per update request

Valkey instance update has a restriction that only one field can be updated at a time. The above error indicates that >1 was changed in one go. Did you try to change any other field along with the labels?

Error updating Instance "projects/my-project/locations/us-central1/instances/memorystore-instance-20101": googleapi: Error 400: 2 shard cluster is not yet supported: invalid argument

Low shard counts have certain limitation today, please follow: https://cloud.google.com/memorystore/docs/valkey/instance-node-specification#selecting_an_instance_shape_of_1_2_or_4_shards