Skip to content
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

BadRequest error when updating google_spanner_instance with labels set at provider level #18445

Open
ab-verily opened this issue Jun 14, 2024 · 1 comment

Comments

@ab-verily
Copy link

ab-verily commented Jun 14, 2024

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
  • Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.
  • If an issue is assigned to a user, that user is claiming responsibility for the issue.
  • Customers working with a Google Technical Account Manager or Customer Engineer can ask them to reach out internally to expedite investigation and resolution of this issue.

Terraform Version & Provider Version(s)

Terraform v1.8.5
on linux_amd64
+ provider registry.terraform.io/hashicorp/google v5.33.0
+ provider registry.terraform.io/hashicorp/google-beta v5.33.0

Affected Resource(s)

google_spanner_instance

Terraform Configuration

Current config:

provider "google" {
  project = local.project_id
  region  = local.region
}

resource "google_spanner_instance" "default" {
  project      = local.project_id
  config       = "regional-${local.region}"
  display_name = "instance-01"
  name         = "instance-01"
  num_nodes    = 1
}

New config I want to apply (set labels at the provider level):

provider "google" {
  project = local.project_id
  region  = local.region

  default_labels = {
    "label1" = "value1"
    "label2" = "value2"
  }
}

resource "google_spanner_instance" "default" {
  project      = local.project_id
  config       = "regional-${local.region}"
  display_name = "instance-01"
  name         = "instance-01"
  num_nodes    = 1
}

Debug Output

https://gist.github.com/ab-verily/e33b3eeb92cfea611d0ae00eeed121f4

Expected Behavior

The google_spanner_instance resource should have been updated with the labels set at the provider level.

Expected API request (with fieldMask set):

PATCH /v1/projects/project/instances/instance-01?alt=json HTTP/1.1
Host: spanner.googleapis.com
User-Agent: Terraform/1.8.5 (+https://www.terraform.io) Terraform-Plugin-SDK/2.33.0 terraform-provider-google/5.33.0
...
 {
  "fieldMask": "labels",
  "instance": {
   "displayName": "instance-01",
   "labels": {
    "label1": "value1",
    "label2": "value2"
   },
   "name": "projects/project/instances/%!s(\u003cnil\u003e)",
   "nodeCount": 1,
   "processingUnits": 1000
  }
 }

Actual Behavior

Apply Error:

Error: Error updating Instance "project/instance-01": googleapi: Error 400: Invalid UpdateInstance request.
Details:
[
  {
    "@type": "type.googleapis.com/google.rpc.BadRequest",
    "fieldViolations": [
      {
        "description": "Must specify a non-empty field mask.",
        "field": "field_mask"
      }
    ]
  },
  {
    "@type": "type.googleapis.com/google.rpc.DebugInfo",
    "detail": "[ORIGINAL ERROR] generic::invalid_argument: Invalid UpdateInstance request. [google.rpc.error_details_ext] { message: \"Invalid UpdateInstance request.\" details { [type.googleapis.com/google.rpc.BadRequest] { field_violations { field: \"field_mask\" description: \"Must specify a non-empty field mask.\" } } } } 485239697 { 1: \"Invalid UpdateInstance request.\" 2 { 2: \"Invalid [REDACTED] request.\" 3 { 1: \"type.googleapis.com/google.rpc.BadRequest\" 2 { 1 { 1: \"field_mask\" 2: \"Must specify a non-empty field mask.\" } } } } }"
  }
]

Actual API request (with empty fieldMask):

PATCH /v1/projects/project/instances/instance-01?alt=json HTTP/1.1
Host: spanner.googleapis.com
User-Agent: Terraform/1.8.5 (+https://www.terraform.io) Terraform-Plugin-SDK/2.33.0 terraform-provider-google/5.33.0
...
 {
  "fieldMask": "",
  "instance": {
   "displayName": "instance-01",
   "labels": {
    "label1": "value1",
    "label2": "value2"
   },
   "name": "projects/project/instances/%!s(\u003cnil\u003e)",
   "nodeCount": 1,
   "processingUnits": 1000
  }
 }

Steps to reproduce

  1. Create google_spanner_instance resource:
provider "google" {
  project = local.project_id
  region  = local.region
}

resource "google_spanner_instance" "default" {
  project      = local.project_id
  config       = "regional-${local.region}"
  display_name = "instance-01"
  name         = "instance-01"
  num_nodes    = 1
}
  1. Plan & Apply

  2. Change config to set labels at the provider level:

provider "google" {
  project = local.project_id
  region  = local.region

  default_labels = {
    "label1" = "value1"
    "label2" = "value2"
  }
}

resource "google_spanner_instance" "default" {
  project      = local.project_id
  config       = "regional-${local.region}"
  display_name = "instance-01"
  name         = "instance-01"
  num_nodes    = 1
}
  1. Plan:
Terraform will perform the following actions:

  # google_spanner_instance.default will be updated in-place
  ~ resource "google_spanner_instance" "default" {
      ~ effective_labels = {
          + "label1" = "value1"
          + "label2" = "value2"
        }
        id               = "project/instance-01"
        name             = "instance-01"
      ~ terraform_labels = {
          + "label1" = "value1"
          + "label2" = "value2"
        }
        # (8 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
  1. Apply:
Error: Error updating Instance "project/instance-01": googleapi: Error 400: Invalid UpdateInstance request.
Details:
[
  {
    "@type": "type.googleapis.com/google.rpc.BadRequest",
    "fieldViolations": [
      {
        "description": "Must specify a non-empty field mask.",
        "field": "field_mask"
      }
    ]
  },
  {
    "@type": "type.googleapis.com/google.rpc.DebugInfo",
    "detail": "[ORIGINAL ERROR] generic::invalid_argument: Invalid UpdateInstance request. [google.rpc.error_details_ext] { message: \"Invalid UpdateInstance request.\" details { [type.googleapis.com/google.rpc.BadRequest] { field_violations { field: \"field_mask\" description: \"Must specify a non-empty field mask.\" } } } } 485239697 { 1: \"Invalid UpdateInstance request.\" 2 { 2: \"Invalid [REDACTED] request.\" 3 { 1: \"type.googleapis.com/google.rpc.BadRequest\" 2 { 1 { 1: \"field_mask\" 2: \"Must specify a non-empty field mask.\" } } } } }"
  }
]

Important Factoids

No response

References

No response

b/348054862

@ab-verily ab-verily added the bug label Jun 14, 2024
@github-actions github-actions bot added forward/review In review; remove label to forward service/spanner labels Jun 14, 2024
@ggtisc ggtisc self-assigned this Jun 18, 2024
@ggtisc
Copy link
Collaborator

ggtisc commented Jun 18, 2024

Confirmed issue!

Following the indications if the resource is created with config1 and then updated at provider level it returns an error 400: Invalid UpdateInstance request. It is the same for any change at provider level.

@ggtisc ggtisc removed their assignment Jun 18, 2024
@ggtisc ggtisc removed the forward/review In review; remove label to forward label Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants