Skip to content

Instantly share code, notes, and snippets.

@spettifer
Last active July 8, 2021 15:07
Show Gist options
  • Save spettifer/55dc46bad2f002f1c7def76814ccbd42 to your computer and use it in GitHub Desktop.
Save spettifer/55dc46bad2f002f1c7def76814ccbd42 to your computer and use it in GitHub Desktop.
Workaround for application insights instances created using Terraform AzureRM provider v1.x when upgrading to v2.0
# The application_type attribute is now case senstive. If the resource has been previously created with provider v1.x and the
# application_type was not lower case, then changing it to suit the v2 provider will result in the resource being destroyed
# and re-created since there is no way to update this value in place
# (see https://github.com/terraform-providers/terraform-provider-azurerm/issues/5902).
# To prevent this, add a lifecycle customisation and specify application_type as an attribute to ignore. Any attribute specified
# in the ignore_changes array will not be considered when creating a plan for an update, but they will still be part of creating
# a new resource.
resource "azurerm_application_insights" "appinsights" {
name = "${local.prefix}-appname"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
application_type = "web"
tags = local.tags
lifecycle {
ignore_changes = [
application_type
]
}
}
@andydkelly-ig
Copy link

thank you very much for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment