Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Bug Fixes

* Fix `ExactlyOneOf` in `databricks_app` ([#4946](https://github.com/databricks/terraform-provider-databricks/pull/4946))
* Add support for share resource in plugin framework implementation to be SDKv2 compatible ([#4965](https://github.com/databricks/terraform-provider-databricks/pull/4965))

### Documentation

Expand All @@ -30,6 +31,7 @@

### Internal Changes

* Make plugin framework implementation of share resource as default ([#4967](https://github.com/databricks/terraform-provider-databricks/pull/4967))
* Replaced `common.APIErrorBody` with corresponding structs in Go SDK ([#4936](https://github.com/databricks/terraform-provider-databricks/pull/4936))
* Reimplement `databricks_group` data source to use combination of List + Get API ([#4947](https://github.com/databricks/terraform-provider-databricks/pull/4947))
* Use databricks_sql_table Instead of databricks_table in Sharing Tests ([#4981](https://github.com/databricks/terraform-provider-databricks/pull/4981)
37 changes: 35 additions & 2 deletions exporter/importables.go
Original file line number Diff line number Diff line change
Expand Up @@ -2222,8 +2222,42 @@ var resourcesMap map[string]importable = map[string]importable{
return nil
},
Import: func(ic *importContext, r *resource) error {
resourceInfo := ic.Resources["databricks_share"]
if resourceInfo == nil {
// Fallback to direct data access if schema is not available
objectsList := r.Data.Get("object").([]any)
ic.emitUCGrantsWithOwner("share/"+r.ID, r)
for _, objRaw := range objectsList {
obj := objRaw.(map[string]any)
dataObjectType := obj["data_object_type"].(string)
name := obj["name"].(string)

switch dataObjectType {
case "TABLE":
ic.Emit(&resource{
Resource: "databricks_sql_table",
ID: name,
})
case "VOLUME":
ic.Emit(&resource{
Resource: "databricks_volume",
ID: name,
})
case "MODEL":
ic.Emit(&resource{
Resource: "databricks_registered_model",
ID: name,
})
default:
log.Printf("[INFO] Object type '%s' (name: '%s') isn't supported in share '%s'",
dataObjectType, name, r.ID)
}
}
return nil
}

var share tf_sharing.ShareInfo
s := ic.Resources["databricks_share"].Schema
s := resourceInfo.Schema
common.DataToStructPointer(r.Data, s, &share)
// TODO: how to link recipients to share?
ic.emitUCGrantsWithOwner("share/"+r.ID, r)
Expand All @@ -2249,7 +2283,6 @@ var resourcesMap map[string]importable = map[string]importable{
obj.DataObjectType, obj.Name, r.ID)
}
}

return nil
},
ShouldOmitField: shouldOmitForUnityCatalog,
Expand Down
6 changes: 3 additions & 3 deletions internal/providers/pluginfw/pluginfw_rollout_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ import (
var migratedResources = []func() resource.Resource{
library.ResourceLibrary,
qualitymonitor.ResourceQualityMonitor,
sharing.ResourceShare,
}

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

Expand All @@ -46,7 +49,6 @@ var migratedDataSources = []func() datasource.DataSource{
var pluginFwOnlyResources = append(
[]func() resource.Resource{
app.ResourceApp,
sharing.ResourceShare,
},
autoGeneratedResources...,
)
Expand All @@ -65,8 +67,6 @@ var pluginFwOnlyDataSources = append(
serving.DataSourceServingEndpoints,
// TODO: Add DataSourceCluster into migratedDataSources after fixing unit tests.
cluster.DataSourceCluster, // Using the staging name (with pluginframework suffix)
sharing.DataSourceShare, // Using the staging name (with pluginframework suffix)
sharing.DataSourceShares, // Using the staging name (with pluginframework suffix)
},
autoGeneratedDataSources...,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type ShareDataSource struct {
}

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

func (d *ShareDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type SharesDataSource struct {
}

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

func (d *SharesDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

func checkSharesDataSourcePopulated(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
ds, ok := s.Modules[0].Resources["data.databricks_shares_pluginframework.this"]
require.True(t, ok, "data.databricks_shares_pluginframework.this has to be there")
ds, ok := s.Modules[0].Resources["data.databricks_shares.this"]
require.True(t, ok, "data.databricks_shares.this has to be there")
num_shares, _ := strconv.Atoi(ds.Primary.Attributes["shares.#"])
assert.GreaterOrEqual(t, num_shares, 1)
return nil
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestUcAccDataSourceShares(t *testing.T) {
}
}

resource "databricks_share_pluginframework" "myshare" {
resource "databricks_share" "myshare" {
name = "{var.RANDOM}-terraform-delta-share"
object {
name = databricks_sql_table.mytable.id
Expand All @@ -81,8 +81,8 @@ func TestUcAccDataSourceShares(t *testing.T) {
}
}

data "databricks_shares_pluginframework" "this" {
depends_on = [databricks_share_pluginframework.myshare]
data "databricks_shares" "this" {
depends_on = [databricks_share.myshare]
}
`,
Check: checkSharesDataSourcePopulated(t),
Expand Down
Loading
Loading