0

我想使用以下块授予两个用户使用 Azure Databricks 的访问权限:

resource "databricks_user" "dbuser" {
  display_name     = local.name.display_name
  user_name        = local.name.user_name
  workspace_access = true
}

我的本地人定义如下:

locals {
  name = {
    display_name = ["Vincent Casinha",
      "Susan Young"
    ]
    user_name = ["vincent.casinha@contoso.com",
    "susan.young@contoso.com"]
  }
}

在尝试运行 terraform 在此处输入图像描述plan 时,我收到了附加错误。如何在参数 display_name 和 user_name 的 databricks_user 块中正确使用本地值?

4

1 回答 1

2
locals {
    display_name = ["Vincent Casinha", "Susan Young"]
    user_name = ["vincent.casinha@contoso.com","susan.young@contoso.com"]
}


#assuming length of display_name and user_name are same
resource "databricks_user" "dbuser" {
  count            = length(local.display_name)
  display_name     = local.display_name[count.index]
  user_name        = local.user_name[count.index]
  workspace_access = true
}

#或者你可以像下面这样

locals {
    name = [
    {
        display_name = "Vincent Casinha"
        user_name = "vincent.casinha@contoso.com"
    },
    {
        display_name = "Susan Young"
        user_name = "susan.young@contoso.com"
    }
  ] 
}

resource "databricks_user" "dbuser" {
    for_each         = local.name
    display_name     = each.value.display_name
    user_name        = each.value.user_name
    workspace_access = true
}
于 2021-11-12T05:11:18.700 回答