Skip to content

Commit af25041

Browse files
authored
fix storage credential read (#2804)
1 parent 9f3658d commit af25041

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

catalog/resource_metastore_data_access.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ func adjustDataAccessSchema(m map[string]*schema.Schema) map[string]*schema.Sche
4242
m["gcp_service_account_key"].DiffSuppressFunc = SuppressGcpSAKeyDiff
4343

4444
common.MustSchemaPath(m, "azure_managed_identity", "credential_id").Computed = true
45+
common.MustSchemaPath(m, "databricks_gcp_service_account", "email").Computed = true
46+
common.MustSchemaPath(m, "databricks_gcp_service_account", "credential_id").Computed = true
4547

4648
m["force_destroy"] = &schema.Schema{
4749
Type: schema.TypeBool,
@@ -155,7 +157,7 @@ func ResourceMetastoreDataAccess() *schema.Resource {
155157
}
156158
isDefault := metastore.StorageRootCredentialName == dacName
157159
d.Set("is_default", isDefault)
158-
return common.StructToData(storageCredential, dacSchema, d)
160+
return common.StructToData(storageCredential.CredentialInfo, dacSchema, d)
159161
}, func(w *databricks.WorkspaceClient) error {
160162
var storageCredential *catalog.StorageCredentialInfo
161163
storageCredential, err = w.StorageCredentials.GetByName(ctx, dacName)

catalog/resource_metastore_data_access_test.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,12 @@ func TestCreateAccountDacWithAws(t *testing.T) {
210210
{
211211
Method: "GET",
212212
Resource: "/api/2.0/accounts/100/metastores/abc/storage-credentials/bcd?",
213-
Response: catalog.StorageCredentialInfo{
214-
Name: "bcd",
215-
AwsIamRole: &catalog.AwsIamRole{
216-
RoleArn: "def",
213+
Response: catalog.AccountsStorageCredentialInfo{
214+
CredentialInfo: &catalog.StorageCredentialInfo{
215+
Name: "bcd",
216+
AwsIamRole: &catalog.AwsIamRole{
217+
RoleArn: "def",
218+
},
217219
},
218220
},
219221
},
@@ -275,10 +277,12 @@ func TestCreateAccountDacWithAzMI(t *testing.T) {
275277
{
276278
Method: "GET",
277279
Resource: "/api/2.0/accounts/100/metastores/abc/storage-credentials/bcd?",
278-
Response: catalog.StorageCredentialInfo{
279-
Name: "bcd",
280-
AzureManagedIdentity: &catalog.AzureManagedIdentity{
281-
AccessConnectorId: "def",
280+
Response: catalog.AccountsStorageCredentialInfo{
281+
CredentialInfo: &catalog.StorageCredentialInfo{
282+
Name: "bcd",
283+
AzureManagedIdentity: &catalog.AzureManagedIdentity{
284+
AccessConnectorId: "def",
285+
},
282286
},
283287
},
284288
},
@@ -341,10 +345,12 @@ func TestCreateAccountDacWithDbGcpSA(t *testing.T) {
341345
{
342346
Method: "GET",
343347
Resource: "/api/2.0/accounts/100/metastores/abc/storage-credentials/bcd?",
344-
Response: catalog.StorageCredentialInfo{
345-
Name: "bcd",
346-
DatabricksGcpServiceAccount: &catalog.DatabricksGcpServiceAccountResponse{
347-
348+
Response: catalog.AccountsStorageCredentialInfo{
349+
CredentialInfo: &catalog.StorageCredentialInfo{
350+
Name: "bcd",
351+
DatabricksGcpServiceAccount: &catalog.DatabricksGcpServiceAccountResponse{
352+
353+
},
348354
},
349355
},
350356
},
@@ -367,5 +373,9 @@ func TestCreateAccountDacWithDbGcpSA(t *testing.T) {
367373
is_default = true
368374
databricks_gcp_service_account {}
369375
`,
370-
}.ApplyNoError(t)
376+
}.ApplyAndExpectData(t,
377+
map[string]any{
378+
"databricks_gcp_service_account.#": 1,
379+
"databricks_gcp_service_account.0.email": "[email protected]",
380+
})
371381
}

catalog/resource_storage_credential.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func ResourceStorageCredential() *schema.Resource {
107107
if err != nil {
108108
return err
109109
}
110-
return common.StructToData(storageCredential, storageCredentialSchema, d)
110+
return common.StructToData(storageCredential.CredentialInfo, storageCredentialSchema, d)
111111
}, func(w *databricks.WorkspaceClient) error {
112112
storageCredential, err := w.StorageCredentials.GetByName(ctx, d.Id())
113113
if err != nil {

0 commit comments

Comments
 (0)