Azure Terraform CLI获取错误:ID缺少'slots'元素
我正在windows上执行Azure Terraform CLI获取错误:ID缺少'slots'元素,azure,runtime-error,terraform,azure-web-app-service,terraform-provider-azure,Azure,Runtime Error,Terraform,Azure Web App Service,Terraform Provider Azure,我正在windows上执行terraform.exe apply,并收到错误: azurerm_subnet.subnet: Refreshing state... [id=<...>] azurerm_app_service_plan.service_plan: Refreshing state... [id=<...>] azurerm_app_service.app: Refreshing state... [id=<...>] azurerm_app_
terraform.exe apply
,并收到错误:
azurerm_subnet.subnet: Refreshing state... [id=<...>]
azurerm_app_service_plan.service_plan: Refreshing state... [id=<...>]
azurerm_app_service.app: Refreshing state... [id=<...>]
azurerm_app_service_virtual_network_swift_connection.test: Refreshing state... [id=<...>]
azurerm_app_service_slot.production: Refreshing state... [id=<...>]
azurerm_app_service_slot.staging: Refreshing state... [id=<...>]
Error: ID was missing the `slots` element
azurerm\u subnet.subnet:正在刷新状态。。。[id=]
azurerm\ u应用程序\服务\计划。服务\计划:正在刷新状态。。。[id=]
azurerm_app_service.app:正在刷新状态。。。[id=]
azurerm\应用程序\服务\虚拟\网络\快速\连接。测试:正在刷新状态。。。[id=]
azurerm_应用程序_服务_插槽。生产:正在刷新状态。。。[id=]
azurerm\u应用程序\u服务\u插槽。暂存:正在刷新状态。。。[id=]
错误:ID缺少'slots'元素
我正在尝试用terraform构建一个具有不同插槽和docker图像的Azure WebApp。它应该基于Dockerfile映像部署一个具有不同插槽的Azure WebApp
第一次运行没有错误。我在刷新资源时收到错误
我使用的是azurerm提供程序版本2.1.0和azurerm后端
请参见以下地形文件:
terraform {
backend "azurerm" {
resource_group_name = "..."
storage_account_name = "..."
container_name = "..."
key = "..."
subscription_id = "..."
tenant_id = "..."
sas_token = "...."
}
}
provider "azurerm" {
version = "~>2.1.0"
features {}
}
variable "environment" {
default = "production"
}
variable "resource_group" {}
variable "location" {
default = "West Europe"
}
variable "app_name" {}
variable "network" {}
variable "subnet_prefix" {}
resource "azurerm_app_service_plan" "service_plan" {
name = var.app_name
location = var.location
resource_group_name = var.resource_group
kind = "Linux"
reserved = true
sku {
tier = "Standard"
size = "S1"
}
tags = {
Environment = var.environment
Cost = "€0,081/Stunde"
}
}
resource "azurerm_app_service" "app" {
name = var.app_name
location = var.location
resource_group_name = var.resource_group
app_service_plan_id = azurerm_app_service_plan.service_plan.id
depends_on = [azurerm_app_service_plan.service_plan]
site_config {
linux_fx_version = "DOCKER|<...>.azurecr.io/<...>:0.0.1-95"
always_on = "true"
}
app_settings = {
...
}
storage_account {
access_key = "..."
account_name = "..."
name = "certs"
share_name = "certs"
type = "AzureBlob"
mount_path = "/var/certs"
}
tags = {
Environment = var.environment
}
}
resource "azurerm_app_service_slot" "production" {
name = var.app_name
app_service_name = azurerm_app_service.app.name
location = azurerm_app_service.app.location
resource_group_name = var.resource_group
app_service_plan_id = azurerm_app_service_plan.service_plan.id
depends_on = [azurerm_app_service.app]
site_config {
linux_fx_version = "DOCKER|<...>.azurecr.io/<...>:0.0.1-95"
always_on = "true"
}
app_settings = {
"SOME_KEY" = "some-value"
}
}
resource "azurerm_app_service_slot" "staging" {
name = "staging"
app_service_name = azurerm_app_service.app.name
location = azurerm_app_service.app.location
resource_group_name = var.resource_group
app_service_plan_id = azurerm_app_service_plan.service_plan.id
depends_on = [azurerm_app_service.app]
site_config {
linux_fx_version = "DOCKER|<...>.azurecr.io/<...>:latest"
always_on = "true"
}
}
resource "azurerm_subnet" "subnet" {
name = var.app_name
resource_group_name = var.resource_group
virtual_network_name = var.network
address_prefix = var.subnet_prefix
delegation {
name = var.app_name
service_delegation {
name = "Microsoft.Web/serverFarms"
actions = [
"Microsoft.Network/networkinterfaces/*",
"Microsoft.Network/virtualNetworks/subnets/action",
"Microsoft.Network/virtualNetworks/subnets/join/action",
"Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action",
"Microsoft.Network/virtualNetworks/subnets/unprepareNetworkPolicies/action"
]
}
}
}
resource "azurerm_app_service_virtual_network_swift_connection" "test" {
app_service_id = azurerm_app_service.app.id
subnet_id = azurerm_subnet.subnet.id
depends_on = [
azurerm_app_service.app,
azurerm_subnet.subnet
]
}
地形{
后端“azurerm”{
资源组名称=“…”
存储帐户名称=“…”
容器名称=“…”
key=“…”
订阅_id=“…”
租户_id=“…”
sas_令牌=“…”
}
}
提供程序“azurerm”{
version=“~>2.1.0”
特征{}
}
可变“环境”{
default=“生产”
}
变量“资源组”{}
可变“位置”{
default=“西欧”
}
变量“app_name”{}
变量“网络”{}
变量“子网前缀”{}
资源“azurerm应用程序服务计划”“服务计划”{
name=var.app\u name
位置=变量位置
资源组名称=变量资源组
kind=“Linux”
保留=真
sku{
tier=“标准”
size=“S1”
}
标签={
环境=var.Environment
成本=“0081欧元/眩晕”
}
}
资源“azurerm_应用程序_服务”“应用程序”{
name=var.app\u name
位置=变量位置
资源组名称=变量资源组
app\u service\u plan\u id=azurerm\u app\u service\u plan.id
取决于=[azurerm\应用程序\服务\计划。服务\计划]
站点配置{
linux_fx_version=“DOCKER |.azurecr.io/:0.0.1-95”
始终\u on=“true”
}
应用程序设置={
...
}
储存帐户{
access_key=“…”
帐户名称=“…”
name=“证书”
共享\u name=“证书”
type=“AzureBlob”
mount_path=“/var/certs”
}
标签={
环境=var.Environment
}
}
资源“azurerm\u应用程序\u服务\u插槽”“生产”{
name=var.app\u name
app\u service\u name=azurerm\u app\u service.app.name
location=azurerm\u app\u service.app.location
资源组名称=变量资源组
app\u service\u plan\u id=azurerm\u app\u service\u plan.id
取决于=[azurerm\u app\u service.app]
站点配置{
linux_fx_version=“DOCKER |.azurecr.io/:0.0.1-95”
始终\u on=“true”
}
应用程序设置={
“SOME_KEY”=“SOME value”
}
}
资源“azurerm\u应用程序\u服务\u插槽”“暂存”{
name=“登台”
app\u service\u name=azurerm\u app\u service.app.name
location=azurerm\u app\u service.app.location
资源组名称=变量资源组
app\u service\u plan\u id=azurerm\u app\u service\u plan.id
取决于=[azurerm\u app\u service.app]
站点配置{
linux_fx_version=“DOCKER |.azurecr.io/:最新版本”
始终\u on=“true”
}
}
资源“azurerm_子网”“子网”{
name=var.app\u name
资源组名称=变量资源组
虚拟网络名称=变量网络
地址\前缀=变量子网\前缀
授权{
name=var.app\u name
服务代表团{
name=“Microsoft.Web/serverFarms”
行动=[
“Microsoft.Network/networkinterfaces/*”,
“Microsoft.Network/virtualNetworks/subnets/action”,
“Microsoft.Network/virtualNetworks/subnets/join/action”,
“Microsoft.Network/virtualNetworks/subnets/PrepareNetworkPolicys/action”,
“Microsoft.Network/virtualNetworks/subnets/UnprepareNetworkPolicys/action”
]
}
}
}
资源“azurerm\应用程序\服务\虚拟\网络\快速\连接”“测试”{
app\u service\u id=azurerm\u app\u service.app.id
子网\u id=azurerm\u子网.subnet.id
取决于[
azurerm_app_service.app,
azurerm_subnet.subnet
]
}
缺少插槽元素在这种情况下意味着什么?请共享整个地形代码。您还应该编辑问题,以包含完整的错误输出,包括显示错误来源的周围环境。是否每次都可以复制此问题?为了缩小此问题的范围,如果在terraform init、plan、apply时删除
资源“azurerm\u app\u service\u插槽”
,此问题是否仍然出现?配置文件看起来是正确的。我对该提供程序不太熟悉,无法确切说明这里发生了什么,但此错误似乎来自并似乎意味着其中一个资源实例应该具有包含/slots/…
部分的id。我会运行terraformshow
,然后查看每个实例的id
,看看它们是否看起来很奇怪。