Skip to content

Commit e7c8ff0

Browse files
authored
add environment and environment_key to job settings (#3461)
1 parent 4b51e02 commit e7c8ff0

File tree

2 files changed

+81
-3
lines changed

2 files changed

+81
-3
lines changed

jobs/resource_job.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ type ForEachNestedTask struct {
158158
MinRetryIntervalMillis int32 `json:"min_retry_interval_millis,omitempty"`
159159
RetryOnTimeout bool `json:"retry_on_timeout,omitempty" tf:"computed"`
160160
Health *JobHealth `json:"health,omitempty"`
161+
162+
EnvironmentKey string `json:"environment_key,omitempty"`
161163
}
162164

163165
func sortWebhookNotifications(wn *jobs.WebhookNotifications) {
@@ -238,6 +240,8 @@ type JobTaskSettings struct {
238240
MinRetryIntervalMillis int32 `json:"min_retry_interval_millis,omitempty"`
239241
RetryOnTimeout bool `json:"retry_on_timeout,omitempty" tf:"computed"`
240242
Health *JobHealth `json:"health,omitempty"`
243+
244+
EnvironmentKey string `json:"environment_key,omitempty"`
241245
}
242246

243247
type JobCluster struct {
@@ -297,9 +301,10 @@ type JobSettings struct {
297301
// END Jobs API 2.0
298302

299303
// BEGIN Jobs API 2.1
300-
Tasks []JobTaskSettings `json:"tasks,omitempty" tf:"alias:task"`
301-
Format string `json:"format,omitempty" tf:"computed"`
302-
JobClusters []JobCluster `json:"job_clusters,omitempty" tf:"alias:job_cluster"`
304+
Tasks []JobTaskSettings `json:"tasks,omitempty" tf:"alias:task"`
305+
Format string `json:"format,omitempty" tf:"computed"`
306+
JobClusters []JobCluster `json:"job_clusters,omitempty" tf:"alias:job_cluster"`
307+
Environments []jobs.JobEnvironment `json:"environments,omitempty" tf:"alias:environment"`
303308
// END Jobs API 2.1
304309

305310
// BEGIN Jobs + Repo integration preview

jobs/resource_job_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,79 @@ func TestResourceJobCreate_JobClusters(t *testing.T) {
898898
assert.Equal(t, "17", d.Id())
899899
}
900900

901+
func TestResourceJobCreate_JobCompute(t *testing.T) {
902+
d, err := qa.ResourceFixture{
903+
Fixtures: []qa.HTTPFixture{
904+
{
905+
Method: "POST",
906+
Resource: "/api/2.1/jobs/create",
907+
ExpectedRequest: JobSettings{
908+
Name: "JobEnvironments",
909+
Tasks: []JobTaskSettings{
910+
{
911+
TaskKey: "b",
912+
EnvironmentKey: "j",
913+
NotebookTask: &NotebookTask{
914+
NotebookPath: "/Stuff",
915+
},
916+
},
917+
},
918+
MaxConcurrentRuns: 1,
919+
Environments: []jobs.JobEnvironment{
920+
{
921+
EnvironmentKey: "j",
922+
Spec: &compute.Environment{
923+
Client: "1",
924+
Dependencies: []string{
925+
"cowsay",
926+
"-r /Workspace/Users/[email protected]/my.whl",
927+
},
928+
},
929+
},
930+
},
931+
},
932+
Response: Job{
933+
JobID: 18,
934+
},
935+
},
936+
{
937+
Method: "GET",
938+
Resource: "/api/2.1/jobs/get?job_id=18",
939+
Response: Job{
940+
// good enough for mock
941+
Settings: &JobSettings{
942+
Tasks: []JobTaskSettings{
943+
{
944+
TaskKey: "b",
945+
},
946+
},
947+
},
948+
},
949+
},
950+
},
951+
Create: true,
952+
Resource: ResourceJob(),
953+
HCL: `
954+
name = "JobEnvironments"
955+
environment {
956+
environment_key = "j"
957+
spec {
958+
client = "1"
959+
dependencies = ["cowsay", "-r /Workspace/Users/[email protected]/my.whl"]
960+
}
961+
}
962+
task {
963+
task_key = "b"
964+
environment_key = "j"
965+
notebook_task {
966+
notebook_path = "/Stuff"
967+
}
968+
}`,
969+
}.Apply(t)
970+
assert.NoError(t, err)
971+
assert.Equal(t, "18", d.Id())
972+
}
973+
901974
func TestResourceJobCreate_SqlSubscriptions(t *testing.T) {
902975
d, err := qa.ResourceFixture{
903976
Fixtures: []qa.HTTPFixture{

0 commit comments

Comments
 (0)