Skip to content

Commit 0221695

Browse files
authored
[Internal] Use plugin framework implementation of share resource as default (#5089)
## Changes <!-- Summary of your changes that are easy to understand --> Make the plugin framework implementation of share resource as default. With this change, `databricks_share` will use the plugin framework implementation. To be merged after: #4969 Note: Removal of SDKv2 implementation will be done in next release so users can fallback to SDKv2 implementation in case there are some issues. ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> Integration tests - Applying: SDKv2 -> Plugin Framework - Applying: Plugin Framework -> SDKv2
1 parent add1196 commit 0221695

File tree

9 files changed

+513
-29
lines changed

9 files changed

+513
-29
lines changed

NEXT_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313
### Exporter
1414

1515
### Internal Changes
16+
17+
* Make plugin framework implementation of share resource as default ([#4967](https://github.com/databricks/terraform-provider-databricks/pull/4967))

exporter/importables.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,8 +2222,42 @@ var resourcesMap map[string]importable = map[string]importable{
22222222
return nil
22232223
},
22242224
Import: func(ic *importContext, r *resource) error {
2225+
resourceInfo := ic.Resources["databricks_share"]
2226+
if resourceInfo == nil {
2227+
// Fallback to direct data access if schema is not available
2228+
objectsList := r.Data.Get("object").([]any)
2229+
ic.emitUCGrantsWithOwner("share/"+r.ID, r)
2230+
for _, objRaw := range objectsList {
2231+
obj := objRaw.(map[string]any)
2232+
dataObjectType := obj["data_object_type"].(string)
2233+
name := obj["name"].(string)
2234+
2235+
switch dataObjectType {
2236+
case "TABLE":
2237+
ic.Emit(&resource{
2238+
Resource: "databricks_sql_table",
2239+
ID: name,
2240+
})
2241+
case "VOLUME":
2242+
ic.Emit(&resource{
2243+
Resource: "databricks_volume",
2244+
ID: name,
2245+
})
2246+
case "MODEL":
2247+
ic.Emit(&resource{
2248+
Resource: "databricks_registered_model",
2249+
ID: name,
2250+
})
2251+
default:
2252+
log.Printf("[INFO] Object type '%s' (name: '%s') isn't supported in share '%s'",
2253+
dataObjectType, name, r.ID)
2254+
}
2255+
}
2256+
return nil
2257+
}
2258+
22252259
var share tf_sharing.ShareInfo
2226-
s := ic.Resources["databricks_share"].Schema
2260+
s := resourceInfo.Schema
22272261
common.DataToStructPointer(r.Data, s, &share)
22282262
// TODO: how to link recipients to share?
22292263
ic.emitUCGrantsWithOwner("share/"+r.ID, r)
@@ -2249,7 +2283,6 @@ var resourcesMap map[string]importable = map[string]importable{
22492283
obj.DataObjectType, obj.Name, r.ID)
22502284
}
22512285
}
2252-
22532286
return nil
22542287
},
22552288
ShouldOmitField: shouldOmitForUnityCatalog,

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
@@ -65,7 +65,7 @@ func TestUcAccDataSourceShares(t *testing.T) {
6565
}
6666
}
6767
68-
resource "databricks_share_pluginframework" "myshare" {
68+
resource "databricks_share" "myshare" {
6969
name = "{var.RANDOM}-terraform-delta-share"
7070
object {
7171
name = databricks_sql_table.mytable.id
@@ -81,8 +81,8 @@ func TestUcAccDataSourceShares(t *testing.T) {
8181
}
8282
}
8383
84-
data "databricks_shares_pluginframework" "this" {
85-
depends_on = [databricks_share_pluginframework.myshare]
84+
data "databricks_shares" "this" {
85+
depends_on = [databricks_share.myshare]
8686
}
8787
`,
8888
Check: checkSharesDataSourcePopulated(t),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ type ShareResource struct {
142142
}
143143

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

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

0 commit comments

Comments
 (0)