Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add fallback to databricks_external_location #4372

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
alexott marked this conversation as resolved.
Show resolved Hide resolved
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, the access to the location falls back to cluster credentials if UC credentials are not sufficient.
alexott marked this conversation as resolved.
Show resolved Hide resolved
- `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
Loading