Skip to content

Commit 513ebfe

Browse files
willwwtalexottCopilot
authored
[Feature] Add databricks_disable_legacy_access_setting resource to disable legacy access methods (#4578)
## Changes <!-- Summary of your changes that are easy to understand --> Add the TF support for setting DisableLegacyAccess. ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [x] relevant change in `docs/` folder - [x] covered with integration tests in `internal/acceptance` - [ ] using Go SDK - [ ] using TF Plugin Framework --------- Co-authored-by: Alex Ott <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Alex Ott <[email protected]>
1 parent 9200fb9 commit 513ebfe

File tree

6 files changed

+452
-0
lines changed

6 files changed

+452
-0
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### New Features and Improvements
66

7+
* Add `databricks_disable_legacy_access_setting` resource to disable legacy access methods ([#4578](https://github.com/databricks/terraform-provider-databricks/pull/4578)).
78
* Customize and document `event_log` block in `databricks_pipeline` ([#4612](https://github.com/databricks/terraform-provider-databricks/pull/4612))
89
* Add automatic clustering support for `databricks_sql_table` ([#4607](https://github.com/databricks/terraform-provider-databricks/pull/4607))
910

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
subcategory: "Settings"
3+
---
4+
5+
# databricks_disable_legacy_access_setting Resource
6+
7+
-> This resource can only be used with a workspace-level provider!
8+
9+
The `databricks_disable_legacy_access_setting` resource allows you to disable legacy access. It has the following impact:
10+
11+
1. Disables direct access to Hive Metastores from the workspace. However, you can still access a Hive Metastore through Hive Metastore federation.
12+
2. Disables Fallback Mode on any External Location access from the workspace.
13+
3. Disables Databricks Runtime versions prior to 13.3LTS.
14+
15+
It may take 5 minutes to take effect and requires a restart of clusters and SQL warehouses.
16+
Please also set the default namespace using [databricks_default_namespace_setting](default_namespace_setting.md) to any value other than `hive_metastore` to avoid potential issues.
17+
18+
## Example Usage
19+
20+
```hcl
21+
resource "databricks_disable_legacy_access_setting" "this" {
22+
disable_legacy_access {
23+
value = true
24+
}
25+
}
26+
```
27+
28+
## Argument Reference
29+
30+
The resource supports the following arguments:
31+
32+
* `disable_legacy_access` - (Required) The configuration details.
33+
* `value` - (Required) The boolean value for the setting.
34+
35+
## Import
36+
37+
This resource can be imported by predefined name `global`:
38+
39+
```bash
40+
terraform import databricks_disable_legacy_access_setting.this global
41+
```

settings/all_settings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ func AllSettingsResources() map[string]common.Resource {
2222
"automatic_cluster_update_workspace": makeSettingResource[settings.AutomaticClusterUpdateSetting, *databricks.WorkspaceClient](automaticClusterUpdateSetting),
2323
"aibi_dashboard_embedding_access_policy": makeSettingResource[settings.AibiDashboardEmbeddingAccessPolicySetting, *databricks.WorkspaceClient](aibiDashboardEmbeddingAccessPolicySetting),
2424
"aibi_dashboard_embedding_approved_domains": makeSettingResource[settings.AibiDashboardEmbeddingApprovedDomainsSetting, *databricks.WorkspaceClient](aibiDashboardEmbeddingApprovedDomainsSetting),
25+
"disable_legacy_access": makeSettingResource[settings.DisableLegacyAccess, *databricks.WorkspaceClient](disableLegacyAccess),
2526
}
2627
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package settings_test
2+
3+
import (
4+
"context"
5+
"errors"
6+
"testing"
7+
8+
"github.com/databricks/databricks-sdk-go/apierr"
9+
"github.com/databricks/databricks-sdk-go/service/settings"
10+
"github.com/databricks/terraform-provider-databricks/common"
11+
"github.com/databricks/terraform-provider-databricks/internal/acceptance"
12+
"github.com/hashicorp/terraform-plugin-testing/terraform"
13+
"github.com/stretchr/testify/assert"
14+
"github.com/stretchr/testify/require"
15+
)
16+
17+
func TestAccDisableLegacyAccessSetting(t *testing.T) {
18+
template := `
19+
resource "databricks_disable_legacy_access_setting" "this" {
20+
disable_legacy_access {
21+
value = "true"
22+
}
23+
}
24+
`
25+
acceptance.WorkspaceLevel(t, acceptance.Step{
26+
Template: template,
27+
Check: acceptance.ResourceCheckWithState("databricks_disable_legacy_access_setting.this",
28+
func(ctx context.Context, client *common.DatabricksClient, state *terraform.InstanceState) error {
29+
ctx = context.WithValue(ctx, common.Api, common.API_2_1)
30+
w, err := client.WorkspaceClient()
31+
require.NoError(t, err)
32+
etag := state.Attributes["etag"]
33+
require.NotEmpty(t, etag)
34+
res, err := w.Settings.DisableLegacyAccess().Get(ctx, settings.GetDisableLegacyAccessRequest{
35+
Etag: etag,
36+
})
37+
require.NoError(t, err)
38+
// Check that the resource has been created and that it has the correct value.
39+
assert.True(t, res.DisableLegacyAccess.Value)
40+
return nil
41+
}),
42+
},
43+
acceptance.Step{
44+
Template: template,
45+
Destroy: true,
46+
Check: acceptance.ResourceCheck("databricks_disable_legacy_access_setting.this", func(ctx context.Context, client *common.DatabricksClient, id string) error {
47+
ctx = context.WithValue(ctx, common.Api, common.API_2_1)
48+
w, err := client.WorkspaceClient()
49+
require.NoError(t, err)
50+
// Terraform Check returns the latest resource status before it is destroyed, which has an outdated eTag.
51+
// We are making an update call to get the correct eTag in the response error.
52+
_, err = w.Settings.DisableLegacyAccess().Update(ctx, settings.UpdateDisableLegacyAccessRequest{
53+
AllowMissing: true,
54+
Setting: settings.DisableLegacyAccess{
55+
DisableLegacyAccess: settings.BooleanMessage{
56+
Value: false,
57+
},
58+
},
59+
FieldMask: "disable_legacy_access.value",
60+
})
61+
assert.Error(t, err)
62+
var aerr *apierr.APIError
63+
if !errors.As(err, &aerr) {
64+
assert.FailNow(t, "cannot parse error message %v", err)
65+
}
66+
etag := aerr.Details[0].Metadata["etag"]
67+
res, err := w.Settings.DisableLegacyAccess().Get(ctx, settings.GetDisableLegacyAccessRequest{
68+
Etag: etag,
69+
})
70+
// we should not be getting any error
71+
assert.NoError(t, err)
72+
// setting should go back to default
73+
assert.False(t, res.DisableLegacyAccess.Value)
74+
return nil
75+
}),
76+
},
77+
)
78+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package settings
2+
3+
import (
4+
"context"
5+
6+
"github.com/databricks/databricks-sdk-go"
7+
"github.com/databricks/databricks-sdk-go/service/settings"
8+
"github.com/databricks/terraform-provider-databricks/common"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
)
11+
12+
// Disable Legacy Access setting
13+
var disableLegacyAccess = workspaceSetting[settings.DisableLegacyAccess]{
14+
settingStruct: settings.DisableLegacyAccess{},
15+
customizeSchemaFunc: func(s map[string]*schema.Schema) map[string]*schema.Schema {
16+
common.CustomizeSchemaPath(s, "disable_legacy_access", "value").SetRequired()
17+
return s
18+
},
19+
readFunc: func(ctx context.Context, w *databricks.WorkspaceClient, etag string) (*settings.DisableLegacyAccess, error) {
20+
return w.Settings.DisableLegacyAccess().Get(ctx, settings.GetDisableLegacyAccessRequest{
21+
Etag: etag,
22+
})
23+
},
24+
updateFunc: func(ctx context.Context, w *databricks.WorkspaceClient, t settings.DisableLegacyAccess) (string, error) {
25+
t.SettingName = "disable_legacy_access"
26+
res, err := w.Settings.DisableLegacyAccess().Update(ctx, settings.UpdateDisableLegacyAccessRequest{
27+
AllowMissing: true,
28+
Setting: t,
29+
FieldMask: "disable_legacy_access.value",
30+
})
31+
if err != nil {
32+
return "", err
33+
}
34+
return res.Etag, nil
35+
},
36+
deleteFunc: func(ctx context.Context, w *databricks.WorkspaceClient, etag string) (string, error) {
37+
res, err := w.Settings.DisableLegacyAccess().Delete(ctx, settings.DeleteDisableLegacyAccessRequest{
38+
Etag: etag,
39+
})
40+
if err != nil {
41+
return "", err
42+
}
43+
return res.Etag, err
44+
},
45+
}

0 commit comments

Comments
 (0)