Skip to content

Commit b238f29

Browse files
author
Gary James
committed
Feature - Allow for schedule config
1 parent e6481f8 commit b238f29

File tree

7 files changed

+168
-15
lines changed

7 files changed

+168
-15
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.72
1+
0.0.73

docs/resources/dbt_cloud_job.md

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ description: |-
3131
- **is_active** (Boolean) Flag for whether the job is marked active or deleted
3232
- **num_threads** (Number) Number of threads to use in the job
3333
- **run_generate_sources** (Boolean) Flag for whether the job should run generate sources
34+
- **schedule_cron** (String) Custom cron expression for schedule
35+
- **schedule_days** (List of Number) List of days of week as numbers (0 = Sunday, 7 = Saturday) to execute the job at if running on a schedule
36+
- **schedule_hours** (List of Number) List of hours to execute the job at if running on a schedule
37+
- **schedule_interval** (Number) Number of hours between job executions if running on a schedule
38+
- **schedule_type** (String) Type of schedule to use, one of every_day/ days_of_week/ custom_cron
3439
- **target_name** (String) Target name for the DBT profile
3540

3641

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/aws/aws-sdk-go v1.37.0 // indirect
88
github.com/hashicorp/hcl/v2 v2.8.2 // indirect
99
github.com/hashicorp/terraform-exec v0.15.0 // indirect
10+
github.com/hashicorp/terraform-plugin-docs v0.5.1 // indirect
1011
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.1
1112
github.com/mattn/go-colorable v0.1.11 // indirect
1213
github.com/zclconf/go-cty v1.10.0 // indirect

go.sum

+13
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
3636
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
3737
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3838
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
39+
github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg=
3940
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
41+
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
4042
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
43+
github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60=
4144
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
4245
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
4346
github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk=
@@ -64,6 +67,7 @@ github.com/apparentlymart/go-textseg/v12 v12.0.0 h1:bNEQyAGak9tojivJNkoqWErVCQbj
6467
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=
6568
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
6669
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
70+
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 h1:BUAU3CGlLvorLI26FmByPp2eC2qla6E1Tw+scpcg/to=
6771
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
6872
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
6973
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
@@ -73,6 +77,7 @@ github.com/aws/aws-sdk-go v1.37.0 h1:GzFnhOIsrGyQ69s7VgqtrG2BG8v7X7vwB3Xpbd/DBBk
7377
github.com/aws/aws-sdk-go v1.37.0/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
7478
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
7579
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
80+
github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=
7681
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
7782
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
7883
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
@@ -162,6 +167,7 @@ github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hf
162167
github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
163168
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
164169
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
170+
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
165171
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
166172
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
167173
github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM=
@@ -207,13 +213,16 @@ github.com/hashicorp/terraform-exec v0.15.0/go.mod h1:H4IG8ZxanU+NW0ZpDRNsvh9f0u
207213
github.com/hashicorp/terraform-json v0.12.0/go.mod h1:pmbq9o4EuL43db5+0ogX10Yofv1nozM+wskr/bGFJpI=
208214
github.com/hashicorp/terraform-json v0.13.0 h1:Li9L+lKD1FO5RVFRM1mMMIBDoUHslOniyEi5CM+FWGY=
209215
github.com/hashicorp/terraform-json v0.13.0/go.mod h1:y5OdLBCT+rxbwnpxZs9kGL7R9ExU76+cpdY8zHwoazk=
216+
github.com/hashicorp/terraform-plugin-docs v0.5.1 h1:WwrUcamix9x0TqfTw/WGHMRqoTe1QPZKaeWJPuFb4lQ=
217+
github.com/hashicorp/terraform-plugin-docs v0.5.1/go.mod h1:SQwEgy0/B0UPQ07rNEG1Wpt6E3jvRcCwkVHPNybGgc0=
210218
github.com/hashicorp/terraform-plugin-go v0.3.0 h1:AJqYzP52JFYl9NABRI7smXI1pNjgR5Q/y2WyVJ/BOZA=
211219
github.com/hashicorp/terraform-plugin-go v0.3.0/go.mod h1:dFHsQMaTLpON2gWhVWT96fvtlc/MF1vSy3OdMhWBzdM=
212220
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.1 h1:vpzKKP2dIFb9n89AG8Wxl758/5JSZWZH0OuKdlq0M38=
213221
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.1/go.mod h1:o3pdss6ynDZW9FfiZ+rETUH5LEVufrXdhwLU+5OiRo0=
214222
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
215223
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ=
216224
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
225+
github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw=
217226
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
218227
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
219228
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
@@ -262,6 +271,7 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME
262271
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
263272
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
264273
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
274+
github.com/mitchellh/cli v1.1.2 h1:PvH+lL2B7IQ101xQL63Of8yFS2y+aDlsFcsqNc+u/Kw=
265275
github.com/mitchellh/cli v1.1.2/go.mod h1:6iaV0fGdElS6dPBx0EApTxHrcWvmJphyh2n8YBLPPZ4=
266276
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
267277
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
@@ -291,9 +301,12 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
291301
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
292302
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
293303
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
304+
github.com/posener/complete v1.1.1 h1:ccV59UEOTzVDnDUEFdT95ZzHVZ+5+158q8+SJb2QV5w=
294305
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
295306
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
296307
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
308+
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
309+
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
297310
github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4=
298311
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
299312
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=

pkg/dbt_cloud/job.go

+30-10
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ type JobSettings struct {
2121
}
2222

2323
type scheduleDate struct {
24-
Type string `json:"type"`
24+
Type string `json:"type"`
25+
Days *[]int `json:"days,omitempty"`
26+
Cron *string `json:"cron,omitempty"`
2527
}
2628

2729
type scheduleTime struct {
2830
Type string `json:"type"`
29-
Interval int `json:"interval"`
31+
Interval int `json:"interval,omitempty"`
32+
Hours *[]int `json:"hours,omitempty"`
3033
}
3134

3235
type JobSchedule struct {
@@ -76,7 +79,7 @@ func (c *Client) GetJob(jobID string) (*Job, error) {
7679
return &jobResponse.Data, nil
7780
}
7881

79-
func (c *Client) CreateJob(projectId int, environmentId int, name string, executeSteps []string, dbtVersion string, isActive bool, triggers map[string]interface{}, numThreads int, targetName string, generateDocs bool, runGenerateSources bool) (*Job, error) {
82+
func (c *Client) CreateJob(projectId int, environmentId int, name string, executeSteps []string, dbtVersion string, isActive bool, triggers map[string]interface{}, numThreads int, targetName string, generateDocs bool, runGenerateSources bool, scheduleType string, scheduleInterval int, scheduleHours []int, scheduleDays []int, scheduleCron string) (*Job, error) {
8083
state := 1
8184
if !isActive {
8285
state = 2
@@ -107,14 +110,31 @@ func (c *Client) CreateJob(projectId int, environmentId int, name string, execut
107110
Threads: numThreads,
108111
Target_Name: targetName,
109112
}
113+
114+
time := scheduleTime{
115+
Type: "every_hour",
116+
Interval: 1,
117+
}
118+
if scheduleInterval > 0 {
119+
time.Interval = scheduleInterval
120+
}
121+
if len(scheduleHours) > 0 {
122+
time.Type = "at_exact_hours"
123+
time.Hours = &scheduleHours
124+
time.Interval = 0
125+
}
126+
127+
date := scheduleDate{
128+
Type: scheduleType,
129+
}
130+
if scheduleType == "days_of_week" {
131+
date.Days = &scheduleDays
132+
} else if scheduleCron != "" {
133+
date.Cron = &scheduleCron
134+
}
110135
jobSchedule := JobSchedule{
111-
Date: scheduleDate{
112-
Type: "every_day",
113-
},
114-
Time: scheduleTime{
115-
Type: "every_hour",
116-
Interval: 1,
117-
},
136+
Date: date,
137+
Time: time,
118138
}
119139

120140
newJob := Job{

pkg/resources/job.go

+114-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ import (
88
"github.com/gthesheep/terraform-provider-dbt-cloud/pkg/dbt_cloud"
99
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
12+
)
13+
14+
var (
15+
scheduleTypes = []string{
16+
"every_day",
17+
"days_of_week",
18+
"custom_cron",
19+
}
1120
)
1221

1322
var jobSchema = map[string]*schema.Schema{
@@ -80,6 +89,45 @@ var jobSchema = map[string]*schema.Schema{
8089
Default: false,
8190
Description: "Flag for whether the job should run generate sources",
8291
},
92+
"schedule_type": &schema.Schema{
93+
Type: schema.TypeString,
94+
Optional: true,
95+
Default: "every_day",
96+
Description: "Type of schedule to use, one of every_day/ days_of_week/ custom_cron",
97+
ValidateFunc: validation.StringInSlice(scheduleTypes, false),
98+
},
99+
"schedule_interval": &schema.Schema{
100+
Type: schema.TypeInt,
101+
Optional: true,
102+
Default: 1,
103+
Description: "Number of hours between job executions if running on a schedule",
104+
ValidateFunc: validation.IntBetween(1, 23),
105+
ConflictsWith: []string{"schedule_hours"},
106+
},
107+
"schedule_hours": &schema.Schema{
108+
Type: schema.TypeList,
109+
MinItems: 1,
110+
Optional: true,
111+
Elem: &schema.Schema{
112+
Type: schema.TypeInt,
113+
},
114+
Description: "List of hours to execute the job at if running on a schedule",
115+
ConflictsWith: []string{"schedule_interval"},
116+
},
117+
"schedule_days": &schema.Schema{
118+
Type: schema.TypeList,
119+
MinItems: 1,
120+
Optional: true,
121+
Elem: &schema.Schema{
122+
Type: schema.TypeInt,
123+
},
124+
Description: "List of days of week as numbers (0 = Sunday, 7 = Saturday) to execute the job at if running on a schedule",
125+
},
126+
"schedule_cron": &schema.Schema{
127+
Type: schema.TypeString,
128+
Optional: true,
129+
Description: "Custom cron expression for schedule",
130+
},
83131
}
84132

85133
func ResourceJob() *schema.Resource {
@@ -139,6 +187,27 @@ func resourceJobRead(ctx context.Context, d *schema.ResourceData, m interface{})
139187
if err := d.Set("run_generate_sources", job.Run_Generate_Sources); err != nil {
140188
return diag.FromErr(err)
141189
}
190+
if err := d.Set("schedule_type", job.Schedule.Date.Type); err != nil {
191+
return diag.FromErr(err)
192+
}
193+
194+
schedule := 1
195+
if job.Schedule.Time.Interval > 0 {
196+
schedule = job.Schedule.Time.Interval
197+
}
198+
if err := d.Set("schedule_interval", schedule); err != nil {
199+
return diag.FromErr(err)
200+
}
201+
202+
if err := d.Set("schedule_hours", job.Schedule.Time.Hours); err != nil {
203+
return diag.FromErr(err)
204+
}
205+
if err := d.Set("schedule_days", job.Schedule.Date.Days); err != nil {
206+
return diag.FromErr(err)
207+
}
208+
if err := d.Set("schedule_cron", job.Schedule.Date.Cron); err != nil {
209+
return diag.FromErr(err)
210+
}
142211

143212
var triggers map[string]interface{}
144213
triggersInput, _ := json.Marshal(job.Triggers)
@@ -167,13 +236,26 @@ func resourceJobCreate(ctx context.Context, d *schema.ResourceData, m interface{
167236
targetName := d.Get("target_name").(string)
168237
generateDocs := d.Get("generate_docs").(bool)
169238
runGenerateSources := d.Get("run_generate_sources").(bool)
239+
scheduleType := d.Get("schedule_type").(string)
240+
scheduleInterval := d.Get("schedule_interval").(int)
241+
scheduleHours := d.Get("schedule_hours").([]interface{})
242+
scheduleDays := d.Get("schedule_days").([]interface{})
243+
scheduleCron := d.Get("schedule_cron").(string)
170244

171245
steps := []string{}
172246
for _, step := range executeSteps {
173247
steps = append(steps, step.(string))
174248
}
249+
hours := []int{}
250+
for _, hour := range scheduleHours {
251+
hours = append(hours, hour.(int))
252+
}
253+
days := []int{}
254+
for _, day := range scheduleDays {
255+
days = append(days, day.(int))
256+
}
175257

176-
j, err := c.CreateJob(projectId, environmentId, name, steps, dbtVersion, isActive, triggers, numThreads, targetName, generateDocs, runGenerateSources)
258+
j, err := c.CreateJob(projectId, environmentId, name, steps, dbtVersion, isActive, triggers, numThreads, targetName, generateDocs, runGenerateSources, scheduleType, scheduleInterval, hours, days, scheduleCron)
177259
if err != nil {
178260
return diag.FromErr(err)
179261
}
@@ -191,7 +273,9 @@ func resourceJobUpdate(ctx context.Context, d *schema.ResourceData, m interface{
191273

192274
if d.HasChange("name") || d.HasChange("dbt_version") || d.HasChange("num_threads") ||
193275
d.HasChange("target_name") || d.HasChange("execute_steps") || d.HasChange("run_generate_sources") ||
194-
d.HasChange("generate_docs") || d.HasChange("triggers") {
276+
d.HasChange("generate_docs") || d.HasChange("triggers") || d.HasChange("schedule_type") ||
277+
d.HasChange("schedule_interval") || d.HasChange("schedule_hours") || d.HasChange("schedule_days") ||
278+
d.HasChange("schedule_cron") {
195279
job, err := c.GetJob(jobId)
196280
if err != nil {
197281
return diag.FromErr(err)
@@ -235,6 +319,34 @@ func resourceJobUpdate(ctx context.Context, d *schema.ResourceData, m interface{
235319
job.Triggers.Schedule = newTriggers["schedule"].(bool)
236320
job.Triggers.Custom_Branch_Only = newTriggers["custom_branch_only"].(bool)
237321
}
322+
if d.HasChange("schedule_type") {
323+
scheduleType := d.Get("schedule_type").(string)
324+
job.Schedule.Date.Type = scheduleType
325+
}
326+
if d.HasChange("schedule_interval") {
327+
scheduleInterval := d.Get("schedule_interval").(int)
328+
job.Schedule.Time.Interval = scheduleInterval
329+
}
330+
if d.HasChange("schedule_hours") {
331+
scheduleHours := make([]int, len(d.Get("schedule_hours").([]interface{})))
332+
for i, hour := range d.Get("schedule_hours").([]interface{}) {
333+
scheduleHours[i] = hour.(int)
334+
}
335+
job.Schedule.Time.Hours = &scheduleHours
336+
job.Schedule.Time.Type = "at_exact_hours"
337+
job.Schedule.Time.Interval = 0
338+
}
339+
if d.HasChange("schedule_days") {
340+
scheduleDays := make([]int, len(d.Get("schedule_days").([]interface{})))
341+
for i, day := range d.Get("schedule_days").([]interface{}) {
342+
scheduleDays[i] = day.(int)
343+
}
344+
job.Schedule.Date.Days = &scheduleDays
345+
}
346+
if d.HasChange("schedule_cron") {
347+
scheduleCron := d.Get("schedule_cron").(string)
348+
job.Schedule.Date.Cron = &scheduleCron
349+
}
238350

239351
_, err = c.UpdateJob(jobId, *job)
240352
if err != nil {

pkg/resources/job_acceptance_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,18 @@ resource "dbt_cloud_job" "test_job" {
118118
"dbt test"
119119
]
120120
triggers = {
121-
"github_webhook": true,
121+
"github_webhook": false,
122122
"git_provider_webhook": false,
123-
"schedule": false,
123+
"schedule": true,
124124
"custom_branch_only": false,
125125
}
126126
is_active = true
127127
num_threads = 37
128128
target_name = "test"
129129
run_generate_sources = true
130130
generate_docs = true
131+
schedule_type = "every_day"
132+
schedule_hours = [9, 17]
131133
}
132134
`, projectName, environmentName, jobName)
133135
}

0 commit comments

Comments
 (0)