Skip to content

Commit 699716a

Browse files
authored
Fix update for databricks_storage_credential (#1403)
* flatten the array for storage credentials * add test for updating azmi
1 parent 7515dbe commit 699716a

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
lines changed

catalog/resource_storage_credential.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func ResourceStorageCredential() *schema.Resource {
4949
return m
5050
})
5151
update := updateFunctionFactory("/unity-catalog/storage-credentials", []string{
52-
"owner", "comment", "aws_iam_role", "azure_service_principal"})
52+
"owner", "comment", "aws_iam_role", "azure_service_principal", "azure_managed_identity"})
5353
return common.Resource{
5454
Schema: s,
5555
Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {

catalog/resource_storage_credential_test.go

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ func TestUpdateStorageCredentials(t *testing.T) {
104104
Method: "PATCH",
105105
Resource: "/api/2.1/unity-catalog/storage-credentials/a",
106106
ExpectedRequest: map[string]interface{}{
107-
"aws_iam_role": []interface{}{map[string]interface{}{
107+
"aws_iam_role": map[string]interface{}{
108108
"role_arn": "CHANGED",
109-
}},
109+
},
110110
},
111111
},
112112
{
@@ -178,3 +178,91 @@ func TestCreateStorageCredentialWithAzMI(t *testing.T) {
178178
`,
179179
}.ApplyNoError(t)
180180
}
181+
182+
func TestUpdateAzStorageCredentials(t *testing.T) {
183+
qa.ResourceFixture{
184+
Fixtures: []qa.HTTPFixture{
185+
{
186+
Method: "PATCH",
187+
Resource: "/api/2.1/unity-catalog/storage-credentials/a",
188+
ExpectedRequest: map[string]interface{}{
189+
"azure_service_principal": map[string]interface{}{
190+
"directory_id": "CHANGED",
191+
"application_id": "CHANGED",
192+
"client_secret": "CHANGED",
193+
},
194+
},
195+
},
196+
{
197+
Method: "GET",
198+
Resource: "/api/2.1/unity-catalog/storage-credentials/a",
199+
Response: StorageCredentialInfo{
200+
Name: "a",
201+
Azure: &AzureServicePrincipal{
202+
DirectoryID: "CHANGED",
203+
ApplicationID: "CHANGED",
204+
ClientSecret: "CHANGED",
205+
},
206+
MetastoreID: "d",
207+
},
208+
},
209+
},
210+
Resource: ResourceStorageCredential(),
211+
Update: true,
212+
ID: "a",
213+
InstanceState: map[string]string{
214+
"name": "a",
215+
"comment": "c",
216+
},
217+
HCL: `
218+
name = "a"
219+
azure_service_principal {
220+
directory_id = "CHANGED"
221+
application_id = "CHANGED"
222+
client_secret = "CHANGED"
223+
}
224+
comment = "c"
225+
`,
226+
}.ApplyNoError(t)
227+
}
228+
229+
func TestUpdateAzStorageCredentialMI(t *testing.T) {
230+
qa.ResourceFixture{
231+
Fixtures: []qa.HTTPFixture{
232+
{
233+
Method: "PATCH",
234+
Resource: "/api/2.1/unity-catalog/storage-credentials/a",
235+
ExpectedRequest: map[string]interface{}{
236+
"azure_managed_identity": map[string]interface{}{
237+
"access_connector_id": "CHANGED",
238+
},
239+
},
240+
},
241+
{
242+
Method: "GET",
243+
Resource: "/api/2.1/unity-catalog/storage-credentials/a",
244+
Response: StorageCredentialInfo{
245+
Name: "a",
246+
AzMI: &AzureManagedIdentity{
247+
AccessConnectorID: "CHANGED",
248+
},
249+
MetastoreID: "d",
250+
},
251+
},
252+
},
253+
Resource: ResourceStorageCredential(),
254+
Update: true,
255+
ID: "a",
256+
InstanceState: map[string]string{
257+
"name": "a",
258+
"comment": "c",
259+
},
260+
HCL: `
261+
name = "a"
262+
azure_managed_identity {
263+
access_connector_id = "CHANGED"
264+
}
265+
comment = "c"
266+
`,
267+
}.ApplyNoError(t)
268+
}

catalog/update.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ func updateFunctionFactory(pathPrefix string, updatable []string) func(context.C
3333
if !d.HasChange(field) {
3434
continue
3535
}
36+
37+
if contains([]string{
38+
"aws_iam_role",
39+
"azure_service_principal",
40+
"azure_managed_identity",
41+
}, field) {
42+
patch[field] = d.Get(field).([]interface{})[0]
43+
continue
44+
}
45+
3646
if field == "delta_sharing_scope" && old != new && new == "INTERNAL_AND_EXTERNAL" &&
3747
!d.HasChange("delta_sharing_recipient_token_lifetime_in_seconds") {
3848
patch["delta_sharing_recipient_token_lifetime_in_seconds"] =

0 commit comments

Comments
 (0)