cancel
Showing results for 
Search instead for 
Did you mean: 
Warehousing & Analytics
Engage in discussions on data warehousing, analytics, and BI solutions within the Databricks Community. Share insights, tips, and best practices for leveraging data for informed decision-making.
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I associate an account group with a workspace in Terraform?

Andrei_Radulesc
Contributor III

I can create account groups in Terraform as follows:

resource "databricks_group" "dev_perception" {

 provider    = databricks.mws

 display_name = "Perception"

}

Or I can create a workspace group, using the workspace provider instead of the account provider:

resource "databricks_group" "dev_perception" {

 provider    = databricks.dev_workspace

 display_name = "Perception"

}

However, the latter mechanism seems to be obsolete, b/c the UI only allows you to create account level groups.

What I would like to do is:

  • Create the account level group
  • Then, associate it to a workspace (so I can actually use it)

I can do this association in the UI. But how can I do the association in Terraform? I'd like to avoid mixing manual config with Terraform config.

1 ACCEPTED SOLUTION

Accepted Solutions

Pat
Honored Contributor III

Hi @Andrei Radulescu-Banu​ ,

to assign the 'account level group' to workspace you should use `databricks_mws_permission_assignment` resource, i.e.:

data "databricks_group" "this" {
  provider = databricks.mws
  for_each     = toset(keys(var.groups))
  display_name = each.key
}
 
resource "databricks_mws_permission_assignment" "this" {
  provider = databricks.mws
  for_each     = { for key, value in var.groups : key => value }
  workspace_id = var.workspace_id
  principal_id = data.databricks_group.this[each.key].id
  permissions  = [each.value.permissions]
}
 
-- example params:
workspace_id = "${dependency.workspace.outputs.databricks_workspace_id}"
    groups = {
      "data-engineers" = { permissions = "ADMIN" }
      "data-analysts"  = { permissions = "USER" }
    }

docs: https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/mws_permission_a...

View solution in original post

2 REPLIES 2

Pat
Honored Contributor III

Hi @Andrei Radulescu-Banu​ ,

to assign the 'account level group' to workspace you should use `databricks_mws_permission_assignment` resource, i.e.:

data "databricks_group" "this" {
  provider = databricks.mws
  for_each     = toset(keys(var.groups))
  display_name = each.key
}
 
resource "databricks_mws_permission_assignment" "this" {
  provider = databricks.mws
  for_each     = { for key, value in var.groups : key => value }
  workspace_id = var.workspace_id
  principal_id = data.databricks_group.this[each.key].id
  permissions  = [each.value.permissions]
}
 
-- example params:
workspace_id = "${dependency.workspace.outputs.databricks_workspace_id}"
    groups = {
      "data-engineers" = { permissions = "ADMIN" }
      "data-analysts"  = { permissions = "USER" }
    }

docs: https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/mws_permission_a...

Andrei_Radulesc
Contributor III

Thank you, that works!

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group