我正在尝试在同一资源组中部署 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
. 所以我认为我无法改变这一点。