Skip to content

Commit 82954cc

Browse files
authored
Added preview for networks for GCP PSC (#2089)
1 parent d5de730 commit 82954cc

File tree

4 files changed

+110
-11
lines changed

4 files changed

+110
-11
lines changed

docs/resources/mws_networks.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,35 @@ resource "databricks_mws_networks" "this" {
153153
gcp_network_info {
154154
network_project_id = var.google_project
155155
vpc_id = google_compute_network.dbx_private_vpc.name
156-
subnet_id = google_compute_subnetwork.network-with-private-secondary-ip-ranges.name
157-
subnet_region = google_compute_subnetwork.network-with-private-secondary-ip-ranges.region
156+
subnet_id = google_compute_subnetwork.network_with_private_secondary_ip_ranges.name
157+
subnet_region = google_compute_subnetwork.network_with_private_secondary_ip_ranges.region
158158
pod_ip_range_name = "pods"
159159
service_ip_range_name = "svc"
160160
}
161161
}
162162
```
163163

164+
In order to create a VPC [that leverages GCP Private Service Connect](https://docs.gcp.databricks.com/administration-guide/cloud-configurations/gcp/private-service-connect.html) you would need to add the `vpc_endpoint_id` Attributes from [mws_vpc_endpoint](mws_vpc_endpoint.md) resources into the [databricks_mws_networks](databricks_mws_networks.md) resource. For example:
165+
166+
```hcl
167+
resource "databricks_mws_networks" "this" {
168+
account_id = var.databricks_account_id
169+
network_name = "test-demo-${random_string.suffix.result}"
170+
gcp_network_info {
171+
network_project_id = var.google_project
172+
vpc_id = google_compute_network.dbx_private_vpc.name
173+
subnet_id = google_compute_subnetwork.network_with_private_secondary_ip_ranges.name
174+
subnet_region = google_compute_subnetwork.network_with_private_secondary_ip_ranges.region
175+
pod_ip_range_name = "pods"
176+
service_ip_range_name = "svc"
177+
}
178+
vpc_endpoints {
179+
dataplane_relay = [databricks_mws_vpc_endpoint.relay.vpc_endpoint_id]
180+
rest_api = [databricks_mws_vpc_endpoint.workspace.vpc_endpoint_id]
181+
}
182+
}
183+
```
184+
164185
## Modifying networks on running workspaces (AWS only)
165186

166187
Due to specifics of platform APIs, changing any attribute of network configuration would cause `databricks_mws_networks` to be re-created - deleted & added again with special case for running workspaces. Once network configuration is attached to a running [databricks_mws_workspaces](mws_workspaces.md), you cannot delete it and `terraform apply` would result in `INVALID_STATE: Unable to delete, Network is being used by active workspace X` error. In order to modify any attributes of a network, you have to perform three different `terraform apply` steps:
@@ -178,7 +199,7 @@ The following arguments are available:
178199
* `vpc_id` - (AWS only) [aws_vpc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc) id
179200
* `subnet_ids` - (AWS only) ids of [aws_subnet](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/subnet)
180201
* `security_group_ids` - (AWS only) ids of [aws_security_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group)
181-
* `vpc_endpoints` - (Optional, AWS only) mapping of [databricks_mws_vpc_endpoint](mws_vpc_endpoint.md) for PrivateLink connections
202+
* `vpc_endpoints` - (Optional) mapping of [databricks_mws_vpc_endpoint](mws_vpc_endpoint.md) for PrivateLink or Private Service Connect connections
182203
* `gcp_network_info` - (GCP only) a block consists of Google Cloud specific information for this network, for example the VPC ID, subnet ID, and secondary IP ranges. It has the following fields:
183204
* `network_project_id` - The Google Cloud project ID of the VPC network.
184205
* `vpc_id` - The ID of the VPC associated with this network. VPC IDs can be used in multiple network configurations.
@@ -209,5 +230,5 @@ The following resources are used in the same context:
209230
* [Provisioning AWS Databricks E2 with a Hub & Spoke firewall for data exfiltration protection](../guides/aws-e2-firewall-hub-and-spoke.md) guide.
210231
* [Provisioning Databricks on GCP](../guides/gcp-workspace.md) guide.
211232
* [databricks_mws_vpc_endpoint](mws_vpc_endpoint.md) 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.
212-
* [databricks_mws_private_access_settings](mws_private_access_settings.md) 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).
233+
* [databricks_mws_private_access_settings](mws_private_access_settings.md) to create a Private Access Setting 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) or [GCP Private Service Connect] (https://docs.gcp.databricks.com/administration-guide/cloud-configurations/gcp/private-service-connect.html).
213234
* [databricks_mws_workspaces](mws_workspaces.md) to set up [workspaces in E2 architecture on AWS](https://docs.databricks.com/getting-started/overview.html#e2-architecture-1).

internal/acceptance/mws_networks_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,25 @@ func TestMwsAccNetworks(t *testing.T) {
2222
}`,
2323
})
2424
}
25+
26+
func TestMwsAccGcpPscNetworks(t *testing.T) {
27+
accountLevel(t, step{
28+
Template: `
29+
resource "databricks_mws_networks" "my_network" {
30+
account_id = "{env.DATABRICKS_ACCOUNT_ID}"
31+
network_name = "network-test-{var.RANDOM}"
32+
gcp_network_info {
33+
network_project_id = "{env.GOOGLE_PROJECT}"
34+
vpc_id = "{env.VPC_NETWORK_ID}"
35+
subnet_id = "{env.SUBNET_ID}"
36+
subnet_region = "{env.GOOGLE_REGION}"
37+
pod_ip_range_name = "{env.POD_IP_RANGE_NAME}"
38+
service_ip_range_name = "{env.SVC_IP_RANGE_NAME}"
39+
}
40+
vpc_endpoints {
41+
rest_api = ["{env.REST_API_VPCE_ID}"]
42+
dataplane_relay = ["{env.RELAY_VPCE_ID}"]
43+
}
44+
}`,
45+
})
46+
}

mws/resource_mws_networks.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ func ResourceMwsNetworks() *schema.Resource {
8080
s["vpc_id"].ExactlyOneOf = []string{"vpc_id", "gcp_network_info"}
8181
s["subnet_ids"].ExactlyOneOf = []string{"subnet_ids", "gcp_network_info"}
8282
s["security_group_ids"].ExactlyOneOf = []string{"security_group_ids", "gcp_network_info"}
83-
s["vpc_endpoints"].ConflictsWith = []string{"gcp_network_info"}
84-
s["gcp_network_info"].ConflictsWith = []string{"vpc_id", "subnet_ids", "security_group_ids", "vpc_endpoints"}
83+
s["gcp_network_info"].ConflictsWith = []string{"vpc_id", "subnet_ids", "security_group_ids"}
8584

8685
return s
8786
})

mws/resource_mws_networks_test.go

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestResourceNetworkCreate(t *testing.T) {
5454
}
5555

5656
func TestResourceNetworkCreate_GCP(t *testing.T) {
57-
d, err := qa.ResourceFixture{
57+
qa.ResourceFixture{
5858
Fixtures: []qa.HTTPFixture{
5959
{
6060
Method: "POST",
@@ -102,9 +102,67 @@ func TestResourceNetworkCreate_GCP(t *testing.T) {
102102
}
103103
`,
104104
Create: true,
105-
}.Apply(t)
106-
assert.NoError(t, err)
107-
assert.Equal(t, "abc/nid", d.Id())
105+
}.ApplyNoError(t)
106+
}
107+
108+
func TestResourceNetworkCreate_GCPPsc(t *testing.T) {
109+
qa.ResourceFixture{
110+
Fixtures: []qa.HTTPFixture{
111+
{
112+
Method: "POST",
113+
Resource: "/api/2.0/accounts/abc/networks",
114+
ExpectedRequest: Network{
115+
AccountID: "abc",
116+
NetworkName: "Open Workers",
117+
GcpNetworkInfo: &GcpNetworkInfo{
118+
NetworkProjectId: "project_a",
119+
VpcId: "vpc_a",
120+
SubnetId: "subnet_a",
121+
SubnetRegion: "region_a",
122+
PodIpRangeName: "pods",
123+
ServiceIpRangeName: "svc",
124+
},
125+
VPCEndpoints: &NetworkVPCEndpoints{
126+
RestAPI: []string{"rest_api_endpoint"},
127+
DataplaneRelayAPI: []string{"dataplane_relay_endpoint"},
128+
},
129+
},
130+
Response: Network{
131+
AccountID: "abc",
132+
NetworkID: "nid",
133+
},
134+
},
135+
{
136+
Method: "GET",
137+
Resource: "/api/2.0/accounts/abc/networks/nid",
138+
Response: Network{
139+
NetworkID: "nid",
140+
SecurityGroupIds: []string{"one", "two"},
141+
NetworkName: "Open Workers",
142+
VPCID: "five",
143+
SubnetIds: []string{"four", "three"},
144+
},
145+
},
146+
},
147+
Resource: ResourceMwsNetworks(),
148+
HCL: `
149+
account_id = "abc"
150+
network_name = "Open Workers"
151+
gcp_network_info {
152+
network_project_id = "project_a"
153+
vpc_id = "vpc_a"
154+
subnet_id = "subnet_a"
155+
subnet_region = "region_a"
156+
pod_ip_range_name = "pods"
157+
service_ip_range_name = "svc"
158+
}
159+
vpc_endpoints {
160+
rest_api = ["rest_api_endpoint"]
161+
dataplane_relay = ["dataplane_relay_endpoint"]
162+
}
163+
`,
164+
Create: true,
165+
}.ApplyNoError(t)
108166
}
109167

110168
func TestResourceNetworkCreate_ConflictErrors(t *testing.T) {
@@ -135,7 +193,6 @@ func TestResourceNetworkCreate_ConflictErrors(t *testing.T) {
135193
assert.ErrorContains(t, err, "[gcp_network_info] Conflicting configuration arguments")
136194
assert.ErrorContains(t, err, "[security_group_ids] Invalid combination of arguments")
137195
assert.ErrorContains(t, err, "[subnet_ids] Invalid combination of arguments")
138-
assert.ErrorContains(t, err, "[vpc_endpoints] Conflicting configuration arguments")
139196
assert.ErrorContains(t, err, "[vpc_id] Invalid combination of arguments")
140197
}
141198

0 commit comments

Comments
 (0)