terraform-provider-googleworkspace icon indicating copy to clipboard operation
terraform-provider-googleworkspace copied to clipboard

Handle LABEL_REPEATED proto Label in type validation

Open Yohan460 opened this issue 2 years ago • 2 comments

When defining chrome policies and doing the field interpretation the label proto field has the option of being returned as a LABEL_REPEATED which requires the value to be an array of the defined type.

This PR fixes the validation function upon the label being that LABEL_REPEATED option as well as adds some more verbose erroring to call out specific values not complying with the spec.

An example chrome policy schema with hits this issue is the chrome.users.UrlBlocking policy which has the following definition

"definition": {
  "messageType": [
   {
    "field": [
     {
      "label": "LABEL_REPEATED",
      "name": "urlBlocklist",
      "number": 1,
      "type": "TYPE_STRING"
     },
     {
      "label": "LABEL_REPEATED",
      "name": "urlAllowlist",
      "number": 2,
      "type": "TYPE_STRING"
     }
    ],
    "name": "UrlBlocking"
   }
  ]
 }

Allowing the following resource definitions to work

resource "googleworkspace_org_unit" "bleh" {
  name                 = "bleh"
  parent_org_unit_path = "/"
}

resource "googleworkspace_chrome_policy" "url_blocklist" {
  org_unit_id = googleworkspace_org_unit.bleh.id
  policies {
   schema_name = "chrome.users.UrlBlocking"
   schema_values = {
    urlBlocklist = jsonencode([
        "example.com",
        "bleh.com"
        ])
   } 
  }
}

Yohan460 avatar Jun 29 '22 22:06 Yohan460

This PR should be ready for review

Yohan460 avatar Jun 29 '22 22:06 Yohan460

Seems like unit test failure is a CI issue and unrelated to my change. https://github.com/hashicorp/terraform-provider-googleworkspace/runs/7200398697?check_suite_focus=true#step:5:17

@SarahFrench

Yohan460 avatar Jul 05 '22 17:07 Yohan460