From 0759a41d721892601dadc3bf03fd520d6fff590e Mon Sep 17 00:00:00 2001 From: Vuong Date: Fri, 7 Jun 2024 13:42:04 +0100 Subject: [PATCH] clean up --- catalog/permissions/permissions.go | 1 + catalog/resource_grant.go | 2 +- catalog/resource_grants.go | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/catalog/permissions/permissions.go b/catalog/permissions/permissions.go index 322b5106a4..4f37fc8a73 100644 --- a/catalog/permissions/permissions.go +++ b/catalog/permissions/permissions.go @@ -120,6 +120,7 @@ var Mappings = SecurableMapping{ "volume": catalog.SecurableType("volume"), } +// Unity Catalog accepts privileges with spaces, but will automatically convert them to underscores func NormalizePrivilege(privilege string) string { return strings.ToUpper(strings.Replace(privilege, " ", "_", -1)) } diff --git a/catalog/resource_grant.go b/catalog/resource_grant.go index 452e14efb4..ddd3abb08c 100644 --- a/catalog/resource_grant.go +++ b/catalog/resource_grant.go @@ -123,8 +123,8 @@ func ResourceGrant() common.Resource { s := common.StructToSchema(permissions.UnityCatalogPrivilegeAssignment{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { common.CustomizeSchemaPath(m, "principal").SetForceNew().SetCustomSuppressDiff(common.EqualFoldDiffSuppress) - common.MustSchemaPath(m, "principal").DiffSuppressFunc = common.EqualFoldDiffSuppress + // set custom hash function for privileges common.MustSchemaPath(m, "privileges").Set = func(i any) int { privilege := i.(string) return schema.HashString(permissions.NormalizePrivilege(privilege)) diff --git a/catalog/resource_grants.go b/catalog/resource_grants.go index d653146fe0..9831728d40 100644 --- a/catalog/resource_grants.go +++ b/catalog/resource_grants.go @@ -128,6 +128,7 @@ func parseId(d *schema.ResourceData) (string, string, error) { func ResourceGrants() common.Resource { s := common.StructToSchema(PermissionsList{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { + // set custom hash function for principal and privileges common.MustSchemaPath(s, "grant", "privileges").Set = func(i any) int { privilege := i.(string) return schema.HashString(permissions.NormalizePrivilege(privilege))