From b39eeadbcaa9d00d2fb16302858500176518be49 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Fri, 3 Jan 2025 11:43:08 +0100 Subject: [PATCH 1/2] [Feature] Add `fallback` to `databricks_external_location` To support new feature I switched to use of Go SDK instead of manually crafted structure. --- catalog/resource_external_location.go | 28 +++++++++++----------- catalog/resource_external_location_test.go | 5 +++- docs/resources/external_location.md | 6 +++++ exporter/importables.go | 2 +- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/catalog/resource_external_location.go b/catalog/resource_external_location.go index 04985370ee..4c750b2352 100644 --- a/catalog/resource_external_location.go +++ b/catalog/resource_external_location.go @@ -11,17 +11,8 @@ import ( // This structure contains the fields of both catalog.UpdateExternalLocation and catalog.CreateExternalLocation type ExternalLocationInfo struct { - Name string `json:"name" tf:"force_new"` - URL string `json:"url"` - CredentialName string `json:"credential_name"` - Comment string `json:"comment,omitempty"` - SkipValidation bool `json:"skip_validation,omitempty"` - Owner string `json:"owner,omitempty" tf:"computed"` - MetastoreID string `json:"metastore_id,omitempty" tf:"computed"` - ReadOnly bool `json:"read_only,omitempty"` - AccessPoint string `json:"access_point,omitempty"` - EncDetails *catalog.EncryptionDetails `json:"encryption_details,omitempty"` - IsolationMode string `json:"isolation_mode,omitempty" tf:"computed"` + catalog.ExternalLocationInfo + SkipValidation bool `json:"skip_validation,omitempty"` } func ResourceExternalLocation() common.Resource { @@ -38,8 +29,15 @@ func ResourceExternalLocation() common.Resource { m["skip_validation"].DiffSuppressFunc = func(k, old, new string, d *schema.ResourceData) bool { return old == "false" && new == "true" } - m["url"].DiffSuppressFunc = ucDirectoryPathSlashOnlySuppressDiff - m["name"].DiffSuppressFunc = common.EqualFoldDiffSuppress + common.CustomizeSchemaPath(m, "url").SetRequired().SetCustomSuppressDiff(ucDirectoryPathSlashOnlySuppressDiff) + common.CustomizeSchemaPath(m, "name").SetRequired().SetCustomSuppressDiff(common.EqualFoldDiffSuppress) + common.CustomizeSchemaPath(m, "credential_name").SetRequired() + common.CustomizeSchemaPath(m, "isolation_mode").SetComputed() + common.CustomizeSchemaPath(m, "owner").SetComputed() + common.CustomizeSchemaPath(m, "metastore_id").SetComputed() + for _, key := range []string{"created_at", "created_by", "credential_id", "updated_at", "updated_by", "browse_only"} { + common.CustomizeSchemaPath(m, key).SetReadOnly() + } return m }) return common.Resource{ @@ -102,7 +100,6 @@ func ResourceExternalLocation() common.Resource { common.DataToStructPointer(d, s, &updateExternalLocationRequest) updateExternalLocationRequest.Name = d.Id() updateExternalLocationRequest.Force = force - if d.HasChange("owner") { _, err = w.ExternalLocations.Update(ctx, catalog.UpdateExternalLocation{ Name: updateExternalLocationRequest.Name, @@ -119,6 +116,9 @@ func ResourceExternalLocation() common.Resource { if d.HasChange("read_only") { updateExternalLocationRequest.ForceSendFields = append(updateExternalLocationRequest.ForceSendFields, "ReadOnly") } + if d.HasChange("fallback") { + updateExternalLocationRequest.ForceSendFields = append(updateExternalLocationRequest.ForceSendFields, "Fallback") + } updateExternalLocationRequest.Owner = "" _, err = w.ExternalLocations.Update(ctx, updateExternalLocationRequest) diff --git a/catalog/resource_external_location_test.go b/catalog/resource_external_location_test.go index c424bbc2fc..516589ee09 100644 --- a/catalog/resource_external_location_test.go +++ b/catalog/resource_external_location_test.go @@ -336,7 +336,8 @@ func TestUpdateExternalLocation_FromReadOnly(t *testing.T) { CredentialName: "bcd", Comment: "def", ReadOnly: false, - ForceSendFields: []string{"ReadOnly"}, + Fallback: false, + ForceSendFields: []string{"ReadOnly", "Fallback"}, }, }, { @@ -360,6 +361,7 @@ func TestUpdateExternalLocation_FromReadOnly(t *testing.T) { "credential_name": "abc", "comment": "def", "read_only": "true", + "fallback": "true", }, HCL: ` name = "abc" @@ -367,6 +369,7 @@ func TestUpdateExternalLocation_FromReadOnly(t *testing.T) { credential_name = "bcd" comment = "def" read_only = false + fallback = false `, }.ApplyNoError(t) } diff --git a/docs/resources/external_location.md b/docs/resources/external_location.md index 2495510bb0..22a9420730 100644 --- a/docs/resources/external_location.md +++ b/docs/resources/external_location.md @@ -124,6 +124,7 @@ The following arguments are required: - `owner` - (Optional) Username/groupname/sp application_id of the external location owner. - `comment` - (Optional) User-supplied free-form text. - `skip_validation` - (Optional) Suppress validation errors if any & force save the external location +- `fallback` - (Optional) Indicates whether fallback mode is enabled for this external location. When fallback mode is enabled, the access to the location falls back to cluster credentials if UC credentials are not sufficient. - `read_only` - (Optional) Indicates whether the external location is read-only. - `force_destroy` - (Optional) Destroy external location regardless of its dependents. - `force_update` - (Optional) Update external location regardless of its dependents. @@ -136,6 +137,11 @@ The following arguments are required: In addition to all arguments above, the following attributes are exported: - `id` - ID of this external location - same as `name`. +- `created_at` - Time at which this external location was created, in epoch milliseconds. +- `created_by` - Username of external location creator. +- `credential_id` - Unique ID of the location's storage credential. +- `updated_at` - Time at which external location this was last modified, in epoch milliseconds. +- `updated_by` - Username of user who last modified the external location. ## Import diff --git a/exporter/importables.go b/exporter/importables.go index aeb2650375..df03d4d9b2 100644 --- a/exporter/importables.go +++ b/exporter/importables.go @@ -3074,7 +3074,7 @@ var resourcesMap map[string]importable = map[string]importable{ // TODO: add check for "securable_kind":"EXTERNAL_LOCATION_DB_STORAGE" when we get it in the credential r.Mode = "data" data := tfcatalog.ResourceExternalLocation().ToResource().TestResourceData() - obj := tfcatalog.ExternalLocationInfo{Name: r.ID} + obj := tfcatalog.ExternalLocationInfo{ExternalLocationInfo: catalog.ExternalLocationInfo{Name: r.ID}} r.Data = ic.generateNewData(data, "databricks_external_location", r.ID, obj) } ic.emitUCGrantsWithOwner("external_location/"+r.ID, r) From 8f091650eab542f6f17506ae70cef21257ae42e2 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Fri, 3 Jan 2025 15:07:44 +0100 Subject: [PATCH 2/2] address code review comments --- docs/resources/external_location.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/resources/external_location.md b/docs/resources/external_location.md index 22a9420730..ce98ed0020 100644 --- a/docs/resources/external_location.md +++ b/docs/resources/external_location.md @@ -124,7 +124,7 @@ The following arguments are required: - `owner` - (Optional) Username/groupname/sp application_id of the external location owner. - `comment` - (Optional) User-supplied free-form text. - `skip_validation` - (Optional) Suppress validation errors if any & force save the external location -- `fallback` - (Optional) Indicates whether fallback mode is enabled for this external location. When fallback mode is enabled, the access to the location falls back to cluster credentials if UC credentials are not sufficient. +- `fallback` - (Optional) Indicates whether fallback mode is enabled for this external location. When fallback mode is enabled (disabled by default), the access to the location falls back to cluster credentials if UC credentials are not sufficient. - `read_only` - (Optional) Indicates whether the external location is read-only. - `force_destroy` - (Optional) Destroy external location regardless of its dependents. - `force_update` - (Optional) Update external location regardless of its dependents.