1
votes

I am trying to create a weekly Azure VM protection policy in Terraform to run on Fridays at 6:30 pm with a retention of 1. TF throws format error related to 'schedule time, schedule days, retention time and retention days' error. I am not exactly sure which parameter has an incorrect value or format.

resource "azurerm_recovery_services_vault" "backup_vault" {
  name                = "${var.RG4VM}-recovery-vault"
  location            = "${var.VMLocation}"
  resource_group_name = "${var.RG4VM}"
  sku                 = "Standard"
  depends_on          = ["azurerm_resource_group.ResourceGroup"]
}

resource "azurerm_recovery_services_protection_policy_vm" "backup_policy" {
  name                = "${var.RG4VM}-bkp-policy"
  resource_group_name = "${var.RG4VM}"
  recovery_vault_name = "${azurerm_recovery_services_vault.backup_vault.name}"
  depends_on          = ["azurerm_recovery_services_vault.backup_vault"]

  backup {
    frequency = "Weekly"
    time      = "18:30"
  }

  retention_weekly {
    count    = 1
    weekdays = ["Friday"]
  }
} 

Expected: It should create the policy as per the config defined.

Actual:

  • azurerm_recovery_services_protection_policy_vm.backup_policy: 1 error(s) occurred:

  • azurerm_recovery_services_protection_policy_vm.backup_policy: Error creating/updating Recovery Service Protection Policy "Terraform-Linux-Test-RG-bkp-policy" (Resource Group "Terraform-Linux-Test-RG"): backup.ProtectionPoliciesClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BMSUserErrorInvalidPolicyInput" Message="Input for create or update policy is not in proper format\r\nPlease check format of parameters like schedule time, schedule days, retention time and retention days "

I'd appreciate any help in resolving this issue.

Thanks Asghar

1
I rechecked the formatting based on terraform.io/docs/providers/azurerm/r/…. Not exactly sure what formatting mistake I am doing. I only want weekly backups to run at 6:30 pm on Fridays with a retention of 1 week.Asghar

1 Answers

1
votes

For your issue, maybe it's a little mistake that you did. You just need to make a change in the backup block of the policy like this:

backup {
    frequency = "Weekly"
    time      = "18:30"
    weekdays  = ["Friday"]
  }

Then it will work fine. The screenshot of the test on my side below:

enter image description here