【问题标题】:Error: azurerm_app_service.ci_rg: resource repeated multiple times错误:azurerm_app_service.ci_rg:资源重复多次
【发布时间】:2019-04-18 20:43:09
【问题描述】:

我正在尝试在同一资源组中部署 2 个不同的 Azure 应用。

这些 Azure 应用程序被定义为存储在 Azure 容器注册表中的 docker 镜像(我之前在其中推送了这些 docker 镜像)。

我无法同时部署它们,因为我认为我定义它们的方式有问题,因为 Terraform 预计只能找到一个 azurerm_app_service,但我不确定我该怎么做解决这个问题?

当我运行此命令时:terraform plan -var-file test.tfvars,然后我在输出中看到此消息:

Error: azurerm_app_service.ci_rg: resource repeated multiple times

如何定义“2个相同类型的不同资源”?

这是main.tf 文件的内容(我将variables.tf 中定义的变量注入test.tfvars 中定义的值):

// the resource group definition
resource "azurerm_resource_group" "ci_rg" {
  name = "${var.resource_group_name}"
  location = "${var.azure_location}"
}

// the app service plan definition
resource "azurerm_app_service_plan" "ci_rg" {
  name                = "${var.app_service_plan}"
  location            = "${azurerm_resource_group.ci_rg.location}"
  resource_group_name = "${azurerm_resource_group.ci_rg.name}"
  kind                = "Linux"

  sku {
    tier = "Standard"
    size = "S1"
    capacity = 2 // for both the docker containers
  }

  properties {
    reserved = true
  }
}

// the first azure app
resource "azurerm_app_service" "ci_rg" {
  name                = "${var.first_app_name}"
  location            = "${azurerm_resource_group.ci_rg.location}"
  resource_group_name = "${azurerm_resource_group.ci_rg.name}"
  app_service_plan_id = "${azurerm_app_service_plan.ci_rg.id}"

  site_config {
    linux_fx_version = "DOCKER|${var.first_app_docker_image_name}"
  }

  app_settings {
      "CONF_ENV" = "${var.conf_env}"

      "DOCKER_REGISTRY_SERVER_URL"      = "${var.docker_registry_url}",
      "DOCKER_REGISTRY_SERVER_USERNAME" = "${var.docker_registry_username}",
      "DOCKER_REGISTRY_SERVER_PASSWORD" = "${var.docker_registry_password}",
  }
}

// the second azure app
resource "azurerm_app_service" "ci_rg" {
  name                = "${var.second_app_name}"
  location            = "${azurerm_resource_group.ci_rg.location}"
  resource_group_name = "${azurerm_resource_group.ci_rg.name}"
  app_service_plan_id = "${azurerm_app_service_plan.ci_rg.id}"

  site_config {
    linux_fx_version = "DOCKER|${var.second_app_docker_image_name}"
  }

  app_settings {
      "CONF_ENV" = "${var.conf_env}"

      "DOCKER_REGISTRY_SERVER_URL"      = "${var.docker_registry_url}",
      "DOCKER_REGISTRY_SERVER_USERNAME" = "${var.docker_registry_username}",
      "DOCKER_REGISTRY_SERVER_PASSWORD" = "${var.docker_registry_password}",
  }
}

编辑:

我不完全确定 Terraform 的工作原理,但我认为标签 azurerm_app_service 是由“Terraform 的语法”采用的。在此处查看文档:https://www.terraform.io/docs/providers/azurerm/r/app_service.html 标题是azurerm_app_service。所以我认为我无法改变这一点。

【问题讨论】:

    标签: azure-web-app-service terraform terraform-provider-azure azure-container-registry terraform-template-file


    【解决方案1】:

    我的猜测是您需要将第二个重命名为其他名称。像这样:resource "azurerm_app_service" "ci_rg_second"。它显然不喜欢它具有相同名称的事实。

    【讨论】:

    • 谢谢,试过了,Terraform 部署资源没有错误,但是现在 Azure 需要很长时间才能让这些 docker 容器运行
    • 这是一个完全不同的问题。我建议你接受这个答案并开始一个新问题
    • 我知道这一点,我只是想提供一些早期反馈。我将等到我在 Azure Web Portal 中看到正在运行的容器的日志,所以我确信这件事会按我的预期进行。谢谢
    • 有趣的事实:启动和运行这些应用程序所需的时间有相当大的波动,门户中的日志并不总是显示,无论如何我要发送一些向 Slack 频道发送消息以监控 docker 容器何时启动以及何时执行特定任务,例如以计划的方式运行 SQL 查询。似乎容器随机死亡,然后它们以随机方式挂起一段时间(一个行为与另一个不同,都是随机方式),并且“数据库计划”不太正确。无论如何,正如您所说,这些是其他问题。再次感谢您的回答。
    猜你喜欢
    • 2014-04-06
    • 1970-01-01
    • 2015-06-13
    • 1970-01-01
    • 1970-01-01
    • 2017-04-18
    • 1970-01-01
    • 1970-01-01
    • 2013-11-25
    相关资源
    最近更新 更多