Skip to content

Commit

Permalink
Make storage transfer job schedule updatable (#6947) (#13262)
Browse files Browse the repository at this point in the history
* Make storage transfer job schedule updatable

* Check error before checking status

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Dec 16, 2022
1 parent 1f5b72c commit 4f4c65f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .changelog/6947.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
storagetransfer: made storage_transfer_job schedule field mutable
```
22 changes: 8 additions & 14 deletions google/resource_storage_transfer_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,20 @@ func resourceStorageTransferJob() *schema.Resource {
"schedule_start_date": {
Type: schema.TypeList,
Required: true,
ForceNew: true,
MaxItems: 1,
Elem: dateObjectSchema(),
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.`,
},
"schedule_end_date": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: dateObjectSchema(),
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.`,
},
"start_time_of_day": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: timeObjectSchema(),
DiffSuppressFunc: diffSuppressEmptyStartTimeOfDay,
Expand Down Expand Up @@ -334,28 +331,24 @@ func timeObjectSchema() *schema.Resource {
"hours": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntBetween(0, 24),
Description: `Hours of day in 24 hour format. Should be from 0 to 23.`,
},
"minutes": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntBetween(0, 59),
Description: `Minutes of hour of day. Must be from 0 to 59.`,
},
"seconds": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntBetween(0, 60),
Description: `Seconds of minutes of the time. Must normally be from 0 to 59.`,
},
"nanos": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntBetween(0, 999999999),
Description: `Fractions of seconds in nanoseconds. Must be from 0 to 999,999,999.`,
},
Expand All @@ -369,23 +362,20 @@ func dateObjectSchema() *schema.Resource {
"year": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntBetween(0, 9999),
Description: `Year of date. Must be from 1 to 9999.`,
},

"month": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntBetween(1, 12),
Description: `Month of year. Must be from 1 to 12.`,
},

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

if d.HasChange("description") {
fieldMask = append(fieldMask, "description")
if v, ok := d.GetOk("description"); ok {
fieldMask = append(fieldMask, "description")
transferJob.Description = v.(string)
}
}

if d.HasChange("status") {
fieldMask = append(fieldMask, "status")
if v, ok := d.GetOk("status"); ok {
fieldMask = append(fieldMask, "status")
transferJob.Status = v.(string)
}
}

if d.HasChange("schedule") {
fieldMask = append(fieldMask, "schedule")
if v, ok := d.GetOk("schedule"); ok {
fieldMask = append(fieldMask, "schedule")
transferJob.Schedule = expandTransferSchedules(v.([]interface{}))
}
}

if d.HasChange("transfer_spec") {
fieldMask = append(fieldMask, "transfer_spec")
if v, ok := d.GetOk("transfer_spec"); ok {
fieldMask = append(fieldMask, "transfer_spec")
transferJob.TransferSpec = expandTransferSpecs(v.([]interface{}))
}
}
Expand All @@ -674,6 +664,10 @@ func resourceStorageTransferJobUpdate(d *schema.ResourceData, meta interface{})
}
}

if len(fieldMask) == 0 {
return nil
}

updateRequest := &storagetransfer.UpdateTransferJobRequest{
ProjectId: project,
TransferJob: transferJob,
Expand Down
6 changes: 3 additions & 3 deletions google/resource_storage_transfer_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,12 @@ func testAccStorageTransferJobDestroyProducer(t *testing.T) func(s *terraform.St
}

res, err := config.NewStorageTransferClient(config.userAgent).TransferJobs.Get(name, project).Do()
if res.Status != "DELETED" {
return fmt.Errorf("Transfer Job not set to DELETED")
}
if err != nil {
return fmt.Errorf("Transfer Job does not exist, should exist and be DELETED")
}
if res.Status != "DELETED" {
return fmt.Errorf("Transfer Job not set to DELETED")
}
}

return nil
Expand Down

0 comments on commit 4f4c65f

Please sign in to comment.