Azure terraform import does not import all attributes in terraform state file after terraform provider version upgrade from 2.x to 3.x
I upgraded deprecated resource 'azurerm_function_app' to 'azurerm_linux_web_app' and 'azurerm_windows_function_app'. Removed resources from terraform state file with 'terraform state rm command' successfully. terraform import adds all attributes in portal but state file does not add some app setting attributes after terraform import and apply.
~ resource "azurerm_linux_web_app" "mcp-frontend" {
~ app_settings = {
+ "WEBSITE_VNET_ROUTE_ALL" = "1"
~ resource "azurerm_windows_function_app" "api" {
~ app_settings = {
+ "APPINSIGHTS_INSTRUMENTATIONKEY" = (sensitive)
+ "WEBSITE_VNET_ROUTE_ALL" = "1"
When Provider upgrades are made , they often introduce changes in behavior and attributes in the latest resources.
Code:
Check the terraform registry :
for azurerm_linux_web_app or azurerm_windows_function_app.
When we compare the attribute names and values in azurerm_function_app resource which is deprecated . Some values are changes and not necessary to provide or some values might be missed.
These values are imported automatically and So in the new configurations check which values are missed and its better to add imported resource if required using resource block to reflect changes.
terraform import azurerm_linux_web_app.name /subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/Microsoft.Web/sites/<function_app_name>
Add required attributes:
Reference: Azure Provider: Migrating to a renamed resource | Guides | hashicorp/azurerm | Terraform Registry