databricks / cli

Databricks CLI
Other
148 stars 56 forks source link

Substitutions ${resouces.jobs.<job_name>.id} not working #1750

Closed aleksei-disney-nd closed 2 months ago

aleksei-disney-nd commented 2 months ago

Describe the issue

I am trying to define a job workflow that is going to trigger another jobs.

my files is as follow:

resources/cron_job.yml

resources:
  jobs:
    cron_job:
      name: cron_job_2
      tasks:
        - task_key: test_1
          run_job_task:
            job_id: ${resouces.jobs.job_a.id}
      queue:
        enabled: true

resources/job_a.yml

resources:
  jobs:

    job_a:
      name: job_a
      description: ""
      max_concurrent_runs: 1
      parameters:

job_a is deployed with no issue at all.

  1. databricks bundle deploy -t dev -p unity-nonprod states validation ok
  2. databricks bundle deploy -t dev -p unity-nonprod raises an error
    
    Error: exit status 1

Error: Reference to undeclared resource

on bundle.tf.json line 32, in resource.databricks_job.cron_job.task[0].run_job_task: 32: "job_id": "${resouces.jobs.job_a.id}"

A managed resource "resouces" "jobs" has not been declared in the root module.



As stated in the documentation I should be able to retrieve id dynamically with [substitutions](https://docs.databricks.com/en/dev-tools/bundles/settings.html#substitutions)

The version i am running on is `Databricks CLI v0.225.0`
andrewnester commented 2 months ago

Hi! You have a typo in the world resources in variables reference thus it's not replaced correctly

job_id: ${resouces.jobs.job_a.id} -> job_id: ${resources.jobs.job_a.id}

aleksei-disney-nd commented 2 months ago

hi @andrewnester it worked but now I am getting another error. What is weird is that for some jobs it does not raise an error

Warning: cannot parse "${resources.jobs.job_b.id}" as an integer
  at resources.jobs.cron_job.tasks[0].run_job_task.job_id
  in resources/cron_job.yml:8:21

Error: exit status 1

Error: Missing required argument

  on bundle.tf.json line 31, in resource.databricks_job.cron_job.task[0].run_job_task:
  31:             "run_job_task": {},

The argument "job_id" is required, but no definition was found.
andrewnester commented 2 months ago

Can you share how job_b job configuration look like? And also could you try to upgrade to the latest CLI (0.227.1) and see if the error persists?

aleksei-disney-nd commented 2 months ago

@andrewnester I think I figured it out. my job name had a double under score so let's say its real name was job__b whereas the previous one was job_a. I tried removing one underscore and reference it as job_b and it worked just fine. I also changed job_a to job__a and it rasied the same error. Could you think of any workaround this bug other than not have double undersocre which wil be my choice if no other available. Thank you so much for all your help so far.

andrewnester commented 2 months ago

Indeed, double underscores are not supported in variable and resources names at the moment. There is no a workaround except renaming but we are aware of the issue and investigating a solution.