Skip to content

Commit 016df8f

Browse files
authored
Update UC Azure guide to use MI (#1543)
1 parent 71dbcb9 commit 016df8f

File tree

2 files changed

+63
-102
lines changed

2 files changed

+63
-102
lines changed

docs/guides/unity-catalog-azure.md

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ page_title: "Unity Catalog set up on Azure"
44

55
# Deploying pre-requisite resources and enabling Unity Catalog (Azure Preview)
66

7-
-> **Public Preview** This feature is in [Public Preview](https://docs.microsoft.com/en-us/azure/databricks/data-governance/unity-catalog). Contact your Databricks representative to request access.
7+
-> **Public Preview** This feature is in [Public Preview](https://docs.microsoft.com/en-us/azure/databricks/data-governance/unity-catalog). Contact your Databricks representative to request access.
88

99
Databricks Unity Catalog brings fine-grained governance and security to Lakehouse data using a familiar, open interface. You can use Terraform to deploy the underlying cloud resources and Unity Catalog objects automatically, using a programmatic approach.
1010

@@ -15,6 +15,7 @@ This guide uses the following variables in configurations:
1515
This guide is provided as-is and you can use this guide as the basis for your custom Terraform module.
1616

1717
To get started with Unity Catalog, this guide takes you throw the following high-level steps:
18+
1819
- [Deploying pre-requisite resources and enabling Unity Catalog (Azure Preview)](#deploying-pre-requisite-resources-and-enabling-unity-catalog-azure-preview)
1920
- [Provider initialization](#provider-initialization)
2021
- [Configure Azure objects](#configure-azure-objects)
@@ -61,22 +62,20 @@ data "azurerm_databricks_workspace" "this" {
6162
```hcl
6263
terraform {
6364
required_providers {
64-
azurerm = {
65-
source = "hashicorp/azurerm"
66-
version = "~>2.99.0"
65+
azapi = {
66+
source = "azure/azapi"
6767
}
68-
azuread = {
69-
source = "hashicorp/azuread"
70-
version = "~>2.19.0"
68+
azurerm = {
69+
source = "hashicorp/azurerm"
7170
}
7271
databricks = {
7372
source = "databricks/databricks"
7473
}
7574
}
7675
}
7776
78-
provider "azuread" {
79-
tenant_id = local.tenant_id
77+
provider "azapi" {
78+
subscription_id = local.subscription_id
8079
}
8180
8281
provider "azurerm" {
@@ -90,22 +89,24 @@ provider "databricks" {
9089
```
9190

9291
## Configure Azure objects
92+
9393
The first step is to create the required Azure objects:
94+
9495
- An Azure storage account, which is the default storage location for managed tables in Unity Catalog. Please use a dedicated account for each metastore.
95-
- An AAD service principal that provides Unity Catalog permissions to access and manage data in the bucket.
96+
- A Databricks Access Connector that provides Unity Catalog permissions to access and manage data in the storage account.
9697

9798
```hcl
98-
resource "azuread_application" "unity_catalog" {
99-
display_name = "${local.prefix}-root-sp"
100-
}
101-
102-
resource "azuread_application_password" "unity_catalog" {
103-
application_object_id = azuread_application.unity_catalog.object_id
104-
}
105-
106-
resource "azuread_service_principal" "unity_catalog" {
107-
application_id = azuread_application.unity_catalog.application_id
108-
app_role_assignment_required = false
99+
resource "azapi_resource" "access_connector" {
100+
type = "Microsoft.Databricks/accessConnectors@2022-04-01-preview"
101+
name = "${local.prefix}-databricks-mi"
102+
location = data.azurerm_resource_group.this.location
103+
parent_id = data.azurerm_resource_group.this.id
104+
identity {
105+
type = "SystemAssigned"
106+
}
107+
body = jsonencode({
108+
properties = {}
109+
})
109110
}
110111
111112
resource "azurerm_storage_account" "unity_catalog" {
@@ -127,7 +128,7 @@ resource "azurerm_storage_container" "unity_catalog" {
127128
resource "azurerm_role_assignment" "example" {
128129
scope = azurerm_storage_account.unity_catalog.id
129130
role_definition_name = "Storage Blob Data Contributor"
130-
principal_id = azuread_service_principal.unity_catalog.object_id
131+
principal_id = azapi_resource.access_connector.identity[0].principal_id
131132
}
132133
```
133134

@@ -147,10 +148,8 @@ resource "databricks_metastore" "this" {
147148
resource "databricks_metastore_data_access" "first" {
148149
metastore_id = databricks_metastore.this.id
149150
name = "the-keys"
150-
azure_service_principal {
151-
directory_id = local.tenant_id
152-
application_id = azuread_application.unity_catalog.application_id
153-
client_secret = azuread_application_password.unity_catalog.value
151+
azure_managed_identity {
152+
access_connector_id = azapi_resource.access_connector.id
154153
}
155154
156155
is_default = true
@@ -165,7 +164,7 @@ resource "databricks_metastore_assignment" "this" {
165164

166165
## Create Unity Catalog objects in the metastore
167166

168-
Each metastore exposes a 3-level namespace (catalog-schema-table) by which data can be organized.
167+
Each metastore exposes a 3-level namespace (catalog-schema-table) by which data can be organized.
169168

170169
```hcl
171170
resource "databricks_catalog" "sandbox" {
@@ -211,23 +210,24 @@ resource "databricks_grants" "things" {
211210
## Configure external tables and credentials
212211

213212
To work with external tables, Unity Catalog introduces two new objects to access and work with external cloud storage:
214-
- [databricks_storage_credential](../resources/storage_credential.md) represent authentication methods to access cloud storage (e.g. an IAM role for Amazon S3 or a service principal for Azure Storage). Storage credentials are access-controlled to determine which users can use the credential.
215-
- [databricks_external_location](../resources/external_location.md) are objects that combine a cloud storage path with a Storage Credential that can be used to access the location.
213+
214+
- [databricks_storage_credential](../resources/storage_credential.md) represent authentication methods to access cloud storage (e.g. an IAM role for Amazon S3 or a managed identity for Azure Storage). Storage credentials are access-controlled to determine which users can use the credential.
215+
- [databricks_external_location](../resources/external_location.md) are objects that combine a cloud storage path with a Storage Credential that can be used to access the location.
216216

217217
First, create the required objects in Azure.
218218

219219
```hcl
220-
resource "azuread_application" "ext_cred" {
221-
display_name = "${local.prefix}-cred"
222-
}
223-
224-
resource "azuread_application_password" "ext_cred" {
225-
application_object_id = azuread_application.ext_cred.object_id
226-
}
227-
228-
resource "azuread_service_principal" "ext_cred" {
229-
application_id = azuread_application.ext_cred.application_id
230-
app_role_assignment_required = false
220+
resource "azapi_resource" "ext_access_connector" {
221+
type = "Microsoft.Databricks/accessConnectors@2022-04-01-preview"
222+
name = "ext-databricks-mi"
223+
location = data.azurerm_resource_group.this.location
224+
parent_id = data.azurerm_resource_group.this.id
225+
identity {
226+
type = "SystemAssigned"
227+
}
228+
body = jsonencode({
229+
properties = {}
230+
})
231231
}
232232
233233
resource "azurerm_storage_account" "ext_storage" {
@@ -249,19 +249,16 @@ resource "azurerm_storage_container" "ext_storage" {
249249
resource "azurerm_role_assignment" "ext_storage" {
250250
scope = azurerm_storage_account.ext_storage.id
251251
role_definition_name = "Storage Blob Data Contributor"
252-
principal_id = azuread_service_principal.ext_cred.object_id
253-
}
252+
principal_id = azapi_resource.ext_access_connector.identity[0].principal_id
254253
```
255254

256255
Then create the [databricks_storage_credential](../resources/storage_credential.md) and [databricks_external_location](../resources/external_location.md) in Unity Catalog.
257256

258257
```hcl
259258
resource "databricks_storage_credential" "external" {
260-
name = azuread_application.ext_cred.display_name
261-
azure_service_principal {
262-
directory_id = local.tenant_id
263-
application_id = azuread_application.ext_cred.application_id
264-
client_secret = azuread_application_password.ext_cred.value
259+
name = azapi_resource.ext_access_connector.name
260+
azure_managed_identity {
261+
access_connector_id = azapi_resource.ext_access_connector.id
265262
}
266263
comment = "Managed by TF"
267264
depends_on = [

docs/resources/storage_credential.md

Lines changed: 19 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -35,67 +35,31 @@ resource "databricks_grants" "external_creds" {
3535
For Azure
3636

3737
```hcl
38-
resource "azurerm_resource_group_template_deployment" "access_connector" {
39-
name = "databricks-access-connectors"
40-
resource_group_name = "vn-sandbox"
41-
deployment_mode = "Incremental"
42-
parameters_content = jsonencode({
43-
"connectorName" = {
44-
value = "vn-databricks-mi"
45-
}
46-
"accessConnectorRegion" = {
47-
value = "uksouth"
48-
}
49-
"enableSystemAssignedIdentity" = {
50-
value = true
51-
}
52-
})
53-
template_content = <<TEMPLATE
54-
{
55-
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
56-
"contentVersion": "1.0.0.0",
57-
"parameters": {
58-
"connectorName": {
59-
"defaultValue": "testConnector",
60-
"type": "String",
61-
"metadata": {
62-
"description": "The name of the Azure Databricks Access Connector to create."
63-
}
64-
},
65-
"accessConnectorRegion": {
66-
"defaultValue": "[resourceGroup().location]",
67-
"type": "String",
68-
"metadata": {
69-
"description": "Location for the access connector resource."
70-
}
71-
},
72-
"enableSystemAssignedIdentity": {
73-
"defaultValue": true,
74-
"type": "Bool",
75-
"metadata": {
76-
"description": "Whether the system assigned managed identity is enabled"
77-
}
78-
}
79-
},
80-
"resources": [
81-
{
82-
"type": "Microsoft.Databricks/accessConnectors",
83-
"apiVersion": "2022-04-01-preview",
84-
"name": "[parameters('connectorName')]",
85-
"location": "[parameters('accessConnectorRegion')]",
86-
"identity": {
87-
"type": "[if(parameters('enableSystemAssignedIdentity'), 'SystemAssigned', 'None')]"
88-
}
89-
}
90-
]
38+
data "azurerm_resource_group" "this" {
39+
name = "example-rg"
9140
}
92-
TEMPLATE
41+
42+
resource "azapi_resource" "access_connector" {
43+
type = "Microsoft.Databricks/accessConnectors@2022-04-01-preview"
44+
name = "example-databricks-mi"
45+
location = data.azurerm_resource_group.this.location
46+
parent_id = data.azurerm_resource_group.this.id
47+
tags = {
48+
tagName1 = "tagValue1"
49+
tagName2 = "tagValue2"
50+
}
51+
identity {
52+
type = "SystemAssigned"
53+
}
54+
body = jsonencode({
55+
properties = {}
56+
})
9357
}
9458
9559
resource "databricks_storage_credential" "external_mi" {
9660
name = "mi_credential"
9761
azure_managed_identity {
98-
access_connector_id = "${split("/Microsoft.Resources", azurerm_resource_group_template_deployment.access_connector.id)[0]}/Microsoft.Databricks/accessConnectors/${jsondecode(azurerm_resource_group_template_deployment.access_connector.parameters_content).connectorName.value}"
62+
access_connector_id = azapi_resource.access_connector.id
9963
}
10064
comment = "Managed identity credential managed by TF"
10165
}

0 commit comments

Comments
 (0)