0

我为 Azure LogicApp 创建了名为工作流的模块这是模块:

resource "azurerm_logic_app_workflow" "LogicApp" {
    name                             = "${var.LogicAppName}"
    location                         = "${var.LogicAppLocation}"
    resource_group_name = "${var.rgName}"
    workflow_schema         = "${var.schema}"
}

workflow_schema我指定包含 logicapp 配置的文件的路径

主要config.tf我有以下设置:

module "workflow" {
  source                     = "./modules/workflow/"
  LogicAppName       = "LaName"
  LogicAppLocation  = "${azurerm_resource_group.rg.location}"
  rgName                   = "${azurerm_resource_group.rg.name}"
  schema                   = "${file("./path/to/the/file/LaName")}"
}

所以,当我跑步时terraform initterraform plan一切都很好。

由于我的逻辑应用程序是较早创建的,因此我想导入它以便 terraform apply 不会覆盖它。

我正在运行以下命令,它返回错误:

terraform import module.workflow.azurerm_logic_app_workflow.LogicApp /subscriptions/mySubscriptionID/resourceGroups/myRgName/providers/Microsoft.Logic/workflows/LaName

Error: Import to non-existent module

module.workflow is not defined in the configuration. Please add configuration
for this module before importing into it.

我正在使用以下版本的软件:

Terraform v0.12.13
+ provider.azurerm v1.28.0

如果有人对terraform import失败的原因有任何想法,请分享。

4

1 回答 1

2

我看到命名的问题。您的模块已命名workflow,并且在您的配置中您也命名了资源workflow,这应该不同。您正在尝试直接导入资源。例子:

module "workflow-azure" {
  source                   = "./modules/workflow/"
  LogicAppName             = "LaName"
  LogicAppLocation         = "${azurerm_resource_group.rg.location}"
  rgName                   = "${azurerm_resource_group.rg.name}"
  schema                   = "${file("./path/to/the/file/LaName")}"
}

然后应该导入

terraform import module.workflow-azure.azurerm_logic_app_workflow.LogicApp /subscriptions/mySubscriptionID/resourceGroups/myRgName/providers/Microsoft.Logic/workflows/LaName
于 2020-05-22T15:13:56.433 回答