Skip to content

Commit 4f4c65f

Browse files
Make storage transfer job schedule updatable (#6947) (#13262)
* Make storage transfer job schedule updatable * Check error before checking status Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 1f5b72c commit 4f4c65f

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

.changelog/6947.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
storagetransfer: made storage_transfer_job schedule field mutable
3+
```

google/resource_storage_transfer_job.go

+8-14
Original file line numberDiff line numberDiff line change
@@ -181,23 +181,20 @@ func resourceStorageTransferJob() *schema.Resource {
181181
"schedule_start_date": {
182182
Type: schema.TypeList,
183183
Required: true,
184-
ForceNew: true,
185184
MaxItems: 1,
186185
Elem: dateObjectSchema(),
187186
Description: `The first day the recurring transfer is scheduled to run. If schedule_start_date is in the past, the transfer will run for the first time on the following day.`,
188187
},
189188
"schedule_end_date": {
190189
Type: schema.TypeList,
191190
Optional: true,
192-
ForceNew: true,
193191
MaxItems: 1,
194192
Elem: dateObjectSchema(),
195193
Description: `The last day the recurring transfer will be run. If schedule_end_date is the same as schedule_start_date, the transfer will be executed only once.`,
196194
},
197195
"start_time_of_day": {
198196
Type: schema.TypeList,
199197
Optional: true,
200-
ForceNew: true,
201198
MaxItems: 1,
202199
Elem: timeObjectSchema(),
203200
DiffSuppressFunc: diffSuppressEmptyStartTimeOfDay,
@@ -334,28 +331,24 @@ func timeObjectSchema() *schema.Resource {
334331
"hours": {
335332
Type: schema.TypeInt,
336333
Required: true,
337-
ForceNew: true,
338334
ValidateFunc: validation.IntBetween(0, 24),
339335
Description: `Hours of day in 24 hour format. Should be from 0 to 23.`,
340336
},
341337
"minutes": {
342338
Type: schema.TypeInt,
343339
Required: true,
344-
ForceNew: true,
345340
ValidateFunc: validation.IntBetween(0, 59),
346341
Description: `Minutes of hour of day. Must be from 0 to 59.`,
347342
},
348343
"seconds": {
349344
Type: schema.TypeInt,
350345
Required: true,
351-
ForceNew: true,
352346
ValidateFunc: validation.IntBetween(0, 60),
353347
Description: `Seconds of minutes of the time. Must normally be from 0 to 59.`,
354348
},
355349
"nanos": {
356350
Type: schema.TypeInt,
357351
Required: true,
358-
ForceNew: true,
359352
ValidateFunc: validation.IntBetween(0, 999999999),
360353
Description: `Fractions of seconds in nanoseconds. Must be from 0 to 999,999,999.`,
361354
},
@@ -369,23 +362,20 @@ func dateObjectSchema() *schema.Resource {
369362
"year": {
370363
Type: schema.TypeInt,
371364
Required: true,
372-
ForceNew: true,
373365
ValidateFunc: validation.IntBetween(0, 9999),
374366
Description: `Year of date. Must be from 1 to 9999.`,
375367
},
376368

377369
"month": {
378370
Type: schema.TypeInt,
379371
Required: true,
380-
ForceNew: true,
381372
ValidateFunc: validation.IntBetween(1, 12),
382373
Description: `Month of year. Must be from 1 to 12.`,
383374
},
384375

385376
"day": {
386377
Type: schema.TypeInt,
387378
Required: true,
388-
ForceNew: true,
389379
ValidateFunc: validation.IntBetween(0, 31),
390380
Description: `Day of month. Must be from 1 to 31 and valid for the year and month.`,
391381
},
@@ -638,29 +628,29 @@ func resourceStorageTransferJobUpdate(d *schema.ResourceData, meta interface{})
638628
fieldMask := []string{}
639629

640630
if d.HasChange("description") {
631+
fieldMask = append(fieldMask, "description")
641632
if v, ok := d.GetOk("description"); ok {
642-
fieldMask = append(fieldMask, "description")
643633
transferJob.Description = v.(string)
644634
}
645635
}
646636

647637
if d.HasChange("status") {
638+
fieldMask = append(fieldMask, "status")
648639
if v, ok := d.GetOk("status"); ok {
649-
fieldMask = append(fieldMask, "status")
650640
transferJob.Status = v.(string)
651641
}
652642
}
653643

654644
if d.HasChange("schedule") {
645+
fieldMask = append(fieldMask, "schedule")
655646
if v, ok := d.GetOk("schedule"); ok {
656-
fieldMask = append(fieldMask, "schedule")
657647
transferJob.Schedule = expandTransferSchedules(v.([]interface{}))
658648
}
659649
}
660650

661651
if d.HasChange("transfer_spec") {
652+
fieldMask = append(fieldMask, "transfer_spec")
662653
if v, ok := d.GetOk("transfer_spec"); ok {
663-
fieldMask = append(fieldMask, "transfer_spec")
664654
transferJob.TransferSpec = expandTransferSpecs(v.([]interface{}))
665655
}
666656
}
@@ -674,6 +664,10 @@ func resourceStorageTransferJobUpdate(d *schema.ResourceData, meta interface{})
674664
}
675665
}
676666

667+
if len(fieldMask) == 0 {
668+
return nil
669+
}
670+
677671
updateRequest := &storagetransfer.UpdateTransferJobRequest{
678672
ProjectId: project,
679673
TransferJob: transferJob,

google/resource_storage_transfer_job_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,12 @@ func testAccStorageTransferJobDestroyProducer(t *testing.T) func(s *terraform.St
276276
}
277277

278278
res, err := config.NewStorageTransferClient(config.userAgent).TransferJobs.Get(name, project).Do()
279-
if res.Status != "DELETED" {
280-
return fmt.Errorf("Transfer Job not set to DELETED")
281-
}
282279
if err != nil {
283280
return fmt.Errorf("Transfer Job does not exist, should exist and be DELETED")
284281
}
282+
if res.Status != "DELETED" {
283+
return fmt.Errorf("Transfer Job not set to DELETED")
284+
}
285285
}
286286

287287
return nil

0 commit comments

Comments
 (0)