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
New Contributor III
New Contributor III

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
        }
      }
    }
  }
Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!