Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package sharing_test

import (
"context"
"fmt"
"regexp"
"strconv"
"testing"

"github.com/databricks/databricks-sdk-go"
"github.com/databricks/terraform-provider-databricks/internal/acceptance"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -135,3 +137,30 @@ func TestAccSharesData_ProviderConfig_Mismatched(t *testing.T) {
),
})
}

func TestAccSharesData_ProviderConfig_MismatchReapply(t *testing.T) {
acceptance.LoadUcwsEnv(t)
ctx := context.Background()
w := databricks.Must(databricks.NewWorkspaceClient())
workspaceID, err := w.CurrentWorkspaceID(ctx)
require.NoError(t, err)
workspaceIDStr := strconv.FormatInt(workspaceID, 10)
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
Template: preTestTemplateSchema + dataSourceSharesTemplate(`
provider_config = {
workspace_id = "123"
}
`),
ExpectError: regexp.MustCompile(
`(?s)failed to get workspace client.*workspace_id mismatch` +
`.*please check the workspace_id provided in ` +
`provider_config`,
),
}, acceptance.Step{
Template: preTestTemplateSchema + dataSourceSharesTemplate(fmt.Sprintf(`
provider_config = {
workspace_id = "%s"
}
`, workspaceIDStr)),
})
}
31 changes: 31 additions & 0 deletions internal/providers/pluginfw/products/sharing/resource_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,37 @@ func (d *ShareResource) Configure(ctx context.Context, req resource.ConfigureReq
}
}

func (r *ShareResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) {
ctx = pluginfwcontext.SetUserAgentInResourceContext(ctx, resourceName)

var plan ShareInfoExtended
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
if resp.Diagnostics.HasError() {
return
}

var planGoSDK sharing.ShareInfo
resp.Diagnostics.Append(converters.TfSdkToGoSdkStruct(ctx, plan, &planGoSDK)...)
if resp.Diagnostics.HasError() {
return
}

workspaceID, diags := tfschema.GetWorkspaceID_SdkV2(ctx, plan.ProviderConfig)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

// Validate the workspace ID by making sure we are able to get a workspace client
// for the new workspace ID.
_, clientDiags := r.Client.GetWorkspaceClientForUnifiedProviderWithDiagnostics(ctx, workspaceID)
resp.Diagnostics.Append(clientDiags...)
if resp.Diagnostics.HasError() {
return
}

}

func (r *ShareResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
ctx = pluginfwcontext.SetUserAgentInResourceContext(ctx, resourceName)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,35 @@ func TestAccShare_ProviderConfig_Mismatched(t *testing.T) {
`.*please check the workspace_id provided in ` +
`provider_config`,
),
PlanOnly: true,
})
}

func TestAccShare_ProviderConfig_MismatchedReapply(t *testing.T) {
acceptance.LoadUcwsEnv(t)
ctx := context.Background()
w := databricks.Must(databricks.NewWorkspaceClient())
workspaceID, err := w.CurrentWorkspaceID(ctx)
require.NoError(t, err)
workspaceIDStr := strconv.FormatInt(workspaceID, 10)
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
Template: preTestTemplateSchema + shareTemplate(`
provider_config {
workspace_id = "123"
}
`),
ExpectError: regexp.MustCompile(
`(?s)failed to get workspace client.*workspace_id mismatch` +
`.*please check the workspace_id provided in ` +
`provider_config`,
),
PlanOnly: true,
}, acceptance.Step{
Template: preTestTemplateSchema + shareTemplate(fmt.Sprintf(`
provider_config {
workspace_id = "%s"
}
`, workspaceIDStr)),
})
}

Expand Down
Loading