我正在尝试在同一资源组中部署2个不同的Azure应用。
这些Azure应用被定义为存储在Azure容器注册表中的docker映像(我之前在其中推送了这些docker映像)。
我无法同时部署它们两者,因为我认为定义它们的方式有误,因为Terraform期望只找到一个git init
,但是我不确定如何我可以解决这个问题吗?
当我运行以下命令:azurerm_app_service
时,我会在输出中看到此消息:
terraform plan -var-file test.tfvars
如何定义“ 2个相同类型的不同资源”?
这是Error: azurerm_app_service.ci_rg: resource repeated multiple times
文件的内容(我在其中注入了main.tf
中定义的变量和variables.tf
中定义的值)
test.tfvars
编辑:
我不太确定Terraform的工作原理,但是我认为标签// 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的语法”所采用的。在此处查看文档:{{3}}
标题为azurerm_app_service
。所以我认为我无法改变。
答案 0 :(得分:1)
我的猜测是您需要将第二个重命名为其他名称。像这样:resource "azurerm_app_service" "ci_rg_second"
。它显然不喜欢它具有相同名称的事实。