From 0110db5d9e9c0cb044554d09bdcae152a8ec84fe Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Tue, 9 Apr 2024 13:59:02 +0200 Subject: [PATCH] Exporter: skip listing of jobs deployed with DABs Because these jobs could be deployed with DABs it makes little sense to export them into Terraform... --- docs/guides/experimental-exporter.md | 2 +- exporter/importables_test.go | 12 +++++++++++- exporter/util.go | 5 +++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/guides/experimental-exporter.md b/docs/guides/experimental-exporter.md index 2627919b2a..a4520da585 100644 --- a/docs/guides/experimental-exporter.md +++ b/docs/guides/experimental-exporter.md @@ -67,7 +67,7 @@ Services are just logical groups of resources used for filtering and organizatio * `directories` - **listing** [databricks_directory](../resources/directory.md). * `dlt` - **listing** [databricks_pipeline](../resources/pipeline.md). * `groups` - **listing** [databricks_group](../data-sources/group.md) with [membership](../resources/group_member.md) and [data access](../resources/group_instance_profile.md). -* `jobs` - **listing** [databricks_job](../resources/job.md). Usually, there are more automated jobs than interactive clusters, so they get their own file in this tool's output. +* `jobs` - **listing** [databricks_job](../resources/job.md). Usually, there are more automated workflows than interactive clusters, so they get their own file in this tool's output. *Please note that workflows deployed and maintained via [Databricks Asset Bundles](https://docs.databricks.com/en/dev-tools/bundles/index.html) aren't exported!* * `mlflow-webhooks` - **listing** [databricks_mlflow_webhook](../resources/mlflow_webhook.md). * `model-serving` - **listing** [databricks_model_serving](../resources/model_serving.md). * `mounts` - **listing** works only in combination with `-mounts` command-line option. diff --git a/exporter/importables_test.go b/exporter/importables_test.go index 6d026fd003..e8e0f4ecdf 100644 --- a/exporter/importables_test.go +++ b/exporter/importables_test.go @@ -14,6 +14,7 @@ import ( "github.com/databricks/databricks-sdk-go/service/catalog" "github.com/databricks/databricks-sdk-go/service/compute" "github.com/databricks/databricks-sdk-go/service/iam" + sdk_jobs "github.com/databricks/databricks-sdk-go/service/jobs" "github.com/databricks/databricks-sdk-go/service/sharing" sdk_workspace "github.com/databricks/databricks-sdk-go/service/workspace" tfcatalog "github.com/databricks/terraform-provider-databricks/catalog" @@ -434,7 +435,7 @@ func TestInstnacePoolsListWithMatch(t *testing.T) { }) } -func TestJobListNoNameMatch(t *testing.T) { +func TestJobListNoNameMatchOrFromBundles(t *testing.T) { ic := importContextForTest() ic.match = "bcd" ic.importJobs([]jobs.Job{ @@ -443,6 +444,15 @@ func TestJobListNoNameMatch(t *testing.T) { Name: "abc", }, }, + { + Settings: &jobs.JobSettings{ + Name: "bcd", + EditMode: "UI_LOCKED", + Deployment: &sdk_jobs.JobDeployment{ + Kind: "BUNDLE", + }, + }, + }, }) assert.Equal(t, 0, len(ic.testEmits)) } diff --git a/exporter/util.go b/exporter/util.go index e8153a77b5..55d2ae11b7 100644 --- a/exporter/util.go +++ b/exporter/util.go @@ -822,6 +822,11 @@ func (ic *importContext) importJobs(l []jobs.Job) { log.Printf("[INFO] Job name %s doesn't match selection %s", job.Settings.Name, ic.match) continue } + if job.Settings.Deployment != nil && job.Settings.Deployment.Kind == "BUNDLE" && + job.Settings.EditMode == "UI_LOCKED" { + log.Printf("[INFO] Skipping job '%s' because it's deployed by DABs", job.Settings.Name) + continue + } ic.Emit(&resource{ Resource: "databricks_job", ID: job.ID(),