azureterraformazure-databricksterraform-provider-databricks

Is it possible to set role "account_admin" on Azure Databricks with Terraform?


I have ADB workspace and i want to create new user with Terraform and set role "Admin" to this workspace user.

I have ADB workspace, user and group. But I cannot assign user role "Admin" with Terraform:

resource "databricks_user" "user" { provider = databricks.azure_account display_name = "John Doe" user_name = "john_doe@gmail.com" workspace_access = true depends_on = [ resource.azurerm_databricks_workspace.this ] }

resource "databricks_user_role" "my_user_account_admin" { provider = databricks.azure_account user_id = databricks_user.user.id role = "account_admin" }

And I get an error:

023-09-06T14:36:50.175+0300 [ERROR] vertex "databricks_user_role.my_user_account_admin" error: cannot read user role: User has no role ╷ Error: cannot read user role: User has no role │ with databricks_user_role.my_user_account_admin, on main.tf line 223, in resource "databricks_user_role" "my_user_account_admin": 223: resource "databricks_user_role" "my_user_account_admin" {


Solution

  • Solution:

    data "databricks_group" "admins" {
      provider     = databricks.azure_account
      display_name = "admins"
    }
    
    resource "databricks_user" "user" { 
      provider = databricks.azure_account
      display_name = "John Doe"
      user_name = "john_doe@gmail.com"
      workspace_access = true 
      depends_on = [ resource.azurerm_databricks_workspace.this ]
    }
    
    resource "databricks_group_member" "user" {
      provider         = databricks.azure_account
      group_id         = data.databricks_group.admins.id
      member_id        = databricks_user.user.id
      depends_on       = [
        resource.azurerm_databricks_workspace.this
      ]
    }