Skip to content

Commit 41317f3

Browse files
authored
[Exporter] Add export of dashboard tasks in datarbicks_job (#4665)
## Changes <!-- Summary of your changes that are easy to understand --> ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [ ] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [ ] using Go SDK - [ ] using TF Plugin Framework
1 parent a0371a2 commit 41317f3

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
### Exporter
1919

2020
* Correctly handle account-level identities when generating the code ([#4650](https://github.com/databricks/terraform-provider-databricks/pull/4650))
21+
* Add export of dashboard tasks in `datarbicks_job` ([#4665](https://github.com/databricks/terraform-provider-databricks/pull/4665))
2122
* Add `Ignore` implementation for `databricks_grants` to fix issue with wrongly generated dependencies ([#4661](https://github.com/databricks/terraform-provider-databricks/pull/4650))
2223

2324
### Internal Changes

exporter/impl_jobs.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,35 @@ func importTask(ic *importContext, task sdk_jobs.Task, jobName, rID string) {
101101
ic.emitWorkspaceFileOrRepo(task.SqlTask.File.Path)
102102
}
103103
}
104+
if task.DashboardTask != nil {
105+
ic.Emit(&resource{
106+
Resource: "databricks_dashboard",
107+
ID: task.DashboardTask.DashboardId,
108+
})
109+
if task.DashboardTask.WarehouseId != "" {
110+
ic.Emit(&resource{
111+
Resource: "databricks_sql_endpoint",
112+
ID: task.DashboardTask.WarehouseId,
113+
})
114+
}
115+
if task.DashboardTask.Subscription != nil {
116+
for _, subscriber := range task.DashboardTask.Subscription.Subscribers {
117+
if subscriber.DestinationId != "" {
118+
ic.Emit(&resource{
119+
Resource: "databricks_notification_destination",
120+
ID: subscriber.DestinationId,
121+
})
122+
}
123+
if subscriber.UserName != "" {
124+
ic.Emit(&resource{
125+
Resource: "databricks_user",
126+
Attribute: "user_name",
127+
Value: subscriber.UserName,
128+
})
129+
}
130+
}
131+
}
132+
}
104133
if task.DbtTask != nil {
105134
if task.DbtTask.WarehouseId != "" {
106135
ic.Emit(&resource{

exporter/importables.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ var resourcesMap map[string]importable = map[string]importable{
354354
{Path: "job_cluster.new_cluster.policy_id", Resource: "databricks_cluster_policy"},
355355
{Path: "run_as.service_principal_name", Resource: "databricks_service_principal", Match: "application_id"},
356356
{Path: "task.dbt_task.warehouse_id", Resource: "databricks_sql_endpoint"},
357+
{Path: "task.dashboard_task.dashboard_id", Resource: "databricks_dashboard"},
358+
{Path: "task.dashboard_task.warehouse_id", Resource: "databricks_sql_endpoint"},
357359
{Path: "task.existing_cluster_id", Resource: "databricks_cluster"},
358360
{Path: "task.library.egg", Resource: "databricks_dbfs_file", Match: "dbfs_path"},
359361
{Path: "task.library.egg", Resource: "databricks_workspace_file", Match: "workspace_path"},
@@ -414,6 +416,8 @@ var resourcesMap map[string]importable = map[string]importable{
414416
{Path: "task.webhook_notifications.on_success.id", Resource: "databricks_notification_destination"},
415417
{Path: "task.webhook_notifications.on_streaming_backlog_exceeded.id", Resource: "databricks_notification_destination"},
416418
{Path: "task.for_each_task.task.dbt_task.warehouse_id", Resource: "databricks_sql_endpoint"},
419+
{Path: "task.for_each_task.task.dashboard_task.dashboard_id", Resource: "databricks_dashboard"},
420+
{Path: "task.for_each_task.task.dashboard_task.warehouse_id", Resource: "databricks_sql_endpoint"},
417421
{Path: "task.for_each_task.task.existing_cluster_id", Resource: "databricks_cluster"},
418422
{Path: "task.for_each_task.task.library.egg", Resource: "databricks_dbfs_file", Match: "dbfs_path"},
419423
{Path: "task.for_each_task.task.library.egg", Resource: "databricks_workspace_file", Match: "workspace_path"},
@@ -466,6 +470,10 @@ var resourcesMap map[string]importable = map[string]importable{
466470
{Path: "task.for_each_task.task.sql_task.dashboard.dashboard_id", Resource: "databricks_sql_dashboard"},
467471
{Path: "task.for_each_task.task.sql_task.query.query_id", Resource: "databricks_query"},
468472
{Path: "task.for_each_task.task.sql_task.warehouse_id", Resource: "databricks_sql_endpoint"},
473+
{Path: "task.for_each_task.task.dashboard_task.subscription.subscribers.destination_id",
474+
Resource: "databricks_notification_destination"},
475+
{Path: "task.dashboard_task.subscription.subscribers.destination_id",
476+
Resource: "databricks_notification_destination"},
469477
{Path: "task.for_each_task.task.webhook_notifications.on_duration_warning_threshold_exceeded.id",
470478
Resource: "databricks_notification_destination"},
471479
{Path: "task.for_each_task.task.webhook_notifications.on_failure.id", Resource: "databricks_notification_destination"},
@@ -498,6 +506,10 @@ var resourcesMap map[string]importable = map[string]importable{
498506
MatchType: MatchCaseInsensitive},
499507
{Path: "task.email_notifications.on_streaming_backlog_exceeded", Resource: "databricks_user",
500508
Match: "user_name", MatchType: MatchCaseInsensitive},
509+
{Path: "task.for_each_task.task.dashboard_task.subscription.subscribers.user_name",
510+
Resource: "databricks_user", Match: "user_name", MatchType: MatchCaseInsensitive},
511+
{Path: "task.dashboard_task.subscription.subscribers.user_name",
512+
Resource: "databricks_user", Match: "user_name", MatchType: MatchCaseInsensitive},
501513
{Path: "run_as.user_name", Resource: "databricks_user", Match: "user_name", MatchType: MatchCaseInsensitive},
502514
{Path: "task.for_each_task.task.email_notifications.on_duration_warning_threshold_exceeded", Resource: "databricks_user",
503515
Match: "user_name", MatchType: MatchCaseInsensitive},

0 commit comments

Comments
 (0)