From d87cd184e849f4934f5910afc4548699c1e0a123 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Thu, 3 Oct 2024 07:46:20 -0400 Subject: [PATCH] [Fix] force send `read_only` in `databricks_external_location` when it changed Resolves #4037 --- catalog/resource_external_location.go | 3 ++ catalog/resource_external_location_test.go | 47 ++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/catalog/resource_external_location.go b/catalog/resource_external_location.go index f21549cb98..04985370ee 100644 --- a/catalog/resource_external_location.go +++ b/catalog/resource_external_location.go @@ -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) diff --git a/catalog/resource_external_location_test.go b/catalog/resource_external_location_test.go index 26493c1005..c424bbc2fc 100644 --- a/catalog/resource_external_location_test.go +++ b/catalog/resource_external_location_test.go @@ -293,6 +293,7 @@ func TestUpdateExternalLocation(t *testing.T) { Url: "s3://foo/bar", CredentialName: "bcd", Comment: "def", + ReadOnly: false, }, }, { @@ -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{