From 4b7eb0ef3f0caa4f622d58cf540adb62185ef6e2 Mon Sep 17 00:00:00 2001 From: Omer Lachish Date: Thu, 24 Oct 2024 15:19:00 +0200 Subject: [PATCH] support adding objects anywhere in the list + integration test for that case --- .../resources/sharing/resource_acc_test.go | 66 ++++++++++++++++++- .../resources/sharing/resource_share.go | 3 +- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/internal/providers/pluginfw/resources/sharing/resource_acc_test.go b/internal/providers/pluginfw/resources/sharing/resource_acc_test.go index fb046339c..7018e0b40 100644 --- a/internal/providers/pluginfw/resources/sharing/resource_acc_test.go +++ b/internal/providers/pluginfw/resources/sharing/resource_acc_test.go @@ -56,6 +56,22 @@ const preTestTemplate = ` type_json = "{\"name\":\"id\",\"type\":\"integer\",\"nullable\":true,\"metadata\":{}}" } } + + resource "databricks_table" "mytable_3" { + catalog_name = databricks_catalog.sandbox.id + schema_name = databricks_schema.things.name + name = "bar_3" + table_type = "MANAGED" + data_source_format = "DELTA" + + column { + name = "id" + position = 0 + type_name = "INT" + type_text = "int" + type_json = "{\"name\":\"id\",\"type\":\"integer\",\"nullable\":true,\"metadata\":{}}" + } + } ` const preTestTemplateUpdate = ` @@ -123,7 +139,8 @@ func shareTemplateWithOwner(comment string, owner string) string { comment = "%s" data_object_type = "TABLE" history_data_sharing_status = "DISABLED" - } + } + }`, owner, comment) } @@ -138,3 +155,50 @@ func TestUcAccUpdateShare(t *testing.T) { Template: preTestTemplate + preTestTemplateUpdate + shareTemplateWithOwner("f", "{env.TEST_METASTORE_ADMIN_GROUP_NAME}"), }) } + +func TestUcAccUpdateShareAddObject(t *testing.T) { + acceptance.UnityWorkspaceLevel(t, acceptance.Step{ + Template: preTestTemplate + preTestTemplateUpdate + + `resource "databricks_share_pluginframework" "myshare" { + name = "{var.STICKY_RANDOM}-terraform-delta-share" + owner = "account users" + object { + name = databricks_table.mytable.id + comment = "A" + data_object_type = "TABLE" + history_data_sharing_status = "DISABLED" + } + object { + name = databricks_table.mytable_3.id + comment = "C" + data_object_type = "TABLE" + history_data_sharing_status = "DISABLED" + } + + }`, + }, acceptance.Step{ + Template: preTestTemplate + preTestTemplateUpdate + + `resource "databricks_share_pluginframework" "myshare" { + name = "{var.STICKY_RANDOM}-terraform-delta-share" + owner = "account users" + object { + name = databricks_table.mytable.id + comment = "AA" + data_object_type = "TABLE" + history_data_sharing_status = "DISABLED" + } + object { + name = databricks_table.mytable_2.id + comment = "BB" + data_object_type = "TABLE" + history_data_sharing_status = "DISABLED" + } + object { + name = databricks_table.mytable_3.id + comment = "CC" + data_object_type = "TABLE" + history_data_sharing_status = "DISABLED" + } + }`, + }) +} diff --git a/internal/providers/pluginfw/resources/sharing/resource_share.go b/internal/providers/pluginfw/resources/sharing/resource_share.go index e00404e4f..3f22631b6 100644 --- a/internal/providers/pluginfw/resources/sharing/resource_share.go +++ b/internal/providers/pluginfw/resources/sharing/resource_share.go @@ -143,8 +143,6 @@ func (r *ShareResource) Schema(ctx context.Context, req resource.SchemaRequest, c.AddPlanModifier(stringplanmodifier.RequiresReplace(), "name") // ForceNew c.AddPlanModifier(int64planmodifier.UseStateForUnknown(), "created_at") c.AddPlanModifier(stringplanmodifier.UseStateForUnknown(), "created_by") - c.AddPlanModifier(int64planmodifier.UseStateForUnknown(), "object", "added_at") - c.AddPlanModifier(stringplanmodifier.UseStateForUnknown(), "object", "added_by") c.SetRequired("object", "data_object_type") c.SetRequired("object", "partitions", "values", "op") @@ -361,6 +359,7 @@ func (r *ShareResource) Update(ctx context.Context, req resource.UpdateRequest, } } + matchOrder(updatedShareInfo.Objects, planGoSDK.Objects, func(obj sharing.SharedDataObject) string { return obj.Name }) resp.Diagnostics.Append(converters.GoSdkToTfSdkStruct(ctx, updatedShareInfo, &state)...) if resp.Diagnostics.HasError() { return