Skip to content

Commit d1587b1

Browse files
committed
make the update operations use just a timestamp vs. a datetimestamp
1 parent bcaf8b6 commit d1587b1

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

internal/services/recoveryservices/backup_policy_vm_resource.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,13 @@ func resourceBackupProtectionPolicyVMCreate(d *pluginsdk.ResourceData, meta inte
114114
log.Printf("[DEBUG] Creating %s", id)
115115

116116
// getting this ready now because its shared between *everything*, time is... complicated for this resource
117-
timeOfDay := d.Get("backup.0.time").(string)
118-
dateOfDay, err := time.Parse(time.RFC3339, fmt.Sprintf("%sT%s:00Z", time.Now().Format("2006-01-02"), timeOfDay))
117+
timeOfDay := fmt.Sprintf("%s:00Z", d.Get("backup.0.time").(string))
118+
dateOfDay, err := time.Parse(time.RFC3339, fmt.Sprintf("%sT%s", time.Now().Format("2006-01-02"), timeOfDay))
119119
if err != nil {
120120
return fmt.Errorf("generating time from %q for %s: %+v", timeOfDay, id, err)
121121
}
122122
times := append(make([]string, 0), date.Time{Time: dateOfDay}.String())
123+
formattedTimeOfDay := append(make([]string, 0), timeOfDay)
123124

124125
existing, err := client.Get(ctx, id)
125126
if err != nil {
@@ -150,10 +151,10 @@ func resourceBackupProtectionPolicyVMCreate(d *pluginsdk.ResourceData, meta inte
150151
TieringPolicy: expandBackupProtectionPolicyVMTieringPolicy(d.Get("tiering_policy").([]interface{})),
151152
InstantRPDetails: expandBackupProtectionPolicyVMResourceGroup(d),
152153
RetentionPolicy: &protectionpolicies.LongTermRetentionPolicy{ // SimpleRetentionPolicy only has duration property ¯\_(ツ)_/¯
153-
DailySchedule: expandBackupProtectionPolicyVMRetentionDaily(d, times),
154-
WeeklySchedule: expandBackupProtectionPolicyVMRetentionWeekly(d, times),
155-
MonthlySchedule: expandBackupProtectionPolicyVMRetentionMonthly(d, times),
156-
YearlySchedule: expandBackupProtectionPolicyVMRetentionYearly(d, times),
154+
DailySchedule: expandBackupProtectionPolicyVMRetentionDaily(d, formattedTimeOfDay),
155+
WeeklySchedule: expandBackupProtectionPolicyVMRetentionWeekly(d, formattedTimeOfDay),
156+
MonthlySchedule: expandBackupProtectionPolicyVMRetentionMonthly(d, formattedTimeOfDay),
157+
YearlySchedule: expandBackupProtectionPolicyVMRetentionYearly(d, formattedTimeOfDay),
157158
},
158159
}
159160

@@ -289,12 +290,13 @@ func resourceBackupProtectionPolicyVMUpdate(d *pluginsdk.ResourceData, meta inte
289290
log.Printf("[DEBUG] Updating %s", id)
290291

291292
// getting this ready now because its shared between *everything*, time is... complicated for this resource
292-
timeOfDay := d.Get("backup.0.time").(string)
293-
dateOfDay, err := time.Parse(time.RFC3339, fmt.Sprintf("%sT%s:00Z", time.Now().Format("2006-01-02"), timeOfDay))
293+
timeOfDay := fmt.Sprintf("%s:00Z", d.Get("backup.0.time").(string))
294+
dateOfDay, err := time.Parse(time.RFC3339, fmt.Sprintf("%sT%s", time.Now().Format("2006-01-02"), timeOfDay))
294295
if err != nil {
295296
return fmt.Errorf("generating time from %q for %s: %+v", timeOfDay, id, err)
296297
}
297298
times := append(make([]string, 0), date.Time{Time: dateOfDay}.String())
299+
formattedTimeOfDay := append(make([]string, 0), timeOfDay)
298300

299301
// Less than 7 daily backups is no longer supported for create/update
300302
if d.HasChange("retention_daily.0.count") && (d.Get("retention_daily.0.count").(int) > 1 && d.Get("retention_daily.0.count").(int) < 7) {
@@ -360,7 +362,7 @@ func resourceBackupProtectionPolicyVMUpdate(d *pluginsdk.ResourceData, meta inte
360362
properties.RetentionPolicy = &protectionpolicies.LongTermRetentionPolicy{}
361363
}
362364

363-
retentionPolicy.DailySchedule = expandBackupProtectionPolicyVMRetentionDaily(d, times)
365+
retentionPolicy.DailySchedule = expandBackupProtectionPolicyVMRetentionDaily(d, formattedTimeOfDay)
364366
properties.RetentionPolicy = retentionPolicy
365367
}
366368

@@ -373,7 +375,7 @@ func resourceBackupProtectionPolicyVMUpdate(d *pluginsdk.ResourceData, meta inte
373375
properties.RetentionPolicy = &protectionpolicies.LongTermRetentionPolicy{}
374376
}
375377

376-
retentionPolicy.WeeklySchedule = expandBackupProtectionPolicyVMRetentionWeekly(d, times)
378+
retentionPolicy.WeeklySchedule = expandBackupProtectionPolicyVMRetentionWeekly(d, formattedTimeOfDay)
377379
properties.RetentionPolicy = retentionPolicy
378380
}
379381

@@ -386,7 +388,7 @@ func resourceBackupProtectionPolicyVMUpdate(d *pluginsdk.ResourceData, meta inte
386388
properties.RetentionPolicy = &protectionpolicies.LongTermRetentionPolicy{}
387389
}
388390

389-
retentionPolicy.MonthlySchedule = expandBackupProtectionPolicyVMRetentionMonthly(d, times)
391+
retentionPolicy.MonthlySchedule = expandBackupProtectionPolicyVMRetentionMonthly(d, formattedTimeOfDay)
390392
properties.RetentionPolicy = retentionPolicy
391393
}
392394

@@ -399,7 +401,7 @@ func resourceBackupProtectionPolicyVMUpdate(d *pluginsdk.ResourceData, meta inte
399401
properties.RetentionPolicy = &protectionpolicies.LongTermRetentionPolicy{}
400402
}
401403

402-
retentionPolicy.YearlySchedule = expandBackupProtectionPolicyVMRetentionYearly(d, times)
404+
retentionPolicy.YearlySchedule = expandBackupProtectionPolicyVMRetentionYearly(d, formattedTimeOfDay)
403405
properties.RetentionPolicy = retentionPolicy
404406
}
405407

0 commit comments

Comments
 (0)