terraformazure-databrickshashicorp

Passing the alias databricks provider - terraform


Sorry for the very long code. I want to create the group on the account level and also deploy SQL warehouses on workspace level. I understand that I need to pass two different providers in this case (alias) but I'm doing it wrong, I suppose.

I have the following structure where I keep all the terraform files:

├── dev/
    └── groups.auto.tfvars
    └── sql_warehouses.auto.tfvars
    └── main.tf
    └── variable.tf
├── modules/
    └── main.tf
    └── locals.tf
    └── variable.tf
    └── databricks_groups.tf
    └── databricks_sql_warehouses.tf
    resources/
         groups/
          └── main.tf
          └── module.tf
          └── variables.tf
         sql_warehouses/
          └── main.tf
          └── module.tf
          └── variables.tf

Let me present what I have in each file.

So from the top dev/:

main.tf

terraform {
  backend "azurerm" {
    # container_name = "databricks"
    key            = "terraform.tfstate"
  }
  required_providers {
    databricks = {
      source  = "databricks/databricks"
      version = "1.23.0"
    }
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.35.0"
    }
  }
}
locals {
  tenant_id       = var.tenant_id
  subscription_id = var.subscription_id
}
# PROVIDER REGISTRATION
provider "azurerm" {
  features {}
  storage_use_azuread        = false
  skip_provider_registration = true
  tenant_id                  = local.tenant_id
  subscription_id            = local.subscription_id
}

provider "databricks" {
  azure_workspace_resource_id = 
 data.azurerm_databricks_workspace.workspace.id
  host                        = 
data.azurerm_databricks_workspace.workspace.workspace_url
}

locals {
  account_id       = var.tenant_id
}
provider "databricks" {
  alias      = "azure_account"
  host       = "https://accounts.azuredatabricks.net"
  account_id = var.account_id
  auth_type  = "azure-cli"
}
module "this" {
  source = "../modules"

  # tags            = var.tags
  global_settings = var.global_settings
  databricks = {
    databricks_sql_warehouse           = 
  var.databricks_sql_warehouse
    databricks_groups                  = var.databricks_groups
  }
} 

Then we go to modules/

main.tf

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 3.35.0"
    }
    azuread = {
      source  = "hashicorp/azuread"
      version = "~> 2.22.0"
    }
    databricks = {
      source  = "databricks/databricks"
      version = "1.23.0"
      configuration_aliases = databricks.azure_account 
    }
  }
}
data "azurerm_subscription" "primary" {}
data "azurerm_client_config" "current" {}

local.tf

locals {
    databricks = {
        databricks_groups = 
  try(var.databricks.databricks_groups, {})
        databricks_sql_warehouse = 
  try(var.databricks.databricks_sql_warehouse, {})
    }
  }

databricks_groups.tf

  module "databricks_groups" {
  source   = "./modules/groups"
  for_each = local.databricks.databricks_groups

  settings = each.value

  providers = {
    databricks =databricks.azure_account
  }
  }

then we going inside resources and there I have groups folder with files:

main.tf

terraform {
required_providers {
databricks = {
  source  = "databricks/databricks"
  version = "1.23.0"
  configuration_aliases = databricks.azure_account 
}
}
}

and my module.tf looks like this

resource "databricks_group" "this" {
  provider     = databricks.azure_account
  display_name = var.settings.aad_groups
}

Could you please help me to identify where I'm making a mistake?

My error points to main.tf file in the modules folder

configuration_aliases = databricks.azure_account
A static list expression is required.


Solution

  • When Terraform says "a static list expression", it means a series of expressions in brackets [ ], separated by commas ,.

    You only have one configuration alias to specify, so you don't need any commas but you do still need the brackets to satisfy the requirement that it be a "static list expression":

      configuration_aliases = [databricks.azure_account]
    

    Fixing this one syntax error may reveal other problems, since the syntax error will be blocking Terraform from starting semantic validation. If so, I suggest starting a new question about that because Stack Overflow's Q&A format does not really work for answering follow-up questions.