Azure recovery service vault backup policy retentionTimes and scheduleRunTimes incorrect

Azure recovery service vault backup policy retentionTimes and scheduleRunTimes incorrect

Azure Provider: 3.70.0
Terraform version: v1.3.7

After successfully creating a backup policy, I was unable to use this to backup a VM ( the process timed out with an uninformative interanal error):

Exported Policy config:

{
    "status": "Failed",
    "error": {
        "code": "CloudInternalError",
        "message": "Microsoft Azure Backup encountered an internal error."
    }
}

see below the dates starting with 2018-07:

        {
            "type": "Microsoft.RecoveryServices/vaults/backupPolicies",
            "apiVersion": "2023-04-01",
            "name": "[concat(parameters('vaults_sv_dev_eastus_recoveryvault_billing_name'), '/MyDefaultPolicy')]",
            "dependsOn": [
                "[resourceId('Microsoft.RecoveryServices/vaults', parameters('vaults_sv_dev_eastus_recoveryvault_billing_name'))]"
            ],
            "properties": {
                "backupManagementType": "AzureIaasVM",
                "policyType": "V2",
                "instantRPDetails": {},
                "schedulePolicy": {
                    "schedulePolicyType": "SimpleSchedulePolicyV2",
                    "scheduleRunFrequency": "Daily",
                    "dailySchedule": {
                        "scheduleRunTimes": [
                            "2018-07-30T23:00:00Z"
                        ]
                    }
                },
                "retentionPolicy": {
                    "retentionPolicyType": "LongTermRetentionPolicy",
                    "dailySchedule": {
                        "retentionTimes": [
                            "2018-07-30T23:00:00Z"
                        ],
                        "retentionDuration": {
                            "count": 7,
                            "durationType": "Days"
                        }
                    },
                    "weeklySchedule": {
                        "daysOfTheWeek": [
                            "Thursday",
                            "Friday",
                            "Wednesday",
                            "Saturday",
                            "Tuesday",
                            "Monday",
                            "Sunday"
                        ],
                        "retentionTimes": [
                            "2018-07-30T23:00:00Z"
                        ],
                        "retentionDuration": {
                            "count": 4,
                            "durationType": "Weeks"
                        }
                    },
                    "monthlySchedule": {
                        "retentionScheduleFormatType": "Weekly",
                        "retentionScheduleWeekly": {
                            "daysOfTheWeek": [
                                "Sunday"
                            ],
                            "weeksOfTheMonth": [
                                "Last",
                                "First"
                            ]
                        },
                        "retentionTimes": [
                            "2018-07-30T23:00:00Z"
                        ],
                        "retentionDuration": {
                            "count": 12,
                            "durationType": "Months"
                        }
                    },
                    "yearlySchedule": {
                        "retentionScheduleFormatType": "Weekly",
                        "monthsOfYear": [
                            "January"
                        ],
                        "retentionScheduleWeekly": {
                            "daysOfTheWeek": [
                                "Sunday"
                            ],
                            "weeksOfTheMonth": [
                                "Last"
                            ]
                        },
                        "retentionTimes": [
                            "2018-07-30T23:00:00Z"
                        ],
                        "retentionDuration": {
                            "count": 4,
                            "durationType": "Years"
                        }
                    }
                },
                "instantRpRetentionRangeInDays": 7,
                "timeZone": "UTC",
                "protectedItemsCount": 0
            }
        },

Anyone have any ideas why this may be occuring?

tsvars:

backup_policy_list = {
  flexdefault = {
    policy_name                    =  "MyVMDefaultPolicy"
    policy_type                    =  "V2"
    policy_timezone                =  "UTC"
    instant_restore_retention_days = null
    backup_policy_backup = [
      { frequency     = "Daily", time = "23:00", hour_interval = null, hour_duration = null }
    ]
    backup_policy_retention_daily = [
      { count = "7" }
    ]
    backup_policy_retention_weekly  = [
      { 
        count = 4  
        weekdays = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"] 
      }
    ]
    backup_policy_retention_monthly = [
      { 
        count    = 12 
        weekdays = ["Sunday"] 
        weeks    = ["First","Last"]
      }
    ]
    backup_policy_retention_yearly  = [
      {
        count    = 4  
        weekdays = ["Sunday"] 
        weeks    = ["Last"] 
        months   = ["January"] 
      }
    ]
  }

Module:

resource "azurerm_backup_policy_vm" "backup_policy" {  
for_each = { for idx,val in var.backup_policy_list: idx => val }    
  resource_group_name            = var.backup_policy_res_group_name
  recovery_vault_name            = var.backup_policy_vault_name 
  name                           = each.value.policy_name
  policy_type                    = each.value.policy_type
  timezone                       = each.value.policy_timezone
  instant_restore_retention_days = each.value.instant_restore_retention_days
    dynamic "backup"{
    for_each = each.value.backup_policy_backup
    content {
      frequency     = backup.value["frequency"]
      time          = backup.value["time"]
      hour_interval = backup.value["hour_interval"]
      hour_duration = backup.value["hour_duration"]
    }
  }  
dynamic "retention_daily" {
    for_each = each.value.backup_policy_retention_daily
    content {
      count = retention_daily.value["count"]
    }
  }

    dynamic "retention_weekly" {
    for_each = each.value.backup_policy_retention_weekly
    content {
      count    = retention_weekly.value["count"]
      weekdays = retention_weekly.value["weekdays"]

    }
  }

    dynamic "retention_monthly" {
    for_each = each.value.backup_policy_retention_monthly
    content {
      count    = retention_monthly.value["count"]
      weekdays = retention_monthly.value["weekdays"]
      weeks    = retention_monthly.value["weeks"]
    }
  }

This bug has now been fixed:

“azurerm_backup_policy_vm”: fix payload by ziyeqf · Pull Request #23586 · hashicorp/terraform-provider-azurerm (github.com)