Skip to content

Commit cba690c

Browse files
nordpmgyucht
andauthored
Added experimental compute field to databricks_job resource (#2401)
* add experimental compute api * make fmt * use sdk instead --------- Co-authored-by: Miles Yucht <[email protected]>
1 parent 9fe7490 commit cba690c

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

jobs/resource_job.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1616

1717
"github.com/databricks/databricks-sdk-go/apierr"
18+
"github.com/databricks/databricks-sdk-go/service/compute"
1819
"github.com/databricks/terraform-provider-databricks/clusters"
1920
"github.com/databricks/terraform-provider-databricks/common"
2021
"github.com/databricks/terraform-provider-databricks/libraries"
@@ -172,6 +173,7 @@ type JobTaskSettings struct {
172173
ExistingClusterID string `json:"existing_cluster_id,omitempty" tf:"group:cluster_type"`
173174
NewCluster *clusters.Cluster `json:"new_cluster,omitempty" tf:"group:cluster_type"`
174175
JobClusterKey string `json:"job_cluster_key,omitempty" tf:"group:cluster_type"`
176+
ComputeKey string `json:"compute_key,omitempty" tf:"group:cluster_type"`
175177
Libraries []libraries.Library `json:"libraries,omitempty" tf:"slice_set,alias:library"`
176178
NotebookTask *NotebookTask `json:"notebook_task,omitempty" tf:"group:task_type"`
177179
SparkJarTask *SparkJarTask `json:"spark_jar_task,omitempty" tf:"group:task_type"`
@@ -193,6 +195,11 @@ type JobCluster struct {
193195
NewCluster *clusters.Cluster `json:"new_cluster,omitempty" tf:"group:cluster_type"`
194196
}
195197

198+
type JobCompute struct {
199+
ComputeKey string `json:"compute_key,omitempty" tf:"group:cluster_type"`
200+
ComputeSpec *compute.ComputeSpec `json:"spec,omitempty" tf:"group:cluster_type"`
201+
}
202+
196203
type ContinuousConf struct {
197204
PauseStatus string `json:"pause_status,omitempty" tf:"computed"`
198205
}
@@ -241,6 +248,7 @@ type JobSettings struct {
241248
Tasks []JobTaskSettings `json:"tasks,omitempty" tf:"alias:task"`
242249
Format string `json:"format,omitempty" tf:"computed"`
243250
JobClusters []JobCluster `json:"job_clusters,omitempty" tf:"alias:job_cluster"`
251+
Compute []JobCompute `json:"compute,omitempty" tf:"alias:compute"`
244252
// END Jobs API 2.1
245253

246254
// BEGIN Jobs + Repo integration preview

jobs/resource_job_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/databricks/databricks-sdk-go/apierr"
11+
"github.com/databricks/databricks-sdk-go/service/compute"
1112
"github.com/databricks/terraform-provider-databricks/clusters"
1213
"github.com/databricks/terraform-provider-databricks/common"
1314
"github.com/databricks/terraform-provider-databricks/libraries"
@@ -332,6 +333,78 @@ func TestResourceJobCreate_JobClusters(t *testing.T) {
332333
assert.Equal(t, "17", d.Id())
333334
}
334335

336+
func TestResourceJobCreate_JobCompute(t *testing.T) {
337+
d, err := qa.ResourceFixture{
338+
Fixtures: []qa.HTTPFixture{
339+
{
340+
Method: "POST",
341+
Resource: "/api/2.1/jobs/create",
342+
ExpectedRequest: JobSettings{
343+
Name: "JobComputed",
344+
Tasks: []JobTaskSettings{
345+
{
346+
TaskKey: "b",
347+
ComputeKey: "j",
348+
NotebookTask: &NotebookTask{
349+
NotebookPath: "/Stuff",
350+
},
351+
},
352+
},
353+
MaxConcurrentRuns: 1,
354+
Compute: []JobCompute{
355+
{
356+
ComputeKey: "j",
357+
ComputeSpec: &compute.ComputeSpec{
358+
Kind: "t",
359+
},
360+
},
361+
},
362+
},
363+
Response: Job{
364+
JobID: 18,
365+
},
366+
},
367+
{
368+
Method: "GET",
369+
Resource: "/api/2.1/jobs/get?job_id=18",
370+
Response: Job{
371+
// good enough for mock
372+
Settings: &JobSettings{
373+
Tasks: []JobTaskSettings{
374+
{
375+
TaskKey: "b",
376+
},
377+
},
378+
},
379+
},
380+
},
381+
},
382+
Create: true,
383+
Resource: ResourceJob(),
384+
HCL: `
385+
name = "JobComputed"
386+
387+
compute {
388+
compute_key = "j"
389+
spec {
390+
kind = "t"
391+
}
392+
}
393+
394+
task {
395+
task_key = "b"
396+
397+
compute_key = "j"
398+
399+
notebook_task {
400+
notebook_path = "/Stuff"
401+
}
402+
}`,
403+
}.Apply(t)
404+
assert.NoError(t, err)
405+
assert.Equal(t, "18", d.Id())
406+
}
407+
335408
func TestResourceJobCreate_AlwaysRunning(t *testing.T) {
336409
d, err := qa.ResourceFixture{
337410
Fixtures: []qa.HTTPFixture{

0 commit comments

Comments
 (0)