Skip to content

Commit

Permalink
[Feature] Add fallback to databricks_external_location (#4372)
Browse files Browse the repository at this point in the history
## Changes
<!-- Summary of your changes that are easy to understand -->

To support the new feature, I switched to the use of Go SDK instead of a
manually crafted structure.

Resolves #4369


## 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`
- [x] using Go SDK
- [ ] using TF Plugin Framework
  • Loading branch information
alexott authored Jan 3, 2025
1 parent abb2b36 commit b15e372
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
28 changes: 14 additions & 14 deletions catalog/resource_external_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion catalog/resource_external_location_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
{
Expand All @@ -360,13 +361,15 @@ func TestUpdateExternalLocation_FromReadOnly(t *testing.T) {
"credential_name": "abc",
"comment": "def",
"read_only": "true",
"fallback": "true",
},
HCL: `
name = "abc"
url = "s3://foo/bar"
credential_name = "bcd"
comment = "def"
read_only = false
fallback = false
`,
}.ApplyNoError(t)
}
Expand Down
6 changes: 6 additions & 0 deletions docs/resources/external_location.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (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.
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion exporter/importables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b15e372

Please sign in to comment.