【问题标题】:Removing last record terraform state in a terraform workspace删除 terraform 工作区中的最后一条记录 terraform 状态
【发布时间】: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 个月前的旧状态?

如果有人能指出我正确的道路,我将不胜感激。

【问题讨论】:

标签: terraform terraform-provider-azure


【解决方案1】:

也许您可以使用命令terraform refresh 来更新状态文件以匹配资源的当前状态。可以获取命令here的详细信息。

【讨论】:

    猜你喜欢
    • 2019-11-14
    • 2019-04-29
    • 2020-08-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-02
    • 1970-01-01
    • 2018-10-03
    • 2021-07-02
    相关资源
    最近更新 更多