Skip to content

Commit 50d60f8

Browse files
committed
promote pluginfw share resource
1 parent c9d991a commit 50d60f8

File tree

9 files changed

+423
-29
lines changed

9 files changed

+423
-29
lines changed

NEXT_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### New Features and Improvements
88

9+
* Promote Plugin Framework Share Resource to Production ([#4846](https://github.com/databricks/terraform-provider-databricks/pull/4846)).
10+
911
### Bug Fixes
1012

1113
* Corrected accidentally removed `SpID` field from `databricks_service_principal` ([#4868](https://github.com/databricks/terraform-provider-databricks/pull/4868)).

exporter/importables.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
tf_dlt "github.com/databricks/terraform-provider-databricks/pipelines"
2929
"github.com/databricks/terraform-provider-databricks/repos"
3030
tf_settings "github.com/databricks/terraform-provider-databricks/settings"
31-
tf_sharing "github.com/databricks/terraform-provider-databricks/sharing"
3231
tf_sql "github.com/databricks/terraform-provider-databricks/sql"
3332
"github.com/databricks/terraform-provider-databricks/storage"
3433
"github.com/hashicorp/hcl/v2/hclwrite"
@@ -1990,31 +1989,36 @@ var resourcesMap map[string]importable = map[string]importable{
19901989
return nil
19911990
},
19921991
Import: func(ic *importContext, r *resource) error {
1993-
var share tf_sharing.ShareInfo
1994-
s := ic.Resources["databricks_share"].Schema
1995-
common.DataToStructPointer(r.Data, s, &share)
1996-
// TODO: how to link recipients to share?
1992+
// Handle share objects by reading them directly from the data
1993+
// since the resource has been migrated to pluginfw
19971994
ic.emitUCGrantsWithOwner("share/"+r.ID, r)
1998-
for _, obj := range share.Objects {
1999-
switch obj.DataObjectType {
1995+
1996+
// Get objects array from the resource data
1997+
objectsList := r.Data.Get("object").([]any)
1998+
for _, objRaw := range objectsList {
1999+
obj := objRaw.(map[string]any)
2000+
dataObjectType := obj["data_object_type"].(string)
2001+
name := obj["name"].(string)
2002+
2003+
switch dataObjectType {
20002004
case "TABLE":
20012005
ic.Emit(&resource{
20022006
Resource: "databricks_sql_table",
2003-
ID: obj.Name,
2007+
ID: name,
20042008
})
20052009
case "VOLUME":
20062010
ic.Emit(&resource{
20072011
Resource: "databricks_volume",
2008-
ID: obj.Name,
2012+
ID: name,
20092013
})
20102014
case "MODEL":
20112015
ic.Emit(&resource{
20122016
Resource: "databricks_registered_model",
2013-
ID: obj.Name,
2017+
ID: name,
20142018
})
20152019
default:
20162020
log.Printf("[INFO] Object type '%s' (name: '%s') isn't supported in share '%s'",
2017-
obj.DataObjectType, obj.Name, r.ID)
2021+
dataObjectType, name, r.ID)
20182022
}
20192023
}
20202024

internal/providers/pluginfw/pluginfw_rollout_utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ import (
3333
var migratedResources = []func() resource.Resource{
3434
library.ResourceLibrary,
3535
qualitymonitor.ResourceQualityMonitor,
36+
sharing.ResourceShare,
3637
}
3738

3839
// List of data sources that have been migrated from SDK V2 to plugin framework
3940
// Keep this list sorted.
4041
var migratedDataSources = []func() datasource.DataSource{
42+
sharing.DataSourceShare,
43+
sharing.DataSourceShares,
4144
volume.DataSourceVolumes,
4245
}
4346

@@ -46,7 +49,6 @@ var migratedDataSources = []func() datasource.DataSource{
4649
var pluginFwOnlyResources = append(
4750
[]func() resource.Resource{
4851
app.ResourceApp,
49-
sharing.ResourceShare,
5052
},
5153
autoGeneratedResources...,
5254
)
@@ -65,8 +67,6 @@ var pluginFwOnlyDataSources = append(
6567
serving.DataSourceServingEndpoints,
6668
// TODO: Add DataSourceCluster into migratedDataSources after fixing unit tests.
6769
cluster.DataSourceCluster, // Using the staging name (with pluginframework suffix)
68-
sharing.DataSourceShare, // Using the staging name (with pluginframework suffix)
69-
sharing.DataSourceShares, // Using the staging name (with pluginframework suffix)
7070
},
7171
autoGeneratedDataSources...,
7272
)

internal/providers/pluginfw/products/sharing/data_share.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type ShareDataSource struct {
2828
}
2929

3030
func (d *ShareDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
31-
resp.TypeName = pluginfwcommon.GetDatabricksStagingName(dataSourceNameShare)
31+
resp.TypeName = pluginfwcommon.GetDatabricksProductionName(dataSourceNameShare)
3232
}
3333

3434
func (d *ShareDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {

internal/providers/pluginfw/products/sharing/data_shares.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type SharesDataSource struct {
5252
}
5353

5454
func (d *SharesDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
55-
resp.TypeName = pluginfwcommon.GetDatabricksStagingName(dataSourceNameShares)
55+
resp.TypeName = pluginfwcommon.GetDatabricksProductionName(dataSourceNameShares)
5656
}
5757

5858
func (d *SharesDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {

internal/providers/pluginfw/products/sharing/data_shares_acc_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212

1313
func checkSharesDataSourcePopulated(t *testing.T) func(s *terraform.State) error {
1414
return func(s *terraform.State) error {
15-
ds, ok := s.Modules[0].Resources["data.databricks_shares_pluginframework.this"]
16-
require.True(t, ok, "data.databricks_shares_pluginframework.this has to be there")
15+
ds, ok := s.Modules[0].Resources["data.databricks_shares.this"]
16+
require.True(t, ok, "data.databricks_shares.this has to be there")
1717
num_shares, _ := strconv.Atoi(ds.Primary.Attributes["shares.#"])
1818
assert.GreaterOrEqual(t, num_shares, 1)
1919
return nil
@@ -71,7 +71,7 @@ func TestUcAccDataSourceShares(t *testing.T) {
7171
}
7272
}
7373
74-
resource "databricks_share_pluginframework" "myshare" {
74+
resource "databricks_share" "myshare" {
7575
name = "{var.RANDOM}-terraform-delta-share"
7676
object {
7777
name = databricks_table.mytable.id
@@ -86,8 +86,8 @@ func TestUcAccDataSourceShares(t *testing.T) {
8686
}
8787
}
8888
89-
data "databricks_shares_pluginframework" "this" {
90-
depends_on = [databricks_share_pluginframework.myshare]
89+
data "databricks_shares" "this" {
90+
depends_on = [databricks_share.myshare]
9191
}
9292
`,
9393
Check: checkSharesDataSourcePopulated(t),

internal/providers/pluginfw/products/sharing/resource_acc_test.go

Lines changed: 122 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const preTestTemplateUpdate = `
9191
func TestUcAccCreateShare(t *testing.T) {
9292
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
9393
Template: preTestTemplate + `
94-
resource "databricks_share_pluginframework" "myshare" {
94+
resource "databricks_share" "myshare" {
9595
name = "{var.STICKY_RANDOM}-terraform-delta-share"
9696
owner = "account users"
9797
object {
@@ -119,7 +119,7 @@ func TestUcAccCreateShare(t *testing.T) {
119119
}
120120
121121
resource "databricks_grants" "some" {
122-
share = databricks_share_pluginframework.myshare.name
122+
share = databricks_share.myshare.name
123123
grant {
124124
principal = databricks_recipient.db2open.name
125125
privileges = ["SELECT"]
@@ -131,7 +131,7 @@ func TestUcAccCreateShare(t *testing.T) {
131131

132132
func shareTemplateWithOwner(comment string, owner string) string {
133133
return fmt.Sprintf(`
134-
resource "databricks_share_pluginframework" "myshare" {
134+
resource "databricks_share" "myshare" {
135135
name = "{var.STICKY_RANDOM}-terraform-delta-share"
136136
owner = "%s"
137137
object {
@@ -159,7 +159,7 @@ func TestUcAccUpdateShare(t *testing.T) {
159159
func TestUcAccUpdateShareAddObject(t *testing.T) {
160160
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
161161
Template: preTestTemplate + preTestTemplateUpdate +
162-
`resource "databricks_share_pluginframework" "myshare" {
162+
`resource "databricks_share" "myshare" {
163163
name = "{var.STICKY_RANDOM}-terraform-delta-share"
164164
owner = "account users"
165165
object {
@@ -178,7 +178,7 @@ func TestUcAccUpdateShareAddObject(t *testing.T) {
178178
}`,
179179
}, acceptance.Step{
180180
Template: preTestTemplate + preTestTemplateUpdate +
181-
`resource "databricks_share_pluginframework" "myshare" {
181+
`resource "databricks_share" "myshare" {
182182
name = "{var.STICKY_RANDOM}-terraform-delta-share"
183183
owner = "account users"
184184
object {
@@ -206,7 +206,7 @@ func TestUcAccUpdateShareAddObject(t *testing.T) {
206206
func TestUcAccUpdateShareReorderObject(t *testing.T) {
207207
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
208208
Template: preTestTemplate + preTestTemplateUpdate +
209-
`resource "databricks_share_pluginframework" "myshare" {
209+
`resource "databricks_share" "myshare" {
210210
name = "{var.STICKY_RANDOM}-terraform-delta-share"
211211
owner = "account users"
212212
object {
@@ -220,7 +220,7 @@ func TestUcAccUpdateShareReorderObject(t *testing.T) {
220220
}`,
221221
}, acceptance.Step{
222222
Template: preTestTemplate + preTestTemplateUpdate +
223-
`resource "databricks_share_pluginframework" "myshare" {
223+
`resource "databricks_share" "myshare" {
224224
name = "{var.STICKY_RANDOM}-terraform-delta-share"
225225
owner = "account users"
226226
object {
@@ -234,3 +234,118 @@ func TestUcAccUpdateShareReorderObject(t *testing.T) {
234234
}`,
235235
})
236236
}
237+
238+
// TestUcAccUpdateShareNoChanges tests that updating a share with no actual changes doesn't cause issues
239+
func TestUcAccUpdateShareNoChanges(t *testing.T) {
240+
shareConfig := preTestTemplate + preTestTemplateUpdate +
241+
`resource "databricks_share" "myshare" {
242+
name = "{var.STICKY_RANDOM}-terraform-delta-share"
243+
owner = "account users"
244+
object {
245+
name = databricks_table.mytable.id
246+
comment = "stable comment"
247+
data_object_type = "TABLE"
248+
}
249+
}`
250+
251+
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
252+
Template: shareConfig,
253+
}, acceptance.Step{
254+
Template: shareConfig, // Same config - should not trigger any updates
255+
})
256+
}
257+
258+
// TestUcAccUpdateShareComplexObjectChanges tests complex scenarios with multiple object updates
259+
func TestUcAccUpdateShareComplexObjectChanges(t *testing.T) {
260+
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
261+
Template: preTestTemplate + preTestTemplateUpdate +
262+
`resource "databricks_share" "myshare" {
263+
name = "{var.STICKY_RANDOM}-terraform-delta-share"
264+
owner = "account users"
265+
object {
266+
name = databricks_table.mytable.id
267+
comment = "original comment"
268+
data_object_type = "TABLE"
269+
}
270+
object {
271+
name = databricks_table.mytable_2.id
272+
comment = "second table"
273+
data_object_type = "TABLE"
274+
}
275+
}`,
276+
}, acceptance.Step{
277+
// Remove one object, add another, and update comment on existing
278+
Template: preTestTemplate + preTestTemplateUpdate +
279+
`resource "databricks_share" "myshare" {
280+
name = "{var.STICKY_RANDOM}-terraform-delta-share"
281+
owner = "account users"
282+
object {
283+
name = databricks_table.mytable.id
284+
comment = "updated comment"
285+
data_object_type = "TABLE"
286+
}
287+
object {
288+
name = databricks_table.mytable_3.id
289+
comment = "third table"
290+
data_object_type = "TABLE"
291+
}
292+
}`,
293+
})
294+
}
295+
296+
// TestUcAccUpdateShareRemoveAllObjects tests removing all objects from a share
297+
func TestUcAccUpdateShareRemoveAllObjects(t *testing.T) {
298+
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
299+
Template: preTestTemplate + preTestTemplateUpdate +
300+
`resource "databricks_share" "myshare" {
301+
name = "{var.STICKY_RANDOM}-terraform-delta-share"
302+
owner = "account users"
303+
object {
304+
name = databricks_table.mytable.id
305+
comment = "to be removed"
306+
data_object_type = "TABLE"
307+
}
308+
object {
309+
name = databricks_table.mytable_2.id
310+
comment = "also to be removed"
311+
data_object_type = "TABLE"
312+
}
313+
}`,
314+
}, acceptance.Step{
315+
Template: preTestTemplate + preTestTemplateUpdate +
316+
`resource "databricks_share" "myshare" {
317+
name = "{var.STICKY_RANDOM}-terraform-delta-share"
318+
owner = "account users"
319+
}`,
320+
})
321+
}
322+
323+
// TestUcAccUpdateShareCDFEnabled tests the CDF enabled suppression logic
324+
func TestUcAccUpdateShareCDFEnabled(t *testing.T) {
325+
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
326+
Template: preTestTemplate + preTestTemplateUpdate +
327+
`resource "databricks_share" "myshare" {
328+
name = "{var.STICKY_RANDOM}-terraform-delta-share"
329+
owner = "account users"
330+
object {
331+
name = databricks_table.mytable.id
332+
comment = "with history sharing"
333+
data_object_type = "TABLE"
334+
history_data_sharing_status = "ENABLED"
335+
}
336+
}`,
337+
}, acceptance.Step{
338+
// Change comment but keep history_data_sharing_status
339+
Template: preTestTemplate + preTestTemplateUpdate +
340+
`resource "databricks_share" "myshare" {
341+
name = "{var.STICKY_RANDOM}-terraform-delta-share"
342+
owner = "account users"
343+
object {
344+
name = databricks_table.mytable.id
345+
comment = "updated comment with history sharing"
346+
data_object_type = "TABLE"
347+
history_data_sharing_status = "ENABLED"
348+
}
349+
}`,
350+
})
351+
}

internal/providers/pluginfw/products/sharing/resource_share.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ type ShareResource struct {
140140
}
141141

142142
func (r *ShareResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
143-
resp.TypeName = pluginfwcommon.GetDatabricksStagingName(resourceName)
143+
resp.TypeName = pluginfwcommon.GetDatabricksProductionName(resourceName)
144144
}
145145

146146
func (r *ShareResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {

0 commit comments

Comments
 (0)