cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
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
        }
      }
    }
  }
Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.