我正在尝试使用 terraform 创建 APIM 后端,但它总是给我这个错误:
module.apim_backends.azurerm_api_management_backend.mssdcontractingcommandsdev: Creating...
╷
│ Error: creating/updating Backend (Subscription: "e*******-ce34-****-****-0151ca9****4"
│ Resource Group Name: "**-**-**-devqa"
│ Service Name: "*******"
│ Backend: "mssdcontractingcommandsdev"): unexpected status 400 (400 Bad Request) with error: ValidationError: One or more fields contain incorrect values:
│
│ with module.apim_backends.azurerm_api_management_backend.mssdcontractingcommandsdev,
│ on ..\modules\apimgmt\backends\backends.tf line 1, in resource "azurerm_api_management_backend" "mssdcontractingcommandsdev":
│ 1: resource "azurerm_api_management_backend" "mssdcontractingcommandsdev" {
terraform中的代码(仅发送这部分,因为其他代码有效,并且所有变量都是正确的,我已经检查了多次):
resource "azurerm_api_management_backend" "mssdcontractingcommandsdev" {
name = format("%s%s", "mssdcontractingcommands", var.env)
description = format("%s%s", "mssdcontractingcommands", var.env)
api_management_name = var.apim_name
resource_group_name = var.resource_group_name
protocol = "http"
url = format("%s%s%s", "https://***", var.env, ".azurewebsites.net/api")
resource_id = var.contracting_commands_id
tls {
validate_certificate_chain = false
validate_certificate_name = false
}
}
地形计划:
+ resource "azurerm_api_management_backend" "mssdcontractingcommandsdev" {
+ api_management_name = "*****"
+ description = "***"
+ id = (known after apply)
+ name = "mssdcontractingcommandsdev"
+ protocol = "http"
+ resource_group_name = "rg-*****-*****-*****"
+ resource_id = "/subscriptions/e*******-ce34-****-****-0151ca9****4/resourceGroups/rg-*****-*****-devqa/providers/Microsoft.Web/sites/mssdcontractingcommandsdev"
+ url = "https://*******.azurewebsites.net"
+ tls {
+ validate_certificate_chain = false
+ validate_certificate_name = false
}
}
这个想法只是创建 APIM 后端,因为函数管道将通过 Swagger 创建其余部分,例如 API 和策略
<set-backend-service id="apim-generated-policy" backend-id="mssdcontractingcommandsdev" />
除此之外我没有尝试过很多事情,只是进行了一些搜索。
提供商:
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=3.107.0"
}
}
backend "azurerm" {
resource_group_name = "rg-*****-****-devqa"
storage_account_name = "state"
container_name = "tfstatedev"
key = "terraform.tfstate"
}
}
provider "azurerm" {
features {}
skip_provider_registration = true
}
我解决了这个问题,由于某种原因,我需要在函数应用程序 ID 之前添加
"https://management.azure.com"
。
resource "azurerm_api_management_backend" "mssdcontractingcommandsdev" {
name = format("%s%s", "mssdcontractingcommands", var.env)
description = format("%s%s", "mssdcontractingcommands", var.env)
api_management_name = var.apim_name
resource_group_name = var.resource_group_name
protocol = "http"
url = format("%s%s%s", "https://***", var.env, ".azurewebsites.net/api")
resource_id = format("%s%s", "https://management.azure.com", var.contracting_commands_id)
tls {
validate_certificate_chain = false
validate_certificate_name = false
}
}
我将在 github 上打开一个问题来了解这一点。
但是问题解决了。