【发布时间】:2021-08-15 04:52:10
【问题描述】:
我正在使用 terraform 云工作区。 错误地,我将错误的 terraform 状态上传到我的工作区。现在我的 terraform plan 正在使用它,但我不想使用它,因为那不是我想要的状态。
让我用这张图片解释一下:我想使用 10 个月前的状态,而不是我最近得到的新状态:
我想回到我的旧状态,因为在新状态中没有一些资源,然后它们正在我的 terraform 计划中重新创建。
我正在尝试通过以这种方式执行terraform import <RESOURCE-INSTANCE> <ID> 命令来导入每个单独的资源:
terraform import azurerm_app_service_plan.fem-plan /subscriptions/d37e88d5-e443-4285-98c9-91bf40d514f9/resourceGroups/rhd-spec-prod-rhdhv-1mo5mz5r2o4f6/providers/Microsoft.Web/serverfarms/fem-plan-afd1
Acquiring state lock. This may take a few moments...
azurerm_app_service_plan.fem-plan: Importing from ID "/subscriptions/d37e88d5-e443-4285-98c9-91bf40d514f9/resourceGroups/rhd-spec-prod-rhdhv-1mo5mz5r2o4f6/providers/Microsoft.Web/serverfarms/fem-plan-afd1"...
azurerm_app_service_plan.fem-plan: Import prepared!
Prepared azurerm_app_service_plan for import
azurerm_app_service_plan.fem-plan: Refreshing state... [id=/subscriptions/d37e88d5-e443-4285-98c9-91bf40d514f9/resourceGroups/rhd-spec-prod-rhdhv-1mo5mz5r2o4f6/providers/Microsoft.Web/serverfarms/fem-plan-afd1]
Error: Cannot import non-existent remote object
While attempting to import an existing object to
azurerm_app_service_plan.fem-plan, the provider detected that no object exists
with the given id. Only pre-existing objects can be imported; check that the
id is correct and that it is associated with the provider's configured region
or endpoint, or use "terraform apply" to create a new remote object for this
resource.
Releasing state lock. This may take a few moments...
但我得到了输出,该资源不存在,因为 terraform 正在使用我最新的 新状态,其中不包括该资源。
如何使用 10 个月前的旧状态?
如果有人能指出我正确的道路,我将不胜感激。
【问题讨论】:
-
这些步骤会有帮助吗? support.hashicorp.com/hc/en-us/articles/…
-
关于这个问题的任何更新?它解决了你的问题吗?
-
@CharlesXu 上面Adil-B提供的支持文章解决了这个问题。
标签: terraform terraform-provider-azure