Skip to content

Commit 7c8f2c7

Browse files
authored
Add terraform support for Job Parameters (Private Preview) (#2509)
* start * Add JobParameters to Terraform * fmt fix * revert scim changes * Rename variables * nit * add documentation * naming nits * add alias and change documentation * add test coverage * add run-now tests * add passing tests * lint fix
1 parent f39d66b commit 7c8f2c7

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed

docs/resources/job.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,13 @@ This block controls notification settings for both email & webhook notifications
239239
* `no_alert_for_skipped_runs` - (Optional) (Bool) don't send alert for skipped runs.
240240
* `no_alert_for_canceled_runs` - (Optional) (Bool) don't send alert for cancelled runs.
241241

242+
### parameter Configuration Block
243+
244+
This block defines a job-level parameter for the job. You can define several job-level parameters for the job. Supported options are:
245+
246+
* `name` - (Required) The name of the defined parameter. May only contain alphanumeric characters, `_`, `-`, and `.`.
247+
* `default` - (Required) Default value of the parameter.
248+
242249
### notification_settings Configuration Block (Task Level)
243250

244251
This block controls notification settings for both email & webhook notifications on a task level:

jobs/resource_job.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ type JobSettings struct {
294294
Queue *Queue `json:"queue,omitempty"`
295295
RunAs *JobRunAs `json:"run_as,omitempty"`
296296
Health *JobHealth `json:"health,omitempty"`
297+
Parameters []JobParameterDefinition `json:"parameters,omitempty" tf:"alias:parameter"`
297298
}
298299

299300
func (js *JobSettings) isMultiTask() bool {
@@ -341,6 +342,19 @@ type RunParameters struct {
341342
SparkSubmitParams []string `json:"spark_submit_params,omitempty"`
342343
}
343344

345+
// Job-level parameter
346+
type JobParameter struct {
347+
Name string `json:"name,omitempty"`
348+
Default string `json:"default,omitempty"`
349+
Value string `json:"value,omitempty"`
350+
}
351+
352+
// Job-level parameter definitions
353+
type JobParameterDefinition struct {
354+
Name string `json:"name,omitempty"`
355+
Default string `json:"default,omitempty"`
356+
}
357+
344358
// RunState of the job
345359
type RunState struct {
346360
ResultState string `json:"result_state,omitempty"`
@@ -358,7 +372,8 @@ type JobRun struct {
358372
Trigger string `json:"trigger,omitempty"`
359373
RuntType string `json:"run_type,omitempty"`
360374

361-
OverridingParameters RunParameters `json:"overriding_parameters,omitempty"`
375+
OverridingParameters RunParameters `json:"overriding_parameters,omitempty"`
376+
JobParameters []JobParameter `json:"job_parameters,omitempty"`
362377
}
363378

364379
// JobRunsListRequest used to do what it sounds like

jobs/resource_job_test.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,91 @@ func TestResourceJobCreate_MultiTask(t *testing.T) {
269269
assert.Equal(t, "789", d.Id())
270270
}
271271

272+
func TestResourceJobCreate_JobParameters(t *testing.T) {
273+
d, err := qa.ResourceFixture{
274+
Fixtures: []qa.HTTPFixture{
275+
{
276+
Method: "POST",
277+
Resource: "/api/2.1/jobs/create",
278+
ExpectedRequest: JobSettings{
279+
Name: "JobParameterTesting",
280+
Tasks: []JobTaskSettings{
281+
{
282+
TaskKey: "a",
283+
},
284+
{
285+
TaskKey: "b",
286+
},
287+
},
288+
MaxConcurrentRuns: 1,
289+
Parameters: []JobParameterDefinition{
290+
{
291+
Name: "hello",
292+
Default: "world",
293+
},
294+
{
295+
Name: "key",
296+
Default: "value_default",
297+
},
298+
},
299+
},
300+
Response: Job{
301+
JobID: 231,
302+
},
303+
},
304+
{
305+
Method: "GET",
306+
Resource: "/api/2.1/jobs/get?job_id=231",
307+
Response: Job{
308+
// good enough for mock
309+
Settings: &JobSettings{
310+
Tasks: []JobTaskSettings{
311+
{
312+
TaskKey: "a",
313+
},
314+
{
315+
TaskKey: "b",
316+
},
317+
},
318+
Parameters: []JobParameterDefinition{
319+
{
320+
Name: "hello",
321+
Default: "world",
322+
},
323+
{
324+
Name: "key",
325+
Default: "value_default",
326+
},
327+
},
328+
},
329+
},
330+
},
331+
},
332+
Create: true,
333+
Resource: ResourceJob(),
334+
HCL: `
335+
name = "JobParameterTesting"
336+
337+
parameter {
338+
name = "hello"
339+
default = "world"
340+
}
341+
parameter {
342+
name = "key"
343+
default = "value_default"
344+
}
345+
346+
task {
347+
task_key = "a"
348+
}
349+
350+
task {
351+
task_key = "b"
352+
}`,
353+
}.Apply(t)
354+
assert.NoError(t, err)
355+
assert.Equal(t, "231", d.Id())
356+
}
272357
func TestResourceJobCreate_JobClusters(t *testing.T) {
273358
d, err := qa.ResourceFixture{
274359
Fixtures: []qa.HTTPFixture{

0 commit comments

Comments
 (0)