Skip to content

Commit 4697aa3

Browse files
authored
[Internal] Simplify databricks_storage_credential code (#4301)
## Changes <!-- Summary of your changes that are easy to understand --> Previously, the `DatabricksGcpServiceAccount` type was defined as `any` and the led to the problems sending the Create request. Now this type is declared as struct, so we don't need the workaround anymore. ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [ ] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [ ] relevant acceptance tests are passing - [x] using Go SDK
1 parent e48fa77 commit 4697aa3

File tree

3 files changed

+6
-25
lines changed

3 files changed

+6
-25
lines changed

catalog/resource_metastore_data_access.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,8 @@ func ResourceMetastoreDataAccess() common.Resource {
9090
Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
9191
metastoreId := d.Get("metastore_id").(string)
9292

93-
tmpSchema := removeGcpSaField(dacSchema)
9493
var create catalog.CreateStorageCredential
95-
common.DataToStructPointer(d, tmpSchema, &create)
96-
//manually add empty struct back for databricks_gcp_service_account
97-
if _, ok := d.GetOk("databricks_gcp_service_account"); ok {
98-
create.DatabricksGcpServiceAccount = &catalog.DatabricksGcpServiceAccountRequest{}
99-
}
94+
common.DataToStructPointer(d, dacSchema, &create)
10095

10196
return c.AccountOrWorkspaceRequest(func(acc *databricks.AccountClient) error {
10297
dac, err := acc.StorageCredentials.Create(ctx,

catalog/resource_storage_credential.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,14 @@ type StorageCredentialInfo struct {
2626
IsolationMode string `json:"isolation_mode,omitempty" tf:"computed"`
2727
}
2828

29-
func removeGcpSaField(originalSchema map[string]*schema.Schema) map[string]*schema.Schema {
30-
//common.DataToStructPointer(d, s, &create) will error out because of DatabricksGcpServiceAccount any
31-
tmpSchema := make(map[string]*schema.Schema)
32-
for k, v := range originalSchema {
33-
tmpSchema[k] = v
34-
}
35-
delete(tmpSchema, "databricks_gcp_service_account")
36-
return tmpSchema
37-
}
38-
3929
var storageCredentialSchema = common.StructToSchema(StorageCredentialInfo{},
4030
func(m map[string]*schema.Schema) map[string]*schema.Schema {
4131
m["storage_credential_id"] = &schema.Schema{
4232
Type: schema.TypeString,
4333
Computed: true,
4434
}
35+
common.MustSchemaPath(m, "databricks_gcp_service_account", "email").Computed = true
36+
common.MustSchemaPath(m, "databricks_gcp_service_account", "credential_id").Computed = true
4537
return adjustDataAccessSchema(m)
4638
})
4739

@@ -50,19 +42,13 @@ func ResourceStorageCredential() common.Resource {
5042
Schema: storageCredentialSchema,
5143
Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
5244
metastoreId := d.Get("metastore_id").(string)
53-
tmpSchema := removeGcpSaField(storageCredentialSchema)
5445

5546
var create catalog.CreateStorageCredential
5647
var update catalog.UpdateStorageCredential
57-
common.DataToStructPointer(d, tmpSchema, &create)
58-
common.DataToStructPointer(d, tmpSchema, &update)
48+
common.DataToStructPointer(d, storageCredentialSchema, &create)
49+
common.DataToStructPointer(d, storageCredentialSchema, &update)
5950
update.Name = d.Get("name").(string)
6051

61-
//manually add empty struct back for databricks_gcp_service_account
62-
if _, ok := d.GetOk("databricks_gcp_service_account"); ok {
63-
create.DatabricksGcpServiceAccount = &catalog.DatabricksGcpServiceAccountRequest{}
64-
}
65-
6652
return c.AccountOrWorkspaceRequest(func(acc *databricks.AccountClient) error {
6753
storageCredential, err := acc.StorageCredentials.Create(ctx,
6854
catalog.AccountsCreateStorageCredential{

docs/resources/storage_credential.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ resource "databricks_storage_credential" "external_mi" {
4646
}
4747
4848
resource "databricks_grants" "external_creds" {
49-
storage_credential = databricks_storage_credential.external.id
49+
storage_credential = databricks_storage_credential.external_mi.id
5050
grant {
5151
principal = "Data Engineers"
5252
privileges = ["CREATE_EXTERNAL_TABLE"]

0 commit comments

Comments
 (0)