如何让 terraform 自动导入所有“已存在”资源?

All*_* Xu 7 azure terraform terraform-provider-azure

当我运行时,terraform apply -auto-approve出现以下错误:

Error: A resource with the ID "/subscriptions/.../resourceGroups/RG-SCUSTFStorage" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_resource_group" for more information.
Run Code Online (Sandbox Code Playgroud)

我知道我需要运行才能terraform import将资源导入到我的工作空间中。问题是我需要一次指定所有缺失资源的资源 ID。

有没有办法terraform import自动导入所有“已存在”资源,而无需一次输入一个资源 ID?

小智 2

如果您希望导入 Azure 资源,那么aztfy是推荐的工具,因为它本身就来自 Azure。

它确实会生成 terraform 代码,此外,它还有一个功能,您可以导入 azure 资源组,它会自动导入并生成资源组所持有的资源的配置。更不用说,该工具为您提供了良好的基于​​终端的 UI 体验。

对于其他超大规模企业,有两种选择。

  • terracognita:也可以根据他们的文档生成模块。
  • terraformer:由 Google 人员开发,但不是官方产品。