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 f5ca502
Show file tree
Hide file tree
Showing 51 changed files with 21,595 additions and 8,328 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
6 changes: 3 additions & 3 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
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
1 change: 1 addition & 0 deletions examples/recoveryservice/.terraform.tfstate.lock.info
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ID":"efa41ad4-efe5-d0ce-3e9d-7934f328acac","Operation":"OperationTypeApply","Info":"","Who":"kt@snowbook","Version":"0.11.7","Created":"2018-11-28T22:45:00.118089337Z","Path":"terraform.tfstate"}
16 changes: 7 additions & 9 deletions examples/recoveryservice/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ module "vm" {
}

resource "azurerm_recovery_services_vault" "example" {
name = "tfex-recovery-vault"
name = "tfex-recovery-vault3"
location = "${azurerm_resource_group.rg.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
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}"
}
2 changes: 1 addition & 1 deletion examples/recoveryservice/variables.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
variable "resource_group_name" {
type = "string"
description = "Name of the azure resource group."
default = "tfex-recovery_services"
default = "tfex-recovery_services3"
}

variable "resource_group_location" {
Expand Down

This file was deleted.

Loading

0 comments on commit f5ca502

Please sign in to comment.