-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
azurerm_recovery_services_protection_policy_vm: add timezone property #2404
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import ( | |
"strings" | ||
"time" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2016-06-01/backup" | ||
"github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2017-07-01/backup" | ||
|
||
"github.com/Azure/go-autorest/autorest/date" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
|
@@ -55,6 +55,12 @@ func resourceArmRecoveryServicesProtectionPolicyVm() *schema.Resource { | |
), | ||
}, | ||
|
||
"timezone": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "UTC", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we apply some validation to this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice, however I don't know what of the many different timezone formats is valid here (there are at least 2 different sets of valid values it could be, maybe more) |
||
}, | ||
|
||
"backup": { | ||
Type: schema.TypeList, | ||
MaxItems: 1, | ||
|
@@ -156,11 +162,11 @@ func resourceArmRecoveryServicesProtectionPolicyVm() *schema.Resource { | |
Type: schema.TypeString, | ||
DiffSuppressFunc: suppress.CaseDifference, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
string(backup.First), | ||
string(backup.Second), | ||
string(backup.Third), | ||
string(backup.Fourth), | ||
string(backup.Last), | ||
string(backup.WeekOfMonthFirst), | ||
string(backup.WeekOfMonthSecond), | ||
string(backup.WeekOfMonthThird), | ||
string(backup.WeekOfMonthFourth), | ||
string(backup.WeekOfMonthLast), | ||
}, true), | ||
}, | ||
}, | ||
|
@@ -210,11 +216,11 @@ func resourceArmRecoveryServicesProtectionPolicyVm() *schema.Resource { | |
Type: schema.TypeString, | ||
DiffSuppressFunc: suppress.CaseDifference, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
string(backup.First), | ||
string(backup.Second), | ||
string(backup.Third), | ||
string(backup.Fourth), | ||
string(backup.Last), | ||
string(backup.WeekOfMonthFirst), | ||
string(backup.WeekOfMonthSecond), | ||
string(backup.WeekOfMonthThird), | ||
string(backup.WeekOfMonthFourth), | ||
string(backup.WeekOfMonthLast), | ||
}, true), | ||
}, | ||
}, | ||
|
@@ -291,6 +297,7 @@ func resourceArmRecoveryServicesProtectionPolicyVmCreateUpdate(d *schema.Resourc | |
policy := backup.ProtectionPolicyResource{ | ||
Tags: expandTags(tags), | ||
Properties: &backup.AzureIaaSVMProtectionPolicy{ | ||
TimeZone: utils.String(d.Get("timezone").(string)), | ||
BackupManagementType: backup.BackupManagementTypeAzureIaasVM, | ||
SchedulePolicy: expandArmRecoveryServicesProtectionPolicySchedule(d, times), | ||
RetentionPolicy: &backup.LongTermRetentionPolicy{ //SimpleRetentionPolicy only has duration property ¯\_(ツ)_/¯ | ||
|
@@ -347,8 +354,10 @@ func resourceArmRecoveryServicesProtectionPolicyVmRead(d *schema.ResourceData, m | |
d.Set("recovery_vault_name", vaultName) | ||
|
||
if properties, ok := resp.Properties.AsAzureIaaSVMProtectionPolicy(); ok && properties != nil { | ||
if schedule, ok := properties.SchedulePolicy.AsSimpleSchedulePolicy(); ok && schedule != nil { | ||
|
||
d.Set("timezone", properties.TimeZone) | ||
|
||
if schedule, ok := properties.SchedulePolicy.AsSimpleSchedulePolicy(); ok && schedule != nil { | ||
if err := d.Set("backup", flattenArmRecoveryServicesProtectionPolicySchedule(schedule)); err != nil { | ||
return fmt.Errorf("Error setting `backup`: %+v", err) | ||
} | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo we should be raising this error, since
i
won't be valid if it's non-nil?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am raising it as part of the errorf? the cast is done like this because sometimes resp ends up being nil 🤷♀️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I was referring to the casting error that's a
_
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the reasoning behind this is if resp is nil
fails.
however if you use the
ok
cast, even if its_
for unusedthe cast doesn't not fail on a nil value and I becomes the zero value for (backup.ProtectedItemResource): https://play.golang.org/p/cDZrRXP6C27