Skip to content

Commit 97bdbf4

Browse files
authored
Allow updating private_access_settings_id for databricks_mws_workspaces (#1668)
1 parent 146f1e2 commit 97bdbf4

File tree

6 files changed

+119
-13
lines changed

6 files changed

+119
-13
lines changed

docs/guides/aws-private-link-workspace.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
page_title: "Provisioning Databricks on AWS with PrivateLink"
33
---
44

5-
# Deploying pre-requisite resources and enabling PrivateLink connections (AWS Preview)
6-
7-
-> **Public Preview** This feature is in [Public Preview](https://docs.databricks.com/release-notes/release-types.html). Contact your Databricks representative to request access.
5+
# Deploying pre-requisite resources and enabling PrivateLink connections
86

97
Databricks PrivateLink support enables private connectivity between users and their Databricks workspaces and between clusters on the data plane and core services on the control plane within the Databricks workspace infrastructure. You can use Terraform to deploy the underlying cloud resources and the private access settings resources automatically, using a programmatic approach. This guide assumes you are deploying into an existing VPC and you have set up credentials and storage configurations as per prior examples, notably here.
108

docs/resources/mws_private_access_settings.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ subcategory: "AWS"
33
---
44
# databricks_mws_private_access_settings Resource
55

6-
-> **Public Preview** This feature is in [Public Preview](https://docs.databricks.com/release-notes/release-types.html). Contact your Databricks representative to request access.
7-
86
Allows you to create a [Private Access Setting](https://docs.databricks.com/administration-guide/cloud-configurations/aws/privatelink.html#step-5-create-a-private-access-settings-configuration-using-the-databricks-account-api) that can be used as part of a [databricks_mws_workspaces](mws_workspaces.md) resource to create a [Databricks Workspace that leverages AWS PrivateLink](https://docs.databricks.com/administration-guide/cloud-configurations/aws/privatelink.html).
97

108
It is strongly recommended that customers read the [Enable Private Link](https://docs.databricks.com/administration-guide/cloud-configurations/aws/privatelink.html) documentation before trying to leverage this resource.

docs/resources/mws_vpc_endpoint.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ subcategory: "AWS"
33
---
44
# databricks_mws_vpc_endpoint Resource
55

6-
-> **Public Preview** This feature is in [Public Preview](https://docs.databricks.com/release-notes/release-types.html). Contact your Databricks representative to request access.
7-
86
Enables you to register [aws_vpc_endpoint](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_endpoint) resources with Databricks such that they can be used as part of a [databricks_mws_networks](mws_networks.md) configuration.
97

108
It is strongly recommended that customers read the [Enable Private Link](https://docs.databricks.com/administration-guide/cloud-configurations/aws/privatelink.html) documentation before trying to leverage this resource.

docs/resources/mws_workspaces.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ The following arguments are available and cannot be changed after workspace is c
208208
* `workspace_name` - name of the workspace, will appear on UI
209209
* `aws_region` - AWS region of VPC
210210
* `storage_configuration_id` - `storage_configuration_id` from [storage configuration](mws_storage_configurations.md)
211-
* `private_access_settings_id` - (Optional) Canonical unique identifier of [databricks_mws_private_access_settings](mws_private_access_settings.md) in Databricks Account
212211

213212
## token block
214213

@@ -225,7 +224,7 @@ The following arguments could be modified after the workspace is running:
225224
* `network_id` - (Optional) `network_id` from [networks](mws_networks.md). Modifying [networks on running workspaces](mws_networks.md#modifying-networks-on-running-workspaces) would require three separate `terraform apply` steps.
226225
* `credentials_id` - `credentials_id` from [credentials](mws_credentials.md)
227226
* `storage_customer_managed_key_id` - (Optional) `customer_managed_key_id` from [customer managed keys](mws_customer_managed_keys.md) with `use_cases` set to `STORAGE`. This is used to encrypt the DBFS Storage & Cluster EBS Volumes.
228-
227+
* `private_access_settings_id` - (Optional) Canonical unique identifier of [databricks_mws_private_access_settings](mws_private_access_settings.md) in Databricks Account
229228

230229
## Attribute Reference
231230

mws/resource_mws_workspaces.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func (a WorkspacesAPI) WaitForRunning(ws Workspace, timeout time.Duration) error
243243
})
244244
}
245245

246-
var workspaceRunningUpdatesAllowed = []string{"credentials_id", "network_id", "storage_customer_managed_key_id"}
246+
var workspaceRunningUpdatesAllowed = []string{"credentials_id", "network_id", "storage_customer_managed_key_id", "private_access_settings_id", "managed_services_customer_managed_key_id"}
247247

248248
// UpdateRunning will update running workspace with couple of possible fields
249249
func (a WorkspacesAPI) UpdateRunning(ws Workspace, timeout time.Duration) error {
@@ -253,11 +253,12 @@ func (a WorkspacesAPI) UpdateRunning(ws Workspace, timeout time.Duration) error
253253
// The ID of the workspace's network configuration object. Used only if you already use a customer-managed VPC.
254254
// This change is supported only if you specified a network configuration ID when the workspace was created.
255255
// In other words, you cannot switch from a Databricks-managed VPC to a customer-managed VPC. This parameter
256-
// is available for updating both failed and running workspaces. Note: You cannot use a network configuration
257-
// update in this API to add support for PrivateLink (in Public Preview). To add PrivateLink to an existing
258-
// workspace, contact your Databricks representative.
256+
// is available for updating both failed and running workspaces.
259257
"network_id": ws.NetworkID,
260258
}
259+
if ws.PrivateAccessSettingsID != "" {
260+
request["private_access_settings_id"] = ws.PrivateAccessSettingsID
261+
}
261262
if ws.StorageCustomerManagedKeyID != "" {
262263
request["storage_customer_managed_key_id"] = ws.StorageCustomerManagedKeyID
263264
}
@@ -545,6 +546,13 @@ func ResourceMwsWorkspaces() *schema.Resource {
545546
}
546547
return NewWorkspacesAPI(ctx, c).Delete(accountID, workspaceID)
547548
},
549+
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, m any) error {
550+
old, new := d.GetChange("private_access_settings_id")
551+
if old != "" && new == "" {
552+
return fmt.Errorf("cannot remove private access setting from workspace")
553+
}
554+
return nil
555+
},
548556
Timeouts: &schema.ResourceTimeout{
549557
Create: schema.DefaultTimeout(DefaultProvisionTimeout),
550558
Read: schema.DefaultTimeout(DefaultProvisionTimeout),

mws/resource_mws_workspaces_test.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,3 +1234,108 @@ func TestExplainWorkspaceFailureCornerCase(t *testing.T) {
12341234
}), "failed to start workspace. Cannot read network: 🐜")
12351235
})
12361236
}
1237+
1238+
func TestResourceWorkspaceUpdatePrivateAccessSettings(t *testing.T) {
1239+
d, err := qa.ResourceFixture{
1240+
Fixtures: []qa.HTTPFixture{
1241+
{
1242+
Method: "PATCH",
1243+
Resource: "/api/2.0/accounts/abc/workspaces/1234",
1244+
ExpectedRequest: map[string]any{
1245+
"credentials_id": "bcd",
1246+
"network_id": "fgh",
1247+
"storage_customer_managed_key_id": "def",
1248+
"private_access_settings_id": "pas",
1249+
},
1250+
},
1251+
{
1252+
Method: "GET",
1253+
ReuseRequest: true,
1254+
Resource: "/api/2.0/accounts/abc/workspaces/1234",
1255+
Response: Workspace{
1256+
WorkspaceStatus: WorkspaceStatusRunning,
1257+
WorkspaceName: "labdata",
1258+
DeploymentName: "900150983cd24fb0",
1259+
AwsRegion: "us-east-1",
1260+
CredentialsID: "bcd",
1261+
StorageConfigurationID: "ghi",
1262+
NetworkID: "fgh",
1263+
ManagedServicesCustomerManagedKeyID: "def",
1264+
StorageCustomerManagedKeyID: "def",
1265+
PrivateAccessSettingsID: "pas",
1266+
AccountID: "abc",
1267+
WorkspaceID: 1234,
1268+
},
1269+
},
1270+
},
1271+
Resource: ResourceMwsWorkspaces(),
1272+
InstanceState: map[string]string{
1273+
"account_id": "abc",
1274+
"aws_region": "us-east-1",
1275+
"credentials_id": "__OLDER__",
1276+
"managed_services_customer_managed_key_id": "def",
1277+
"storage_customer_managed_key_id": "__OLDER__",
1278+
"deployment_name": "900150983cd24fb0",
1279+
"workspace_name": "labdata",
1280+
"is_no_public_ip_enabled": "true",
1281+
"network_id": "fgh",
1282+
"storage_configuration_id": "ghi",
1283+
"workspace_id": "1234",
1284+
},
1285+
State: map[string]any{
1286+
"account_id": "abc",
1287+
"aws_region": "us-east-1",
1288+
"credentials_id": "bcd",
1289+
"managed_services_customer_managed_key_id": "def",
1290+
"storage_customer_managed_key_id": "def",
1291+
"deployment_name": "900150983cd24fb0",
1292+
"workspace_name": "labdata",
1293+
"is_no_public_ip_enabled": true,
1294+
"network_id": "fgh",
1295+
"storage_configuration_id": "ghi",
1296+
"private_access_settings_id": "pas",
1297+
"workspace_id": 1234,
1298+
},
1299+
Update: true,
1300+
ID: "abc/1234",
1301+
}.Apply(t)
1302+
assert.NoError(t, err, err)
1303+
assert.Equal(t, "abc/1234", d.Id(), "Id should be the same as in reading")
1304+
}
1305+
1306+
func TestResourceWorkspaceRemovePAS_NotAllowed(t *testing.T) {
1307+
qa.ResourceFixture{
1308+
Resource: ResourceMwsWorkspaces(),
1309+
InstanceState: map[string]string{
1310+
"account_id": "abc",
1311+
"aws_region": "us-east-1",
1312+
"credentials_id": "bcd",
1313+
"managed_services_customer_managed_key_id": "def",
1314+
"storage_customer_managed_key_id": "def",
1315+
"deployment_name": "900150983cd24fb0",
1316+
"workspace_name": "labdata",
1317+
"is_no_public_ip_enabled": "true",
1318+
"network_id": "fgh",
1319+
"storage_configuration_id": "ghi",
1320+
"workspace_id": "1234",
1321+
"private_access_settings_id": "pas",
1322+
},
1323+
State: map[string]any{
1324+
"account_id": "abc",
1325+
1326+
"aws_region": "us-east-1",
1327+
"credentials_id": "bcd",
1328+
"managed_services_customer_managed_key_id": "def",
1329+
"storage_customer_managed_key_id": "def",
1330+
"deployment_name": "900150983cd24fb0",
1331+
"workspace_name": "labdata",
1332+
"is_no_public_ip_enabled": true,
1333+
"network_id": "fgh",
1334+
"storage_configuration_id": "ghi",
1335+
"workspace_id": 1234,
1336+
"private_access_settings_id": "",
1337+
},
1338+
Update: true,
1339+
ID: "abc/1234",
1340+
}.ExpectError(t, "cannot remove private access setting from workspace")
1341+
}

0 commit comments

Comments
 (0)