Error when deleting resources created with ARM template via Terraform on Azure

0

I have been working on a terraform script to create windows virtual desktop infrastructure. Unfortunately, there doesn’t seem to be any way to create & add VMs to the hostpool, so I resorted to using an ARM template via terraform. This part is working great. I have a problem when I go to remove the infrastructure setup via the ARM template by simply commenting it out in my terraform script. I, of course, expect it to destroy that infrastructure but instead I am getting this error and nothing is being destroyed:

azurerm_resource_group_template_deployment.wvd_session_hosts_arm: Destroying… [id=/subscriptions/5ba62485-1e62-4a66-abac-7e4d8e1786de/resourceGroups/wvd-rg/providers/Microsoft.Resources/deployments/wvdhosts]

Error: removing items provisioned by this Template Deployment: API version information for RP “Microsoft.Compute” was not found

here is the relevant code from my terraform script (shortened a bit to fit here):

resource "azurerm_resource_group_template_deployment" "wvd_session_hosts_arm" {
      name                = "wvdhosts"
      resource_group_name = azurerm_resource_group.wvd.name
      deployment_mode     = "Complete"
          
      template_content = <<TEMPLATE
    {
        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "nestedTemplatesLocation": {
                "type": "string",
                "metadata": {
                    "description": "The base URI where artifacts required by this template are located."
                },
                "defaultValue": "https://catalogartifact.azureedge.net/publicartifacts/Microsoft.Hostpool-ARM-1.0.18-preview/"
            },
            "artifactsLocation": {
                "type": "string",
                "metadata": {
                    "description": "The base URI where artifacts required by this template are located."
                },
                "defaultValue": "https://wvdportalstorageblob.blob.core.windows.net/galleryartifacts/Configuration.zip"
            },
            "hostpoolName": {
                "type": "string",
                "metadata": {
                    "description": "The name of the Hostpool to be created."
                },
                "defaultValue": "wvd-pool-hp"
            },
            "hostpoolFriendlyName": {
                "type": "string",
                "metadata": {
                    "description": "The friendly name of the Hostpool to be created."
                },
                "defaultValue": ""
            },
            "hostpoolDescription": {
                "type": "string",
                "metadata": {
                    "description": "The description of the Hostpool to be created."
                },
                "defaultValue": "Created through the WVD extension"
            },
            "location": {
                "type": "string",
                "metadata": {
                    "description": "The location where the resources will be deployed."
                },
                "defaultValue": "westus2"
            },
            ...
"vmAdministratorAccountUsername": {
                "type": "string",
                "metadata": {
                    "description": "A username to be used as the virtual machine administrator account. The domain administrator username will be used if this parameter is not provided."
                },
                "defaultValue": "${var.dcadminuser}"
            },
            "vmAdministratorAccountPassword": {
                "type": "securestring",
                "metadata": {
                    "description": "The password associated with the virtual machine administrator account. The domain administrator password will be used if this parameter is not provided."
                },
                "defaultValue": "${var.dcadminpwd}"
            },
            "createAvailabilitySet": {
                "type": "bool",
                "metadata": {
                    "description": "Whether to create a new availability set for the VMs"
                },
                "defaultValue": true
            },
            "vmResourceGroup": {
                "type": "string",
                "metadata": {
                    "description": "The resource group of the session host VMs."
                },
                "defaultValue": "wvd-rg"
            },
            "vmLocation": {
                "type": "string",
                "metadata": {
                    "description": "The location of the session host VMs."
                },
                "defaultValue": "${var.location}"
            },
            "vmSize": {
                "type": "string",
                "metadata": {
                    "description": "The size of the session host VMs."
                },
                "defaultValue": "Standard_D2s_v3"
            },
            "vmNumberOfInstances": {
                "type": "int",
                "metadata": {
                    "description": "Number of session hosts that will be created and added to the hostpool."
                },
                "defaultValue": ${var.rdsh_count}
            },
            "vmNamePrefix": {
                "type": "string",
                "metadata": {
                    "description": "This prefix will be used in combination with the VM number to create the VM name. If using 'rdsh' as the prefix, VMs would be named 'rdsh-0', 'rdsh-1', etc. You should use a unique prefix to reduce name collisions in Active Directory."
                },
                "defaultValue": "wvdhost"
            },
            "vmImageType": {
                "type": "string",
                "metadata": {
                    "description": "Select the image source for the session host vms. VMs from a Gallery image will be created with Managed Disks."
                },
                "defaultValue": "Gallery",
                "allowedValues": [
                    "CustomVHD",
                    "CustomImage",
                    "Gallery"
                ]
            },
            "vmGalleryImageOffer": {
                "type": "string",
                "metadata": {
                    "description": "(Required when vmImageType = Gallery) Gallery image Offer."
                },
                "defaultValue": "office-365"
            },
            "vmGalleryImagePublisher": {
                "type": "string",
                "metadata": {
                    "description": "(Required when vmImageType = Gallery) Gallery image Publisher."
                },
                "defaultValue": "MicrosoftWindowsDesktop"
            },
            "vmGalleryImageSKU": {
                "type": "string",
                "metadata": {
                    "description": "(Required when vmImageType = Gallery) Gallery image SKU."
                },
                "defaultValue": "19h2-evd-o365pp"
            },
            "vmImageVhdUri": {
                "type": "string",
                "metadata": {
                    "description": "(Required when vmImageType = CustomVHD) URI of the sysprepped image vhd file to be used to create the session host VMs. For example, https://rdsstorage.blob.core.windows.net/vhds/sessionhostimage.vhd"
                },
                "defaultValue": ""
            },
            "vmCustomImageSourceId": {
                "type": "string",
                "metadata": {
                    "description": "(Required when vmImageType = CustomImage) Resource ID of the image"
                },
                "defaultValue": ""
            },
            "vmDiskType": {
                "type": "string",
                "allowedValues": [
                    "Premium_LRS",
                    "StandardSSD_LRS",
                    "Standard_LRS"
                ],
                "metadata": {
                    "description": "The VM disk type for the VM: HDD or SSD."
                },
                "defaultValue": "StandardSSD_LRS"
            },
            "vmUseManagedDisks": {
                "type": "bool",
                "metadata": {
                    "description": "True indicating you would like to use managed disks or false indicating you would like to use unmanaged disks."
                },
                "defaultValue": true
            },
            "storageAccountResourceGroupName": {
                "type": "string",
                "metadata": {
                    "description": "(Required when vmUseManagedDisks = False) The resource group containing the storage account of the image vhd file."
                },
                "defaultValue": ""
            },
            "existingVnetName": {
                "type": "string",
                "metadata": {
                    "description": "The name of the virtual network the VMs will be connected to."
                },
                "defaultValue": "dc-network"
            },
            "existingSubnetName": {
                "type": "string",
                "metadata": {
                    "description": "The subnet the VMs will be placed in."
                },
                "defaultValue": "dc-subnet"
            },
            "virtualNetworkResourceGroupName": {
                "type": "string",
                "metadata": {
                    "description": "The resource group containing the existing virtual network."
                },
                "defaultValue": "dc-rg"
            },
            "createNetworkSecurityGroup": {
                "type": "bool",
                "metadata": {
                    "description": "Whether to create a new network security group or use an existing one"
                },
                "defaultValue": false
            },
            "networkSecurityGroupId": {
                "type": "string",
                "metadata": {
                    "description": "The resource id of an existing network security group"
                },
                "defaultValue": ""
            },
            "networkSecurityGroupRules": {
                "type": "array",
                "metadata": {
                    "description": "The rules to be given to the new network security group"
                },
                "defaultValue": []
            },
            "hostpoolType": {
                "type": "string",
                "allowedValues": [
                    "Personal",
                    "Pooled"
                ],
                "metadata": {
                    "description": "Set this parameter to Personal if you would like to enable Persistent Desktop experience. Defaults to false."
                },
                "defaultValue" : "Pooled"
            },
            "personalDesktopAssignmentType": {
                "type": "string",
                "allowedValues": [
                    "Automatic",
                    "Direct",
                    ""
                ],
                "metadata": {
                    "description": "Set the type of assignment for a Personal hostpool type"
                },
                "defaultValue": ""
            },
            "maxSessionLimit": {
                "type": "int",
                "metadata": {
                    "description": "Maximum number of sessions."
                },
                "defaultValue": 10
            },
            "loadBalancerType": {
                "type": "string",
                "allowedValues": [
                    "BreadthFirst",
                    "DepthFirst",
                    "Persistent"
                ],
                "metadata": {
                    "description": "Type of load balancer algorithm."
                },
                "defaultValue": "BreadthFirst"
            },
            "customRdpProperty": {
                "type": "string",
                "metadata": {
                    "description": "Hostpool rdp properties"
                },
                "defaultValue": ""
            },
            "vmTemplate": {
                "type": "string",
                "metadata": {
                    "description": "The necessary information for adding more VMs to this Hostpool"
                },
                "defaultValue": "{\"domain\":\"${var.domain}\",\"galleryImageOffer\":\"office-365\",\"galleryImagePublisher\":\"MicrosoftWindowsDesktop\",\"galleryImageSKU\":\"19h2-evd-o365pp\",\"imageType\":\"Gallery\",\"imageUri\":null,\"customImageId\":null,\"namePrefix\":\"wvdhost\",\"osDiskType\":\"StandardSSD_LRS\",\"useManagedDisks\":true,\"vmSize\":{\"id\":\"Standard_D2s_v3\",\"cores\":2,\"ram\":8},\"galleryItemId\":\"MicrosoftWindowsDesktop.office-36519h2-evd-o365pp\"}"
            },
            ...
            "apiVersion": {
                "type": "string",
                "metadata": {
                    "description": "WVD api version"
                },
                "defaultValue": "2019-12-10-preview"
            },
            "deploymentId": {
                "type": "string",
                "metadata": {
                    "description": "GUID for the deployment"
                },
                "defaultValue": "${random_uuid.wvd.result}"
            },
            ...
        },
        "variables": {
            "createVMs": "[greater(parameters('vmNumberOfInstances'),0)]",
            "rdshManagedDisks": "[if(equals(parameters('vmImageType'), 'CustomVHD'), parameters('vmUseManagedDisks'), bool('true'))]",
            "rdshPrefix": "[concat(parameters('vmNamePrefix'),'-')]",
            "avSetSKU": "[if(variables('rdshManagedDisks'), 'Aligned', 'Classic')]",
            "vhds": "[concat('vhds','/', variables('rdshPrefix'))]",
            "subnet-id": "[resourceId(parameters('virtualNetworkResourceGroupName'),'Microsoft.Network/virtualNetworks/subnets',parameters('existingVnetName'), parameters('existingSubnetName'))]",
            "hostpoolName": "[replace(parameters('hostpoolName'),'\"','')]",
            "hostpoolFriendlyName": "[parameters('hostpoolFriendlyName')]",
            "vmTemplateName": "[concat( if(variables('rdshManagedDisks'), 'managedDisks', 'unmanagedDisks'), '-', toLower(replace(parameters('vmImageType'),' ', '')), 'vm')]",
            "vmTemplateUri": "[concat(parameters('nestedTemplatesLocation'), variables('vmTemplateName'),'.json')]",
            "rdshVmNamesOutput": {
                "copy": [
                    {
                        "name": "rdshVmNamesCopy",
                        "count": "[if(variables('createVMs'), parameters('vmNumberOfInstances'), 1)]",
                        "input": {
                            "name": "[concat(variables('rdshPrefix'),copyIndex('rdshVmNamesCopy'))]"
                        }
                    }
                ]
            },
            "appGroupName": "[concat(variables('hostpoolName'),'-DAG')]",
            "appGroupResourceId": "[createArray(resourceId('Microsoft.DesktopVirtualization/applicationgroups/', variables('appGroupName')))]",
            "workspaceResourceGroup": "[if(empty(parameters('workspaceResourceGroup')), resourceGroup().name, parameters('workspaceResourceGroup'))]",
            "applicationGroupReferencesArr": "[if(equals('',parameters('allApplicationGroupReferences')), variables('appGroupResourceId'), concat(split(parameters('allApplicationGroupReferences'),','), variables('appGroupResourceId')))]"
        },
        "resources": [
            {
                "name": "[parameters('hostpoolName')]",
                "apiVersion": "[parameters('apiVersion')]",
                "type": "Microsoft.DesktopVirtualization/hostpools",
                "location": "[parameters('location')]",
                "tags": "[parameters('hostpoolTags')]",
                "properties": {
                    "friendlyName": "[parameters('hostpoolFriendlyName')]",
                    "description": "[parameters('hostpoolDescription')]",
                    "hostpoolType": "[parameters('hostpoolType')]",
                    "customRdpProperty": "[parameters('customRdpProperty')]",
                    "personalDesktopAssignmentType": "[parameters('personalDesktopAssignmentType')]",
                    "maxSessionLimit": "[parameters('maxSessionLimit')]",
                    "loadBalancerType": "[parameters('loadBalancerType')]",
                    "validationEnvironment": "[parameters('validationEnvironment')]",
                    "preferredAppGroupType": "[parameters('preferredAppGroupType')]",
                    "ring": null,
                    "registrationInfo": {
                        "expirationTime": "[parameters('tokenExpirationTime')]",
                        "token": null,
                        "registrationTokenOperation": "Update"
                    },
                    "vmTemplate": "[parameters('vmTemplate')]"
                }
            },
            {
                "name": "[variables('appGroupName')]",
                "apiVersion": "[parameters('apiVersion')]",
                "type": "Microsoft.DesktopVirtualization/applicationgroups",
                "location": "[parameters('location')]",
                "tags": "[parameters('applicationGroupTags')]",
                "properties": {
                    "hostpoolarmpath": "[resourceId('Microsoft.DesktopVirtualization/hostpools/', parameters('hostpoolName'))]",
                    "friendlyName": "Default Desktop",
                    "description": "Desktop Application Group created through the Hostpool Wizard",
                    "applicationGroupType": "Desktop"
                },
                "dependsOn": [
                    "[resourceId('Microsoft.DesktopVirtualization/hostpools/', parameters('hostpoolName'))]"
                ]
            },
            {
                "apiVersion": "2018-05-01",
                "name": "[concat('Workspace-linkedTemplate-', parameters('deploymentId'))]",
                "type": "Microsoft.Resources/deployments",
                "resourceGroup": "[variables('workspaceResourceGroup')]",
                "condition": "[parameters('addToWorkspace')]",
                "properties": {
                    "mode": "Incremental",
                    "template": {
                        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                        "contentVersion": "1.0.0.0",
                        "resources": [
                            {
                                "apiVersion": "[parameters('apiVersion')]",
                                "name": "[parameters('workSpaceName')]",
                                "type": "Microsoft.DesktopVirtualization/workspaces",
                                "location": "[parameters('workspaceLocation')]",
                                "properties": {
                                    "applicationGroupReferences": "[variables('applicationGroupReferencesArr')]"
                                }
                            }
                        ]
                    }
                },
                "dependsOn": [
                    "[resourceId('Microsoft.DesktopVirtualization/applicationgroups/', variables('appGroupName'))]"
                ]
            },
            {
                "apiVersion": "2018-05-01",
                "name": "[concat('AVSet-linkedTemplate-', parameters('deploymentId'))]",
                "type": "Microsoft.Resources/deployments",
                "resourceGroup": "[parameters('vmResourceGroup')]",
                "condition": "[parameters('createAvailabilitySet')]",
                "properties": {
                    "mode": "Incremental",
                    "template": {
                        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                        "contentVersion": "1.0.0.0",
                        "resources": [
                            {
                                "apiVersion": "2018-10-01",
                                "type": "Microsoft.Compute/availabilitySets",
                                "name": "[concat(variables('rdshPrefix'), 'availabilitySet-', parameters('vmLocation'))]",
                                "location": "[parameters('vmLocation')]",
                                "tags": "[parameters('availabilitySetTags')]",
                                "properties": {
                                    "platformUpdateDomainCount": 5,
                                    "platformFaultDomainCount": 2
                                },
                                "sku": {
                                    "name": "[variables('avSetSKU')]"
                                }
                            }
                        ]
                    }
                },
                "dependsOn": [
                    "[resourceId('Microsoft.DesktopVirtualization/applicationgroups', variables('appGroupName'))]"
                ]
            },
            {
                "apiVersion": "2018-05-01",
                "name": "[concat('vmCreation-linkedTemplate-', parameters('deploymentId'))]",
                "type": "Microsoft.Resources/deployments",
                "condition": "[variables('createVMs')]",
                "resourceGroup": "[parameters('vmResourceGroup')]",
                "dependsOn": [
                    "[concat('AVSet-linkedTemplate-', parameters('deploymentId'))]"
                ],
                "properties": {
                    "mode": "Incremental",
                    "templateLink": {
                        "uri": "[variables('vmTemplateUri')]",
                        "contentVersion": "1.0.0.0"
                    },
                    "parameters": {
                        "artifactsLocation": {
                            "value": "[parameters('artifactsLocation')]"
                        },
                        "vmImageVhdUri": {
                            "value": "[parameters('vmImageVhdUri')]"
                        },
                        "storageAccountResourceGroupName": {
                            "value": "[parameters('storageAccountResourceGroupName')]"
                        },
                        "vmGalleryImageOffer": {
                            "value": "[parameters('vmGalleryImageOffer')]"
                        },
                        "vmGalleryImagePublisher": {
                            "value": "[parameters('vmGalleryImagePublisher')]"
                        },
                        "vmGalleryImageSKU": {
                            "value": "[parameters('vmGalleryImageSKU')]"
                        },
                        "rdshPrefix": {
                            "value": "[variables('rdshPrefix')]"
                        },
                        "rdshNumberOfInstances": {
                            "value": "[parameters('vmNumberOfInstances')]"
                        },
                        "rdshVMDiskType": {
                            "value": "[parameters('vmDiskType')]"
                        },
                        "rdshVmSize": {
                            "value": "[parameters('vmSize')]"
                        },
                        "enableAcceleratedNetworking": {
                            "value": false
                        },
                        "vmAdministratorAccountUsername": {
                            "value": "[parameters('vmAdministratorAccountUsername')]"
                        },
                        "vmAdministratorAccountPassword": {
                            "value": "[parameters('vmAdministratorAccountPassword')]"
                        },
                        "administratorAccountUsername": {
                            "value": "[parameters('administratorAccountUsername')]"
                        },
                        "administratorAccountPassword": {
                            "value": "[parameters('administratorAccountPassword')]"
                        },
                        "subnet-id": {
                            "value": "[variables('subnet-id')]"
                        },
                        "vhds": {
                            "value": "[variables('vhds')]"
                        },
                        "rdshImageSourceId": {
                            "value": "[parameters('vmCustomImageSourceId')]"
                        },
                        "location": {
                            "value": "[parameters('vmLocation')]"
                        },
                        "createNetworkSecurityGroup": {
                            "value": "[parameters('createNetworkSecurityGroup')]"
                        },
                        "networkSecurityGroupId": {
                            "value": "[parameters('networkSecurityGroupId')]"
                        },
                        "networkSecurityGroupRules": {
                            "value": "[parameters('networkSecurityGroupRules')]"
                        },
                        "networkInterfaceTags": {
                            "value": "[parameters('networkInterfaceTags')]"
                        },
                        "networkSecurityGroupTags": {
                            "value": "[parameters('networkSecurityGroupTags')]"
                        },
                        "virtualMachineTags": {
                            "value": "[parameters('virtualMachineTags')]"
                        },
                        "imageTags": {
                            "value": "[parameters('imageTags')]"
                        },
                        "hostpoolToken": {
                            "value": "[reference(parameters('hostpoolName')).registrationInfo.token]"
                        },
                        "hostpoolName": {
                            "value": "[parameters('hostpoolName')]"
                        },
                        "domain": {
                            "value": "[parameters('domain')]"
                        },
                        "ouPath": {
                            "value": "[parameters('ouPath')]"
                        },
                        "_guidValue": {
                            "value": "[parameters('deploymentId')]"
                        }
                    }
                }
            }
        ],
        "outputs": {
            "rdshVmNamesObject": {
                "value": "[variables('rdshVmNamesOutput')]",
                "type": "object"
            }
        }
    }
    TEMPLATE
    
      #depends_on = [azurerm_virtual_desktop_host_pool.wvdhppooled]
    }

I really appreciate any assistance or insight.

thank you