Skip to content

[Internal] Bug fixed in databricks_mws_workspaces resource due to migration of resource to Go SDK #4652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### New Features and Improvements

### Bug Fixes
* Bug fixed in `databricks_mws_workspaces` resource due to migration of resource to Go SDK

### Documentation

Expand Down
18 changes: 7 additions & 11 deletions docs/resources/mws_workspaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ The following arguments are available:
* `deployment_name` - (Optional) part of URL as in `https://<prefix>-<deployment-name>.cloud.databricks.com`. Deployment name cannot be used until a deployment name prefix is defined. Please contact your Databricks representative. Once a new deployment prefix is added/updated, it only will affect the new workspaces created.
* `workspace_name` - name of the workspace, will appear on UI.
* `network_id` - (Optional) `network_id` from [networks](mws_networks.md).
* `credentials_id` - (AWS only) ID of the workspace's credential configuration object.
* `aws_region` - (AWS only) region of VPC.
* `storage_configuration_id` - (AWS only)`storage_configuration_id` from [storage configuration](mws_storage_configurations.md).
* `managed_services_customer_managed_key_id` - (Optional) `customer_managed_key_id` from [customer managed keys](mws_customer_managed_keys.md) with `use_cases` set to `MANAGED_SERVICES`. This is used to encrypt the workspace's notebook and secret data in the control plane.
Expand All @@ -332,9 +331,7 @@ The following arguments are available:
* `cloud_resource_container` - (GCP only) A block that specifies GCP workspace configurations, consisting of following blocks:
* `gcp` - A block that consists of the following field:
* `project_id` - The Google Cloud project ID, which the workspace uses to instantiate cloud resources for your workspace.
* `gcp_managed_network_config` - (GCP only) A block that describes the network configuration for workspaces with Databricks-managed networks.
* `subnet_cidr` - The IP range from which to allocate GKE cluster nodes. No bigger than `/9` and no smaller than `/29`.
* `gke_config` - (GCP only, deprecated) A block that specifies GKE configuration for the Databricks workspace:
* `gke_config` - (GCP only) A block that specifies GKE configuration for the Databricks workspace:
* `connectivity_type`: Specifies the network connectivity types for the GKE nodes and the GKE master network. Possible values are: `PRIVATE_NODE_PUBLIC_MASTER`, `PUBLIC_NODE_PUBLIC_MASTER`.
* `master_ip_range`: The IP range from which to allocate GKE cluster master resources. This field will be ignored if GKE private cluster is not enabled. It must be exactly as big as `/28`.
* `private_access_settings_id` - (Optional) Canonical unique identifier of [databricks_mws_private_access_settings](mws_private_access_settings.md) in Databricks Account.
Expand All @@ -354,25 +351,24 @@ You can specify a `token` block in the body of the workspace resource, so that T

On AWS, the following arguments could be modified after the workspace is running:

* `credentials_id`
* `custom_tags`
* `managed_services_customer_managed_key_id`
* `network_id` - Modifying [networks on running workspaces](mws_networks.md#modifying-networks-on-running-workspaces-aws-only) would require three separate `terraform apply` steps.
* `private_access_settings_id`
* `credentials_id`
* `storage_customer_managed_key_id`
* `private_access_settings_id`
* `custom_tags`

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - (String) Canonical unique identifier for the workspace, of the format `<account-id>/<workspace-id>`
* `creation_time` - (Integer) time when workspace was created
* `custom_tags` - (Map) Custom Tags (if present) added to workspace
* `gcp_workspace_sa` - (String, GCP only) identifier of a service account created for the workspace in form of `db-<workspace-id>@prod-gcp-<region>.iam.gserviceaccount.com`
* `workspace_id` - (String) workspace id
* `workspace_status_message` - (String) updates on workspace status
* `workspace_status` - (String) workspace status
* `creation_time` - (Integer) time when workspace was created
* `workspace_url` - (String) URL of the workspace
* `custom_tags` - (Map) Custom Tags (if present) added to workspace
* `gcp_workspace_sa` - (String, GCP only) identifier of a service account created for the workspace in form of `db-<workspace-id>@prod-gcp-<region>.iam.gserviceaccount.com`

## Timeouts

Expand Down
29 changes: 0 additions & 29 deletions internal/acceptance/expect_not_destroyed.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestAccDashboardsDataSource(t *testing.T) {
acceptance.WorkspaceLevel(t, acceptance.Step{
Template: `
resource "databricks_dashboard" "dashboard" {
display_name = "New Dashboard"
display_name = "New Dashboard-{var.RANDOM}"
warehouse_id = "{env.TEST_DEFAULT_WAREHOUSE_ID}"
serialized_dashboard = "{\"pages\":[{\"name\":\"new_name\",\"displayName\":\"New Page\"}]}"
embed_credentials = false // Optional
Expand Down
4 changes: 2 additions & 2 deletions internal/service/provisioning_tf/legacy_model.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions mws/data_mws_workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ func DataSourceMwsWorkspaces() common.Resource {
if c.Config.AccountID == "" {
return fmt.Errorf("provider block is missing `account_id` property")
}
a, err := c.AccountClient()
if err != nil {
return err
}
workspaces, err := a.Workspaces.List(ctx)
workspaces, err := NewWorkspacesAPI(ctx, c).List(c.Config.AccountID)
if err != nil {
return err
}
data.Ids = map[string]int64{}
for _, v := range workspaces {
data.Ids[v.WorkspaceName] = v.WorkspaceId
data.Ids[v.WorkspaceName] = v.WorkspaceID
}
return nil
})
Expand Down
44 changes: 24 additions & 20 deletions mws/data_mws_workspaces_test.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
package mws

import (
"errors"
"testing"

"github.com/databricks/databricks-sdk-go/experimental/mocks"
"github.com/databricks/databricks-sdk-go/service/provisioning"
"github.com/databricks/terraform-provider-databricks/qa"
"github.com/stretchr/testify/mock"
)

func TestDataSourceMwsWorkspaces(t *testing.T) {
qa.ResourceFixture{
MockAccountClientFunc: func(a *mocks.MockAccountClient) {
a.GetMockWorkspacesAPI().EXPECT().List(mock.Anything).Return([]provisioning.Workspace{
{
WorkspaceName: "bcd",
WorkspaceId: 123,
},
{
WorkspaceName: "def",
WorkspaceId: 456,
Fixtures: []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/accounts/abc/workspaces",

Response: []Workspace{
{
WorkspaceName: "bcd",
WorkspaceID: 123,
},
{
WorkspaceName: "def",
WorkspaceID: 456,
},
},
}, nil)
},
},
AccountID: "abc",
Resource: DataSourceMwsWorkspaces(),
Expand All @@ -37,12 +38,10 @@ func TestDataSourceMwsWorkspaces(t *testing.T) {
})
}

func TestDataSourceMwsWorkspaces_Error(t *testing.T) {
func TestCatalogsData_Error(t *testing.T) {
qa.ResourceFixture{
MockAccountClientFunc: func(a *mocks.MockAccountClient) {
a.GetMockWorkspacesAPI().EXPECT().List(mock.Anything).Return(nil, errors.New("i'm a teapot"))
},
AccountID: "abc",
Fixtures: qa.HTTPFailures,
Resource: DataSourceMwsWorkspaces(),
Read: true,
NonWritable: true,
Expand All @@ -52,8 +51,13 @@ func TestDataSourceMwsWorkspaces_Error(t *testing.T) {

func TestDataSourceMwsWorkspaces_Empty(t *testing.T) {
qa.ResourceFixture{
MockAccountClientFunc: func(a *mocks.MockAccountClient) {
a.GetMockWorkspacesAPI().EXPECT().List(mock.Anything).Return([]provisioning.Workspace{}, nil)
Fixtures: []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/accounts/abc/workspaces",

Response: []Workspace{},
},
},
AccountID: "abc",
Resource: DataSourceMwsWorkspaces(),
Expand Down
Loading