Skip to content

Commit

Permalink
support adding objects anywhere in the list + integration test for th…
Browse files Browse the repository at this point in the history
…at case
  • Loading branch information
rauchy committed Oct 24, 2024
1 parent 5a78df0 commit 4b7eb0e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down Expand Up @@ -123,7 +139,8 @@ func shareTemplateWithOwner(comment string, owner string) string {
comment = "%s"
data_object_type = "TABLE"
history_data_sharing_status = "DISABLED"
}
}
}`, owner, comment)
}

Expand All @@ -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"
}
}`,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4b7eb0e

Please sign in to comment.