What could be causing missing app setting attributes in terraform state file after successful terraform import and apply?

huangapple go评论55阅读模式
英文:

What could be causing missing app setting attributes in terraform state file after successful terraform import and apply?

问题

Azure terraform import 在将 terraform 提供程序版本从 2.x 升级到 3.x 后,未导入 terraform 状态文件中的所有属性。

我将已弃用的资源 'azurerm_function_app' 升级为 'azurerm_linux_web_app' 和 'azurerm_windows_function_app'。
成功使用 'terraform state rm' 命令从 terraform 状态文件中移除了资源。
terraform import 在门户中添加了所有属性,但在 terraform 导入和应用后,状态文件未添加某些应用程序设置属性。

~ 资源 "azurerm_linux_web_app" "mcp-frontend" {
      ~ app_settings                       = {
          + "WEBSITE_VNET_ROUTE_ALL"                          = "1"
~ 资源 "azurerm_windows_function_app" "api" {
      ~ app_settings                       = {
          + "APPINSIGHTS_INSTRUMENTATIONKEY"     = (敏感)
          + "WEBSITE_VNET_ROUTE_ALL"             = "1"
英文:

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"

答案1

得分: 0

"When Provider upgrades are made , they often introduce changes in behavior and attributes in the latest resources."

Code:

resource "azurerm_function_app" "example" {
  name                       = "testazure-functions"
  location                   = data.azurerm_resource_group.example.location
  resource_group_name        = data.azurerm_resource_group.example.name
  app_service_plan_id         = azurerm_app_service_plan.example.id
  storage_connection_string   = azurerm_storage_account.example.primary_connection_string
}

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:

resource "azurerm_linux_web_app" "example" {
  name                = "examplehfhf"
  location            = data.azurerm_resource_group.example.location
  resource_group_name = data.azurerm_resource_group.example.name
  service_plan_id     = azurerm_service_plan.example.id  
  ...
  site_config {}
}

Reference: Azure Provider: Migrating to a renamed resource | Guides | hashicorp/azurerm | Terraform Registry

英文:

When Provider upgrades are made , they often introduce changes in behavior and attributes in the latest resources.

Code:

resource &quot;azurerm_function_app&quot; &quot;example&quot; {
  name                       = &quot;testazure-functions&quot;
 location              = data.azurerm_resource_group.example.location
  resource_group_name   = data.azurerm_resource_group.example.name
   app_service_plan_id       = azurerm_app_service_plan.example.id
  storage_connection_string = azurerm_storage_account.example.primary_connection_string
}

What could be causing missing app setting attributes in terraform state file after successful terraform import and apply?

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.

What could be causing missing app setting attributes in terraform state file after successful terraform import and apply?

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/&lt;subscription_id&gt;/resourceGroups/&lt;resource_group_name&gt;/providers/Microsoft.Web/sites/&lt;function_app_name&gt;

Add required attributes:

resource &quot;azurerm_linux_web_app&quot; &quot;example&quot; {
  name                = &quot;examplehfhf&quot;
  location              = data.azurerm_resource_group.example.location
  resource_group_name   = data.azurerm_resource_group.example.name
  service_plan_id     = azurerm_service_plan.example.id  
   …
  site_config {}
}

What could be causing missing app setting attributes in terraform state file after successful terraform import and apply?

Reference: Azure Provider: Migrating to a renamed resource | Guides | hashicorp/azurerm | Terraform Registry

huangapple
  • 本文由 发表于 2023年5月22日 13:28:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76303253.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定