Skip to content
1 change: 1 addition & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

* Remove incorrect customization for `databricks_catalog` ([#5021](https://github.com/databricks/terraform-provider-databricks/pull/5021))
* Fix filling of `active` attribute in `databricks_user` data source ([#5026](https://github.com/databricks/terraform-provider-databricks/pull/5026))
* 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/databricks/terraform-provider-databricks/internal/acceptance"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

const preTestTemplate = `
Expand Down Expand Up @@ -230,3 +231,41 @@ func TestUcAccUpdateShareReorderObject(t *testing.T) {
}`,
})
}

func shareUpdateWithName(name string) string {
return fmt.Sprintf(`resource "databricks_share_pluginframework" "myshare" {
name = "%s"
owner = "account users"
object {
name = databricks_sql_table.mytable.id
comment = "A"
data_object_type = "TABLE"
history_data_sharing_status = "ENABLED"
}
}`, name)
}

func shareCheckStateforID() func(s *terraform.State) error {
return func(s *terraform.State) error {
r, ok := s.RootModule().Resources["databricks_share_pluginframework.myshare"]
if !ok {
return fmt.Errorf("resource not found in state")
}
id := r.Primary.Attributes["id"]
name := r.Primary.Attributes["name"]
if id != name {
return fmt.Errorf("resource ID is not equal to the name. Attributes: %v", r.Primary.Attributes)
}
return nil
}
}

func TestUcAccUpdateShareName(t *testing.T) {
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
Template: preTestTemplate + shareUpdateWithName("{var.STICKY_RANDOM}-terraform-delta-share-before"),
Check: shareCheckStateforID(),
}, acceptance.Step{
Template: preTestTemplate + shareUpdateWithName("{var.STICKY_RANDOM}-terraform-delta-share-after"),
Check: shareCheckStateforID(),
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
)

const resourceName = "share"
Expand All @@ -31,6 +32,7 @@ func ResourceShare() resource.Resource {

type ShareInfoExtended struct {
sharing_tf.ShareInfo_SdkV2
ID types.String `tfsdk:"id"` // Adding ID field to stay compatible with SDKv2
}

var _ pluginfwcommon.ComplexFieldTypeProvider = ShareInfoExtended{}
Expand Down Expand Up @@ -156,6 +158,8 @@ func (r *ShareResource) Schema(ctx context.Context, req resource.SchemaRequest,
c.SetRequired("object", "partition", "value", "op")
c.SetRequired("object", "partition", "value", "name")

c.SetComputed("id")

return c
})
resp.Schema = schema.Schema{
Expand Down Expand Up @@ -228,6 +232,8 @@ func (r *ShareResource) Create(ctx context.Context, req resource.CreateRequest,
return
}

newState.ID = newState.Name

resp.Diagnostics.Append(resp.State.Set(ctx, newState)...)
}

Expand Down
Loading