英文:
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 "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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论