diff --git a/CHANGELOG.md b/CHANGELOG.md index ac8a780c..fb3a1da3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ ## 0.8.0 (Unreleased) + +BUG FIXES: +* chrome: fixed a bug where when validating a `googleworkspace_chrome_policy` schema value the proto `LABEL_REPEATED` label was not being respected to require an array of the associated type ([#336](https://github.com/hashicorp/terraform-provider-googleworkspace/pull/336)) + ## 0.7.0 (June 10, 2022) FEATURES: diff --git a/internal/provider/resource_chrome_policy.go b/internal/provider/resource_chrome_policy.go index 0ab5fc63..ce7041df 100644 --- a/internal/provider/resource_chrome_policy.go +++ b/internal/provider/resource_chrome_policy.go @@ -357,13 +357,34 @@ func validateChromePolicies(ctx context.Context, d *schema.ResourceData, client }) } - validType := validatePolicyFieldValueType(schemaField.Type, polVal) - if !validType { - return append(diags, diag.Diagnostic{ - Summary: fmt.Sprintf("value provided for %s is of incorrect type (expected type: %s)", schemaField.Name, schemaField.Type), - Severity: diag.Error, - }) + if schemaField.Label == "LABEL_REPEATED" { + polValType := reflect.ValueOf(polVal).Kind() + if !((polValType == reflect.Array) || (polValType == reflect.Slice)) { + return append(diags, diag.Diagnostic{ + Summary: fmt.Sprintf("value provided for %s is of incorrect type %v (expected type: []%v)", schemaField.Name, polValType, schemaField.Type), + Severity: diag.Error, + }) + } else { + if polValArray, ok := polVal.([]interface{}); ok { + for _, polValItem := range polValArray { + if !validatePolicyFieldValueType(schemaField.Type, polValItem) { + return append(diags, diag.Diagnostic{ + Summary: fmt.Sprintf("array value %v provided for %s is of incorrect type (expected type: %s)", polValItem, schemaField.Name, schemaField.Type), + Severity: diag.Error, + }) + } + } + } + } + } else { + if !validatePolicyFieldValueType(schemaField.Type, polVal) { + return append(diags, diag.Diagnostic{ + Summary: fmt.Sprintf("value %v provided for %s is of incorrect type (expected type: %s)", polVal, schemaField.Name, schemaField.Type), + Severity: diag.Error, + }) + } } + } } }