Hi @apparentlymart , how are you? Hope you are doing fine.
I’m new on Terraform and I’m deploying the workflow jobs from Databricks with Terraform modules, to get the resource content from the saved json in folder.
I had the same problem with the tasks orders, because our team just can’t all the tasks ordered, so maybe a solution is to sort the list of tuples. Could you give me a hint how to do that? I spend a lot of time trying without success.
Json example:
{
"name": "notebook-job-test",
"email_notifications": {},
(...)
"tasks": [
{
"task_key": "task-job-two",
"notebook_task": {
"notebook_path": "/notebook/notebook-two
"source": "WORKSPACE"
},
"job_cluster_key": "job_cluster_test",
"timeout_seconds": 0,
"email_notifications": {}
},
{
"task_key": "task-job-one",
"notebook_task": {
"notebook_path": "/notebook/notebook-one",
"source": "WORKSPACE"
},
"job_cluster_key": "job_cluster_test",
"timeout_seconds": 0,
"email_notifications": {
"on_failure": [
"ext-harlem.jose@bbts.com.br"
]
}
}
],
"job_clusters": [{...}],
"format": "MULTI_TASK"
}
In my module file I read all the folder containing the json jobs:
locals {
job_files = fileset("../databricks/workflows/jobs/", "*.json")
job_data = [for f in local.job_files : jsondecode(file("../databricks/workflows/jobs/${f}"))]
}
And in my resource block every fields and blocks are being created dynamically from json files, but the last goal now is to order the tasks to avoid the behavior to suggest change in every plan and apply:
resource "databricks_job" "main" {
for_each = { for f in local.job_data : f.name => f }
name = lookup(each.value, "name", null)
min_retry_interval_millis = lookup(each.value, "min_retry_interval_millis", null)
always_running = lookup(each.value, "always_running", null)
tags = lookup(each.value, "tags", null)
retry_on_timeout = lookup(each.value, "retry_on_timeout", null)
max_retries = lookup(each.value, "max_retries", null)
timeout_seconds = lookup(each.value, "timeout_seconds", null)
max_concurrent_runs = lookup(each.value, "max_concurrent_runs", null)
dynamic "task" {
for_each = lookup(each.value, "tasks", null)[*]
# for_each = tolist(each.value.tasks)[*]
# for_each = {for task in each.value.tasks: task.task_key => task}
content {
task_key = lookup(each.value.tasks[task.key], "task_key", null)
existing_cluster_id = lookup(each.value.tasks[task.key], "existing_cluster_id", null)
job_cluster_key = lookup(each.value.tasks[task.key], "job_cluster_key", null)
timeout_seconds = lookup(each.value.tasks[task.key], "timeout_seconds", null)
(...)
}
}
(...)
}
So when a plan and apply command would be applied, the task block with task_key “task-job-one” should be created before than the task block with the task_key “task-job-two”. Could you help me please to figure out how to solve this issue?
Thank you now in advance.
Have a nice weekend.
Harlem Muniz