Skip to content

Commit

Permalink
added timezone property to recovery vault policy
Browse files Browse the repository at this point in the history
  • Loading branch information
katbyte committed Nov 28, 2018
1 parent c73c2e8 commit 37e6593
Show file tree
Hide file tree
Showing 49 changed files with 21,594 additions and 8,327 deletions.
6 changes: 3 additions & 3 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ import (
"github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/2017-08-01-preview/security"
"github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/2015-05-01-preview/sql"
MsSql "github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/2017-10-01-preview/sql"
"github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2016-06-01/backup"
"github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2016-06-01/recoveryservices"
"github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2017-07-01/backup"
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2018-03-01/redis"
"github.com/Azure/azure-sdk-for-go/services/relay/mgmt/2017-04-01/relay"
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2016-06-01/subscriptions"
Expand Down Expand Up @@ -256,7 +256,7 @@ type ArmClient struct {

// Recovery Services
recoveryServicesVaultsClient recoveryservices.VaultsClient
recoveryServicesProtectedItemsClient backup.ProtectedItemsClient
recoveryServicesProtectedItemsClient backup.ProtectedItemsGroupClient
recoveryServicesProtectionPoliciesClient backup.ProtectionPoliciesClient

// Relay
Expand Down Expand Up @@ -963,7 +963,7 @@ func (c *ArmClient) registerRecoveryServiceClients(endpoint, subscriptionId stri
c.configureClient(&vaultsClient.Client, auth)
c.recoveryServicesVaultsClient = vaultsClient

protectedItemsClient := backup.NewProtectedItemsClientWithBaseURI(endpoint, subscriptionId)
protectedItemsClient := backup.NewProtectedItemsGroupClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&protectedItemsClient.Client, auth)
c.recoveryServicesProtectedItemsClient = protectedItemsClient

Expand Down
9 changes: 5 additions & 4 deletions azurerm/resource_arm_recovery_services_protected_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -92,7 +92,7 @@ func resourceArmRecoveryServicesProtectedVmCreateUpdate(d *schema.ResourceData,
Properties: &backup.AzureIaaSComputeVMProtectedItem{
PolicyID: &policyId,
ProtectedItemType: backup.ProtectedItemTypeMicrosoftClassicComputevirtualMachines,
WorkloadType: backup.VM,
WorkloadType: backup.DataSourceTypeVM,
SourceResourceID: utils.String(vmId),
FriendlyName: utils.String(vmName),
VirtualMachineID: utils.String(vmId),
Expand Down Expand Up @@ -187,7 +187,7 @@ func resourceArmRecoveryServicesProtectedVmDelete(d *schema.ResourceData, meta i
return nil
}

func resourceArmRecoveryServicesProtectedVmWaitForState(client backup.ProtectedItemsClient, ctx context.Context, found bool, vaultName, resourceGroup, containerName, protectedItemName string) (backup.ProtectedItemResource, error) {
func resourceArmRecoveryServicesProtectedVmWaitForState(client backup.ProtectedItemsGroupClient, ctx context.Context, found bool, vaultName, resourceGroup, containerName, protectedItemName string) (backup.ProtectedItemResource, error) {
state := &resource.StateChangeConf{
Timeout: 30 * time.Minute,
MinTimeout: 30 * time.Second,
Expand Down Expand Up @@ -217,7 +217,8 @@ func resourceArmRecoveryServicesProtectedVmWaitForState(client backup.ProtectedI

resp, err := state.WaitForState()
if err != nil {
return resp.(backup.ProtectedItemResource), fmt.Errorf("Error waiting for the Recovery Service Protected VM %q to be %t (Resource Group %q) to provision: %+v", protectedItemName, found, resourceGroup, err)
i, _ := resp.(backup.ProtectedItemResource)
return i, fmt.Errorf("Error waiting for the Recovery Service Protected VM %q to be %t (Resource Group %q) to provision: %+v", protectedItemName, found, resourceGroup, err)
}

return resp.(backup.ProtectedItemResource), nil
Expand Down
33 changes: 21 additions & 12 deletions azurerm/resource_arm_recovery_services_protection_policy_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -55,6 +55,12 @@ func resourceArmRecoveryServicesProtectionPolicyVm() *schema.Resource {
),
},

"timezone": {
Type: schema.TypeString,
Optional: true,
Default: "UTC",
},

"backup": {
Type: schema.TypeList,
MaxItems: 1,
Expand Down Expand Up @@ -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),
},
},
Expand Down Expand Up @@ -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),
},
},
Expand Down Expand Up @@ -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 ¯\_(ツ)_/¯
Expand Down Expand Up @@ -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)
}
Expand Down
14 changes: 6 additions & 8 deletions examples/recoveryservice/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ resource "azurerm_recovery_services_vault" "example" {
sku = "Standard"
}

resource "azurerm_recovery_services_protection_policy_vm" "example" {
resource "azurerm_recovery_services_protection_policy_vm" "simple" {
name = "tfex-policy-simple"
resource_group_name = "${azurerm_resource_group.rg.name}"
recovery_vault_name = "${azurerm_recovery_services_vault.example.name}"
Expand All @@ -42,21 +42,19 @@ resource "azurerm_recovery_services_protection_policy_vm" "example" {
}
}

resource "azurerm_recovery_services_protection_policy_vm" "example" {
resource "azurerm_recovery_services_protection_policy_vm" "advanced" {
name = "tfex-policy-advanced"
resource_group_name = "${azurerm_resource_group.rg.name}"
recovery_vault_name = "${azurerm_recovery_services_vault.example.name}"

timezone = "UTC"

backup = {
frequency = "Daily"
frequency = "Weekly"
time = "23:00"
weekdays = ["Monday", "Wednesday"]
}

retention_daily = {
count = 10
}

retention_weekly = {
weekdays = ["Monday", "Wednesday"]
count = 52
Expand All @@ -79,6 +77,6 @@ resource "azurerm_recovery_services_protection_policy_vm" "example" {
resource "azurerm_recovery_services_protected_vm" "example" {
resource_group_name = "${azurerm_resource_group.rg.name}"
recovery_vault_name = "${azurerm_recovery_services_vault.example.name}"
source_vm_name = "${module.vm.vm-name}"
source_vm_id = "${module.vm.vm-id}"
backup_policy_id = "${azurerm_recovery_services_protection_policy_vm.simple.id}"
}

This file was deleted.

Loading

0 comments on commit 37e6593

Please sign in to comment.