Skip to content

Commit

Permalink
[Fix] force send read_only in databricks_external_location when i…
Browse files Browse the repository at this point in the history
…t changed

Resolves #4037
  • Loading branch information
alexott committed Oct 3, 2024
1 parent 1da7d93 commit d87cd18
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions catalog/resource_external_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ func ResourceExternalLocation() common.Resource {
if !d.HasChangeExcept("owner") {
return nil
}
if d.HasChange("read_only") {
updateExternalLocationRequest.ForceSendFields = append(updateExternalLocationRequest.ForceSendFields, "ReadOnly")
}

updateExternalLocationRequest.Owner = ""
_, err = w.ExternalLocations.Update(ctx, updateExternalLocationRequest)
Expand Down
47 changes: 47 additions & 0 deletions catalog/resource_external_location_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ func TestUpdateExternalLocation(t *testing.T) {
Url: "s3://foo/bar",
CredentialName: "bcd",
Comment: "def",
ReadOnly: false,
},
},
{
Expand Down Expand Up @@ -324,6 +325,52 @@ func TestUpdateExternalLocation(t *testing.T) {
}.ApplyNoError(t)
}

func TestUpdateExternalLocation_FromReadOnly(t *testing.T) {
qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "PATCH",
Resource: "/api/2.1/unity-catalog/external-locations/abc",
ExpectedRequest: catalog.UpdateExternalLocation{
Url: "s3://foo/bar",
CredentialName: "bcd",
Comment: "def",
ReadOnly: false,
ForceSendFields: []string{"ReadOnly"},
},
},
{
Method: "GET",
Resource: "/api/2.1/unity-catalog/external-locations/abc?",
Response: catalog.ExternalLocationInfo{
Name: "abc",
Url: "s3://foo/bar",
CredentialName: "bcd",
Comment: "def",
ReadOnly: false,
},
},
},
Resource: ResourceExternalLocation(),
Update: true,
ID: "abc",
InstanceState: map[string]string{
"name": "abc",
"url": "s3://foo/bar",
"credential_name": "abc",
"comment": "def",
"read_only": "true",
},
HCL: `
name = "abc"
url = "s3://foo/bar"
credential_name = "bcd"
comment = "def"
read_only = false
`,
}.ApplyNoError(t)
}

func TestUpdateExternalLocationOnlyOwner(t *testing.T) {
qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
Expand Down

0 comments on commit d87cd18

Please sign in to comment.