Skip to content

Commit 85a19b5

Browse files
author
Artem Vovchenko
committed
feat: add service credential
1 parent 743741e commit 85a19b5

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

main.tf

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
resource "databricks_credential" "this" {
2+
name = var.service_credential.name
3+
owner = var.service_credential.owner
4+
purpose = "SERVICE"
5+
6+
# Dynamic block for Azure
7+
dynamic "azure_managed_identity" {
8+
for_each = var.cloud == "azure" ? [1] : []
9+
content {
10+
access_connector_id = var.service_credential.azure_access_connector_id
11+
}
12+
}
13+
14+
# Dynamic block for AWS
15+
dynamic "aws_iam_role" {
16+
for_each = var.cloud == "aws" ? [1] : []
17+
content {
18+
role_arn = var.service_credential.aws_iam_role_arn
19+
}
20+
}
21+
22+
# TDOO
23+
# Dynamic block for GCP
24+
# GCP is not yet supported
25+
# dynamic "databricks_gcp_service_account" {
26+
# for_each = var.cloud == "gcp" ? [1] : []
27+
# content {}
28+
#}
29+
30+
force_destroy = var.service_credential.force_destroy
31+
comment = var.service_credential.comment
32+
isolation_mode = var.service_credential.isolation_mode
33+
}
34+
35+
resource "databricks_grants" "credential" {
36+
count = length(var.service_credential_permissions) == 0 ? 0 : 1
37+
38+
credential = databricks_credential.this.id
39+
dynamic "grant" {
40+
for_each = var.service_credential_permissions
41+
content {
42+
principal = grant.value.principal
43+
privileges = grant.value.privileges
44+
}
45+
}
46+
}

outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "service_credential_name" {
2+
value = try(databricks_credential.this.name, null)
3+
description = "Service Credential name"
4+
}

variables.tf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
variable "service_credential" {
2+
type = object({
3+
azure_access_connector_id = optional(string, null) # Azure Databricks Access Connector Id
4+
aws_iam_role_arn = optional(string, null) # AWS IAM role ARN
5+
name = optional(string, null) # Custom whole name of resource
6+
owner = optional(string) # Owner of resource
7+
force_destroy = optional(bool, true)
8+
comment = optional(string, "Managed identity credential provisioned by Terraform")
9+
isolation_mode = optional(string, "ISOLATION_MODE_OPEN")
10+
})
11+
description = "Object with service credentials configuration attributes"
12+
}
13+
14+
variable "cloud" {
15+
type = string
16+
description = "Cloud (azure or aws)"
17+
}
18+
19+
variable "service_credential_permissions" {
20+
type = set(object({
21+
principal = string
22+
privileges = list(string)
23+
}))
24+
default = []
25+
description = "Permissions granted on service credential"
26+
}

versions.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_version = ">=1.0.0"
3+
4+
required_providers {
5+
azurerm = {
6+
source = "hashicorp/azurerm"
7+
version = ">= 4.0.1"
8+
}
9+
databricks = {
10+
source = "databricks/databricks"
11+
version = "~>1.0"
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)