diff --git a/catalog/resource_metastore_data_access.go b/catalog/resource_metastore_data_access.go index 5a32f8ff4..776ecca1c 100644 --- a/catalog/resource_metastore_data_access.go +++ b/catalog/resource_metastore_data_access.go @@ -90,13 +90,8 @@ func ResourceMetastoreDataAccess() common.Resource { Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { metastoreId := d.Get("metastore_id").(string) - tmpSchema := removeGcpSaField(dacSchema) var create catalog.CreateStorageCredential - common.DataToStructPointer(d, tmpSchema, &create) - //manually add empty struct back for databricks_gcp_service_account - if _, ok := d.GetOk("databricks_gcp_service_account"); ok { - create.DatabricksGcpServiceAccount = &catalog.DatabricksGcpServiceAccountRequest{} - } + common.DataToStructPointer(d, dacSchema, &create) return c.AccountOrWorkspaceRequest(func(acc *databricks.AccountClient) error { dac, err := acc.StorageCredentials.Create(ctx, diff --git a/catalog/resource_storage_credential.go b/catalog/resource_storage_credential.go index 17e7896ae..25a5a9ffd 100644 --- a/catalog/resource_storage_credential.go +++ b/catalog/resource_storage_credential.go @@ -26,22 +26,14 @@ type StorageCredentialInfo struct { IsolationMode string `json:"isolation_mode,omitempty" tf:"computed"` } -func removeGcpSaField(originalSchema map[string]*schema.Schema) map[string]*schema.Schema { - //common.DataToStructPointer(d, s, &create) will error out because of DatabricksGcpServiceAccount any - tmpSchema := make(map[string]*schema.Schema) - for k, v := range originalSchema { - tmpSchema[k] = v - } - delete(tmpSchema, "databricks_gcp_service_account") - return tmpSchema -} - var storageCredentialSchema = common.StructToSchema(StorageCredentialInfo{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { m["storage_credential_id"] = &schema.Schema{ Type: schema.TypeString, Computed: true, } + common.MustSchemaPath(m, "databricks_gcp_service_account", "email").Computed = true + common.MustSchemaPath(m, "databricks_gcp_service_account", "credential_id").Computed = true return adjustDataAccessSchema(m) }) @@ -50,19 +42,13 @@ func ResourceStorageCredential() common.Resource { Schema: storageCredentialSchema, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { metastoreId := d.Get("metastore_id").(string) - tmpSchema := removeGcpSaField(storageCredentialSchema) var create catalog.CreateStorageCredential var update catalog.UpdateStorageCredential - common.DataToStructPointer(d, tmpSchema, &create) - common.DataToStructPointer(d, tmpSchema, &update) + common.DataToStructPointer(d, storageCredentialSchema, &create) + common.DataToStructPointer(d, storageCredentialSchema, &update) update.Name = d.Get("name").(string) - //manually add empty struct back for databricks_gcp_service_account - if _, ok := d.GetOk("databricks_gcp_service_account"); ok { - create.DatabricksGcpServiceAccount = &catalog.DatabricksGcpServiceAccountRequest{} - } - return c.AccountOrWorkspaceRequest(func(acc *databricks.AccountClient) error { storageCredential, err := acc.StorageCredentials.Create(ctx, catalog.AccountsCreateStorageCredential{ diff --git a/docs/resources/storage_credential.md b/docs/resources/storage_credential.md index 8f9f63a84..c29653023 100644 --- a/docs/resources/storage_credential.md +++ b/docs/resources/storage_credential.md @@ -46,7 +46,7 @@ resource "databricks_storage_credential" "external_mi" { } resource "databricks_grants" "external_creds" { - storage_credential = databricks_storage_credential.external.id + storage_credential = databricks_storage_credential.external_mi.id grant { principal = "Data Engineers" privileges = ["CREATE_EXTERNAL_TABLE"]