terraformazure-databricksmetastore

databricks_metastores Data Source - I'm trying to use this in Azure to find out the metastore id. Getting the error invalid databricks account config


databricks_metastores Data Source issue:

terraform code used:

data "databricks_metastores" "all" {}

output "all_metastores" {
  value = data.databricks_metastores.all.ids
}

I have used the azure account level provider as below.

provider "databricks" {
  alias      = "azure_account"
  host       = "https://accounts.azuredatabricks.net"
  account_id = "valid account id" # provided valid account id
  auth_type  = "azure-cli"
}

Error:

Planning failed. Terraform encountered an error while generating this plan.

╷ │ Error: cannot read metastores: cannot get client metastores: invalid Databricks Account configuration │


│   `with data.databricks_metastores.all,
│   on main.tf line 59, in data "databricks_metastores" "all":
│   59: data "databricks_metastores" "all" {}

Could you please me to resolve this?

Trying to get the meatastore id


Solution

  • Fetching the IDs of Mutiple megastores using the terraform

    The issue seems to be with the way you try to access to the databricks accounts.

    Even though we provide the complete info in the provider to read all the info it's still failing to establish the connection for terraform to access the databricks account.

    Even I faced the same error with the mentioned configuration as this approach failed to read the metastore info as it fails to establish the connection in the first place.

    enter image description here

    To overcome the issue in reference the provider = databricks.accounts to terraform_registery document I tried to refer the registry inside the data module for metastores when helps in fetching the info we are looking for.

    Configuration:

    
    terraform {
      required_providers {
        azurerm = {
          source = "hashicorp/azurerm"
        }
        databricks = {
          source = "databricks/databricks"
        }
      }
    }
     
    provider "azurerm" {
      subscription_id = "xxxx-xxx-xxx-xxxx"
      features {}
    }
     
    data "azurerm_databricks_workspace" "this" {
      name                = "testsamplevksb"
      resource_group_name = "vksb-rg"
    }
     
    provider "databricks" {
      host = data.azurerm_databricks_workspace.this.workspace_url
    }
     
    provider "databricks" {
      alias      = "accounts"
      host       = "https://accounts.azuredatabricks.net"
      account_id = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    }
     
    data "databricks_metastores" "all" {
        provider      = databricks.accounts
    }
    
    output "all_metastores" {
      value = data.databricks_metastores.all.ids
    }
    

    my preexisting metastores list:

    enter image description here

    Deployement:

    enter image description here

    refer:

    databricks_metastore | Data Sources | databricks/databricks | Terraform | Terraform Registry

    databricks_metastores | Data Sources | databricks/databricks | Terraform | Terraform Registry

    azurerm_databricks_workspace | Resources | hashicorp/azurerm | Terraform | Terraform Registry