Skip to content

Commit 58d257b

Browse files
authored
Updated databricks_mws_private_access_settings (#883)
* Added `private_access_level` and `allowed_vpc_endpoint_ids` * Made it possible to edit existing `databricks_mws_private_access_settings`
1 parent e01993d commit 58d257b

File tree

5 files changed

+77
-9
lines changed

5 files changed

+77
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Version changelog
22

3+
## 0.3.10
4+
5+
* Added `private_access_level` and `allowed_vpc_endpoint_ids` to `databricks_mws_private_access_settings` resource, which is also now updatable ([#867](https://github.com/databrickslabs/terraform-provider-databricks/issues/867)).
6+
37
## 0.3.9
48

59
* Added initial support for multiple task orchestration in `databricks_job` [#853](https://github.com/databrickslabs/terraform-provider-databricks/pull/853)

docs/resources/mws_private_access_settings.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ The following arguments are available:
5050
* `private_access_settings_name` - Name of Private Access Settings in Databricks Account
5151
* `public_access_enabled` (Boolean, Optional, `false` by default) - If `true`, the [databricks_mws_workspaces](mws_workspaces.md) can be accessed over the [databricks_mws_vpc_endpoint](mws_vpc_endpoint.md) as well as over the public network. In such a case, you could also configure an [databricks_ip_access_list](ip_access_list.md) for the workspace, to restrict the source networks that could be used to access it over the public network. If `false` (default), the workspace can be accessed only over VPC endpoints, and not over the public network.
5252
* `region` - Region of AWS VPC
53+
* `private_access_level` - (Optional) The private access level controls which VPC endpoints can connect to the UI or API of any workspace that attaches this private access settings object. `ANY` level access _(default)_ lets any [databricks_mws_vpc_endpoint](mws_vpc_endpoint.md) connect to your [databricks_mws_workspaces](mws_workspaces.md). `ACCOUNT` level access lets only [databricks_mws_vpc_endpoint](mws_vpc_endpoint.md) that are registered in your Databricks account connect to your [databricks_mws_workspaces](mws_workspaces.md). `ENDPOINT` level access lets only specified [databricks_mws_vpc_endpoint](mws_vpc_endpoint.md) connect to your workspace. Please see the `allowed_vpc_endpoint_ids` documentation for more details.
54+
* `allowed_vpc_endpoint_ids` - (Optional) An array of [databricks_mws_vpc_endpoint](mws_vpc_endpoint.md#vpc_endpoint_id) `vpc_endpoint_id` (not `id`). Only used when `private_access_level` is set to `ENDPOINT`. This is an allow list of [databricks_mws_vpc_endpoint](mws_vpc_endpoint.md) that in your account that can connect to your [databricks_mws_workspaces](mws_workspaces.md) over AWS PrivateLink. If hybrid access to your workspace is enabled by setting `public_access_enabled` to true, then this control only works for PrivateLink connections. To control how your workspace is accessed via public internet, see the article for [databricks_ip_access_list](ip_access_list.md).
5355

5456
## Attribute Reference
5557

mws/mws.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,14 @@ type VPCEndpoint struct {
166166

167167
// PrivateAccessSettings (PAS) is the object that contains all the information for creating an PrivateAccessSettings (PAS)
168168
type PrivateAccessSettings struct {
169-
AccountID string `json:"account_id,omitempty"`
170-
PasID string `json:"private_access_settings_id,omitempty" tf:"computed"`
171-
PasName string `json:"private_access_settings_name"`
172-
Region string `json:"region"`
173-
Status string `json:"status,omitempty" tf:"computed"`
174-
PublicAccessEnabled bool `json:"public_access_enabled,omitempty"`
169+
AccountID string `json:"account_id,omitempty"`
170+
PasID string `json:"private_access_settings_id,omitempty" tf:"computed"`
171+
PasName string `json:"private_access_settings_name"`
172+
Region string `json:"region"`
173+
Status string `json:"status,omitempty" tf:"computed"`
174+
PublicAccessEnabled bool `json:"public_access_enabled,omitempty"`
175+
PrivateAccessLevel string `json:"private_access_level,omitempty" tf:"default:ANY"`
176+
AllowedVpcEndpointIDS []string `json:"allowed_vpc_endpoint_ids,omitempty"`
175177
}
176178

177179
type externalCustomerInfo struct {

mws/resource_mws_pas.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ func (a PrivateAccessSettingsAPI) Read(mwsAcctID, pasID string) (PrivateAccessSe
3535
return pas, err
3636
}
3737

38+
func (a PrivateAccessSettingsAPI) Update(pas *PrivateAccessSettings) error {
39+
pasAPIPath := fmt.Sprintf("/accounts/%s/private-access-settings/%s", pas.AccountID, pas.PasID)
40+
return a.client.Put(a.context, pasAPIPath, pas)
41+
}
42+
3843
// Delete deletes the PAS object given a pas id
3944
func (a PrivateAccessSettingsAPI) Delete(mwsAcctID, pasID string) error {
4045
pasAPIPath := fmt.Sprintf("/accounts/%s/private-access-settings/%s", mwsAcctID, pasID)
@@ -85,6 +90,18 @@ func ResourcePrivateAccessSettings() *schema.Resource {
8590
}
8691
return common.StructToData(pas, s, d)
8792
},
93+
Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
94+
_, pasID, err := p.Unpack(d)
95+
if err != nil {
96+
return err
97+
}
98+
var pas PrivateAccessSettings
99+
if err := common.DataToStructPointer(d, s, &pas); err != nil {
100+
return err
101+
}
102+
pas.PasID = pasID
103+
return NewPrivateAccessSettingsAPI(ctx, c).Update(&pas)
104+
},
88105
Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
89106
accountID, pasID, err := p.Unpack(d)
90107
if err != nil {

mws/resource_mws_pas_test.go

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ func TestResourcePASCreate(t *testing.T) {
4949
Method: "POST",
5050
Resource: "/api/2.0/accounts/abc/private-access-settings",
5151
ExpectedRequest: PrivateAccessSettings{
52-
AccountID: "abc",
53-
Region: "ar",
54-
PasName: "pas_name",
52+
AccountID: "abc",
53+
Region: "ar",
54+
PasName: "pas_name",
55+
PrivateAccessLevel: "ANY",
5556
},
5657
Response: PrivateAccessSettings{
5758
PasID: "pas_id",
@@ -173,6 +174,48 @@ func TestResourcePAS_Error(t *testing.T) {
173174
assert.Equal(t, "abc/pas_id", d.Id(), "Id should not be empty for error reads")
174175
}
175176

177+
func TestResourcePAS_Update(t *testing.T) {
178+
qa.ResourceFixture{
179+
Fixtures: []qa.HTTPFixture{
180+
{
181+
Method: "PUT",
182+
Resource: "/api/2.0/accounts/abc/private-access-settings/pas_id",
183+
ExpectedRequest: PrivateAccessSettings{
184+
Region: "eu-west-1",
185+
PublicAccessEnabled: true,
186+
PrivateAccessLevel: "ENDPOINT",
187+
AccountID: "abc",
188+
PasID: "pas_id",
189+
PasName: "pas_name",
190+
AllowedVpcEndpointIDS: []string{"a", "b"},
191+
},
192+
},
193+
{
194+
Method: "GET",
195+
Resource: "/api/2.0/accounts/abc/private-access-settings/pas_id",
196+
Response: PrivateAccessSettings{
197+
Region: "eu-west-1",
198+
PublicAccessEnabled: true,
199+
AccountID: "abc",
200+
PasID: "pas_id",
201+
PasName: "pas_name",
202+
},
203+
},
204+
},
205+
Resource: ResourcePrivateAccessSettings(),
206+
Update: true,
207+
ID: "abc/pas_id",
208+
HCL: `
209+
account_id = "abc"
210+
private_access_settings_name = "pas_name"
211+
public_access_enabled = true
212+
region = "eu-west-1"
213+
private_access_level = "ENDPOINT"
214+
allowed_vpc_endpoint_ids = ["a", "b"]
215+
`,
216+
}.ApplyNoError(t)
217+
}
218+
176219
func TestResourcePASDelete(t *testing.T) {
177220
d, err := qa.ResourceFixture{
178221
Fixtures: []qa.HTTPFixture{

0 commit comments

Comments
 (0)