hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.53k stars 4.6k forks source link

Unable to destroy/recreate azurerm_resource_group_template_deployment after taint #11494

Open ajklotz opened 3 years ago

ajklotz commented 3 years ago

Community Note

Terraform (and AzureRM Provider) Version

Affected Resource(s)

Terraform v0.14.7
+ provider registry.terraform.io/hashicorp/azurerm v2.44.0

Terraform Configuration Files

resource "azurerm_resource_group_template_deployment" "api_virtual_directory" {
  name                = "api_virtual_directory"
  resource_group_name = azurerm_resource_group.digital.name
  deployment_mode     = "Incremental"
  template_content    = <<TEMPLATE
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "webAppName": {
        "type": "String",
        "defaultValue": "${module.webapp["api"].name}"
    },
    "virtualApplications":{
      "type": "Array",
      "defaultValue":[
        {
        "virtualPath": "/",
        "physicalPath": "site\\wwwroot",
        "preloadEnabled": false,
        "virtualDirectories": null
        },
        {
        "virtualPath": "/app1",
        "physicalPath": "site\\wwwroot\\app1",
        "preloadEnabled": false,
        "virtualDirectories": null
        },
        {
        "virtualPath": "/app2",
        "physicalPath": "site\\wwwroot\\app2",
        "preloadEnabled": false,
        "virtualDirectories": null
        }
      ]
    }
  },
  "resources": [
    {
      "type": "Microsoft.Web/sites/config",
      "name": "[concat(parameters('webAppName'), '/web')]",
      "apiVersion": "2020-06-01",
      "properties": {
          "virtualApplications": "[parameters('virtualApplications')]"
      }
    }
  ]
}
TEMPLATE
  depends_on          = [module.webapp["api"]]
}

Debug Output

Panic Output

Error: removing items provisioned by this Template Deployment: deleting Nested Resource "/subscriptions/000-000-000-000/resourceGroups/rg/providers/Microsoft.Web/sites/api/slots/staging/config/web": pollingTrackerBase#updateRawBody: failed to unmarshal response body: StatusCode=0 -- Original Error: invalid character '<' looking for beginning of value

Expected Behaviour

Actual Behaviour

Terraform should successfully destroy tainted resources and be able to recreate it on the next apply

Error thrown

Steps to Reproduce

  1. terraform taint module.region1.azurerm_resource_group_template_deployment.api_virtual_directory
  2. terraform apply

Important Factoids

Since I'm currently fighting a bug/issue with azurerm_resource_group_template_deployment not detecting drift, I tried tainting the object to recreate it entirely, but now I'm running into this problem.

References

ben-002 commented 3 years ago

Try to put delete_nested_items_during_deletion = false(part of features block) inside the provider block. Something like this:

provider "azurerm" {
...
  features {
    template_deployment {
      delete_nested_items_during_deletion = false
    }
  }
...
}

There is a note at the end of this documentation page with a bit more details of how destroy works with templates.

ajklotz commented 3 years ago

Try to put delete_nested_items_during_deletion = false(part of features block) inside the provider block. Something like this:

provider "azurerm" {
...
  features {
    template_deployment {
      delete_nested_items_during_deletion = false
    }
  }
...
}

There is a note at the end of this documentation page with a bit more details of how destroy works with templates.

That solution doesn't seem like it would work. The template deployment I'm using doesn't create nested resources. It is the only resource being created. Also, by indicating that I don't want to delete a resource, then it won't recreate it, which is the goal here.