cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to attach multiple libraries to a cluster terraform in Databricks

User16826994223
Honored Contributor III

I'm currently trying to attach more than one maven artifact to my terraform configuration of a cluster.

How can we add more than one artifact in my terraform configuration ?

3 REPLIES 3

User16826994223
Honored Contributor III

library {

maven {

coordinates = "..."

}

}

library {

maven {

coordinates = "..."

}

}

Simranarora
Databricks Employee
Databricks Employee

Hi @KunalGaurav,

This can be done by using a dynamic configuration block inside your databricks_cluster resource definition.

  • In variable.tf make a library block as:-
variable "listOfMavenPackages" {
  type = list(string)
  
  default = [ "com.google.guava:guava:23.0" , "com.google.protobuf:protobuf-java-util:3.17.3" ]
  
}
  • In main.tf, within databricks_cluster you may write as:-
resource "databricks_cluster" "shared_autoscaling" {
  cluster_name            = "Shared Autoscaling"
  spark_version           = data.databricks_spark_version.latest_lts.id
  node_type_id            = data.databricks_node_type.smallest.id
  autotermination_minutes = 20
  autoscale {
    min_workers = 1
    max_workers = 2
  }
  dynamic "library" {
    for_each = toset(var.listOfMavenPackages)
    content {
      maven {
        coordinates = library.value
      }
    }
  }
}
 

I hope this helps you.

Best Regards,
Simran

pac03
New Contributor II

Thank you, this was exactly what I've been looking for! A way to install packages dynamically. I can confirm it works great for other methods like pypi. If any moderators see this please add this method to the documentation as it is perfect for CICD. My example below.

 

locals {
  requirements = split("\n", trimspace(file("requirements_frozen.txt")))
}
 
  task {
    task_key = var.task_name

    job_cluster_key = "temp"
    spark_python_task {
      python_file = var.python_file
      source = var.task_source
      parameters = var.parameters
    }

   
    dynamic "library" {
      for_each = toset(local.requirements)
      content {
        pypi {
          package = library.value
        }
      }
    }
  }

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