Skip to content

Commit 3077b79

Browse files
authored
[Feature] Allow to use GCP SA in databricks_credential (storage only) (#4302)
## Changes <!-- Summary of your changes that are easy to understand --> Right now, it's only possible to use it only with `purpose = "STORAGE"`. ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [x] relevant change in `docs/` folder - [x] covered with integration tests in `internal/acceptance` - [x] relevant acceptance tests are passing - [x] using Go SDK
1 parent a7cb6b7 commit 3077b79

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

catalog/resource_credential.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import (
1111

1212
var credentialSchema = common.StructToSchema(catalog.CredentialInfo{},
1313
func(m map[string]*schema.Schema) map[string]*schema.Schema {
14-
var alofServiceCreds = []string{"aws_iam_role", "azure_managed_identity", "azure_service_principal"}
14+
var alofServiceCreds = []string{"aws_iam_role", "azure_managed_identity", "azure_service_principal",
15+
"databricks_gcp_service_account"}
1516
for _, cred := range alofServiceCreds {
1617
common.CustomizeSchemaPath(m, cred).SetExactlyOneOf(alofServiceCreds)
1718
}
@@ -25,6 +26,10 @@ var credentialSchema = common.StructToSchema(catalog.CredentialInfo{},
2526
common.CustomizeSchemaPath(m, computed).SetComputed()
2627
}
2728

29+
common.CustomizeSchemaPath(m, "databricks_gcp_service_account").SetComputed()
30+
common.CustomizeSchemaPath(m, "databricks_gcp_service_account", "email").SetComputed()
31+
common.CustomizeSchemaPath(m, "databricks_gcp_service_account", "credential_id").SetComputed()
32+
common.CustomizeSchemaPath(m, "databricks_gcp_service_account", "private_key_id").SetComputed()
2833
common.MustSchemaPath(m, "aws_iam_role", "external_id").Computed = true
2934
common.MustSchemaPath(m, "aws_iam_role", "unity_catalog_iam_arn").Computed = true
3035
common.MustSchemaPath(m, "azure_managed_identity", "credential_id").Computed = true

docs/resources/credential.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,26 @@ resource "databricks_credential" "external_mi" {
5050
}
5151
5252
resource "databricks_grants" "external_creds" {
53-
credential = databricks_credential.external.id
53+
credential = databricks_credential.external_mi.id
54+
grant {
55+
principal = "Data Engineers"
56+
privileges = ["ACCESS"]
57+
}
58+
}
59+
```
60+
61+
For GCP (only applicable when purpose is `STORAGE`)
62+
63+
```hcl
64+
resource "databricks_credential" "external_gcp_sa" {
65+
name = "gcp_sa_credential"
66+
databricks_gcp_service_account {}
67+
purpose = "STORAGE"
68+
comment = "GCP SA credential managed by TF"
69+
}
70+
71+
resource "databricks_grants" "external_creds" {
72+
credential = databricks_credential.external_gcp_sa.id
5473
grant {
5574
principal = "Data Engineers"
5675
privileges = ["ACCESS"]
@@ -87,6 +106,11 @@ The following arguments are required:
87106
- `application_id` - The application ID of the application registration within the referenced AAD tenant
88107
- `client_secret` - The client secret generated for the above app ID in AAD. **This field is redacted on output**
89108

109+
`databricks_gcp_service_account` optional configuration block for creating a Databricks-managed GCP Service Account. Only applicable when purpose is `STORAGE`:
110+
111+
- `email` (output only) - The email of the GCP service account created, to be granted access to relevant buckets.
112+
113+
90114
## Attribute Reference
91115

92116
In addition to all arguments above, the following attributes are exported:

internal/acceptance/credential_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func TestUcAccCredential(t *testing.T) {
1010
UnityWorkspaceLevel(t, Step{
1111
Template: `
1212
resource "databricks_credential" "external" {
13-
name = "cred-{var.RANDOM}"
13+
name = "service-cred-{var.RANDOM}"
1414
aws_iam_role {
1515
role_arn = "{env.TEST_METASTORE_DATA_ACCESS_ARN}"
1616
}
@@ -19,6 +19,18 @@ func TestUcAccCredential(t *testing.T) {
1919
comment = "Managed by TF"
2020
}`,
2121
})
22+
} else if IsGcp(t) {
23+
UnityWorkspaceLevel(t, Step{
24+
// TODO: update purpose to SERVICE when it's released
25+
Template: `
26+
resource "databricks_credential" "external" {
27+
name = "storage-cred-{var.RANDOM}"
28+
databricks_gcp_service_account {}
29+
purpose = "STORAGE"
30+
skip_validation = true
31+
comment = "Managed by TF"
32+
}`,
33+
})
2234
}
2335
}
2436

0 commit comments

Comments
 (0)