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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataCatalog tag update fails when ordered boolean field is present. #16856

Open
whryniewski opened this issue Dec 21, 2023 · 1 comment
Open

Comments

@whryniewski
Copy link

whryniewski commented Dec 21, 2023

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 the modular-magician user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to hashibot, a community member has claimed the issue already.

Terraform Version

Terraform v1.4.6
on darwin_amd64

  • provider registry.terraform.io/hashicorp/google v5.10.0

Affected Resource(s)

  • google_data_catalog_tag

Terraform Configuration Files

terraform {
  required_version = ">= 1.3"

  required_providers {
    google = {
      source  = "hashicorp/google"
      version = ">= 5.10.0"
      
    }
  }
}

resource "google_data_catalog_entry" "entry1" {
  entry_group = google_data_catalog_entry_group.entry_group1.id
  entry_id = "my_entry"

  user_specified_type = "my_custom_type"
  user_specified_system = "SomethingExternal"
}

resource "google_data_catalog_entry_group" "entry_group1" {
  entry_group_id = "my_entry_group"
}

resource "google_data_catalog_tag_template" "tag_template1" {
  tag_template_id = "my_template"
  region = "us-central1"
  display_name = "Demo Tag Template"

  fields {
    field_id = "bool_field"
    display_name = "Number of rows in the data assets"
    type {
      primitive_type = "BOOL"
    }
    order = 1 # must be other than 0 to reproduce

  }

  fields {
    field_id   = "string_field"
    display_name = "String values"
    type {
      primitive_type = "STRING"
    }
    order = 0
  }

  force_delete = "true"
}


resource "google_data_catalog_tag" "basic_tag_wh" {
  parent   = google_data_catalog_entry.entry1.id
  template = google_data_catalog_tag_template.tag_template1.id

  fields {
    field_name   = "bool_field"
    bool_value = false
  }

  fields {
    field_name = "string_field"
    string_value = "fnord" # change value AFTER first application and then re-apply to reproduce the issue
  }

}

Apply above, then change to version below and re-apply:

terraform {
  required_version = ">= 1.3"

  required_providers {
    google = {
      source  = "hashicorp/google"
      version = ">= 5.10.0"
      
    }
  }
}

resource "google_data_catalog_entry" "entry1" {
  entry_group = google_data_catalog_entry_group.entry_group1.id
  entry_id = "my_entry"

  user_specified_type = "my_custom_type"
  user_specified_system = "SomethingExternal"
}

resource "google_data_catalog_entry_group" "entry_group1" {
  entry_group_id = "my_entry_group"
}

resource "google_data_catalog_tag_template" "tag_template1" {
  tag_template_id = "my_template"
  region = "us-central1"
  display_name = "Demo Tag Template"

  fields {
    field_id = "bool_field"
    display_name = "Number of rows in the data assets"
    type {
      primitive_type = "BOOL"
    }
    order = 1 # must be other than 0 to reproduce

  }

  fields {
    field_id   = "string_field"
    display_name = "String values"
    type {
      primitive_type = "STRING"
    }
    order = 0
  }

  force_delete = "true"
}


resource "google_data_catalog_tag" "basic_tag_wh" {
  parent   = google_data_catalog_entry.entry1.id
  template = google_data_catalog_tag_template.tag_template1.id

  fields {
    field_name   = "bool_field"
    bool_value = false
  }

  fields {
    field_name = "string_field"
    string_value = "fnord2" # change value AFTER first application and then re-apply to reproduce the issue
  }

}

Debug Output

https://gist.github.com/whryniewski/6da96db8a2d98266293a0eadb3fb0526

Panic Output

Expected Behavior

Tag should be updated - a request with both string field and bool field should be sent to API.

Actual Behavior

Provider sends a request without bool_value field for boolean field causing error response. This only occurs if bool-type field is NOT changed and string type field is modified.

It seems that

func resourceDataCatalogTagEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
this function removes bool_value field when preparing the request - it does work fine as long as order field is not present in the tag (or is set to 0). Function should count only the keys which names end with "Value" instead of all the keys in the field object.

Steps to Reproduce

  1. terraform apply
  2. Change string tag value to any other
  3. terraform apply

Important Factoids

References

  • #0000

b/318665506

@github-actions github-actions bot added forward/review In review; remove label to forward service/datacatalog labels Dec 21, 2023
@roaks3
Copy link
Collaborator

roaks3 commented Jan 3, 2024

It looks like some of this behavior was explicitly changed with GoogleCloudPlatform/magic-modules#4004, and we most likely missed an edge case.

@roaks3 roaks3 removed the forward/review In review; remove label to forward label Jan 3, 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