[英]Cannot create an Azure Application gateway using Terraform
I'm trying to create an instance of Application Gateway.我正在尝试创建一个应用程序网关实例。 While doing so, I get the following error:
这样做时,出现以下错误:
Error: creating Application Gateway: (Name "name-gateway-wgrkecswbk" / Resource Group "name03n62mct"):.network.ApplicationGatewaysClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidResourceName" Message="Resource name is invalid. The name can be up to 80 characters long. It must begin with a word character, and it must end with a word character or with '_'. The name may contain word characters or '.', '-', '_'." Details=[]
The name used is name-gateway-wgrkecswbk
which, looks to be a valid name according the error description.使用的名称是
name-gateway-wgrkecswbk
,根据错误描述,它看起来是一个有效名称。
The location used is使用的位置是
with module.name.module.gateway[0].azurerm_application_gateway.res,
on .terraform/modules/name/modules/gateway/main.tf line 20, in resource "azurerm_application_gateway" "name":
20: resource "azurerm_application_gateway" "name" {
Tried removed dashes and making it shorter, with the same results.尝试删除破折号并使其更短,结果相同。
The unicode character [ie, space] on the gateway name may cause a problem.网关名称上的 unicode 字符 [即空格]可能会导致问题。 I have repeated the procedure using the same application gateway name, " name-gateway-wgrkecswbk ."
我使用相同的应用程序网关名称“ name-gateway-wgrkecswbk ”重复了该过程。
below code reference from harshicop下面是来自harshicop的代码参考
main tf as follows:主要tf如下:
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "example" {
name = "**********"
location = "West Europe"
}
resource "azurerm_virtual_network" "example" {
name = "examples-network"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
address_space = ["10.254.0.0/16"]
}
resource "azurerm_subnet" "frontend" {
name = "frontend"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.254.0.0/24"]
}
resource "azurerm_subnet" "backend" {
name = "backend"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.254.2.0/24"]
}
resource "azurerm_public_ip" "example" {
name = "examples-pip"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
allocation_method = "Dynamic"
}
locals {
backend_address_pool_name = "${azurerm_virtual_network.example.name}-beap"
frontend_port_name = "${azurerm_virtual_network.example.name}-feport"
frontend_ip_configuration_name = "${azurerm_virtual_network.example.name}-feip"
http_setting_name = "${azurerm_virtual_network.example.name}-be-htst"
listener_name = "${azurerm_virtual_network.example.name}-httplstn"
request_routing_rule_name = "${azurerm_virtual_network.example.name}-rqrt"
redirect_configuration_name = "${azurerm_virtual_network.example.name}-rdrcfg"
}
resource "azurerm_application_gateway" "network" {
name = "name-gateway-wgrkecswbk"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
sku {
name = "Standard_Small"
tier = "Standard"
capacity = 2
}
gateway_ip_configuration {
name = "my-gateway-ip-configuration"
subnet_id = azurerm_subnet.frontend.id
}
frontend_port {
name = local.frontend_port_name
port = 80
}
frontend_ip_configuration {
name = local.frontend_ip_configuration_name
public_ip_address_id = azurerm_public_ip.example.id
}
backend_address_pool {
name = local.backend_address_pool_name
}
backend_http_settings {
name = local.http_setting_name
cookie_based_affinity = "Disabled"
path = "/path1/"
port = 80
protocol = "Http"
request_timeout = 60
}
http_listener {
name = local.listener_name
frontend_ip_configuration_name = local.frontend_ip_configuration_name
frontend_port_name = local.frontend_port_name
protocol = "Http"
}
request_routing_rule {
name = local.request_routing_rule_name
rule_type = "Basic"
http_listener_name = local.listener_name
backend_address_pool_name = local.backend_address_pool_name
backend_http_settings_name = local.http_setting_name
}
}
provide tf as follows:提供 tf 如下:
terraform {
required_version = "~>1.3.3"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">=3.5.0"
}
}
}
Output while running plan command运行计划命令时 Output
terraform plan
upon apply申请时
terraform apply -auto-approve
From Portal:从门户:
The issue was that under ssl_certificate
, the name
property was using a variable ssl_certificate_name
which turned to be empty
.问题是在
ssl_certificate
下, name
属性使用的变量ssl_certificate_name
变为empty
。
Then, the error coming back from Azure
was half correct;然后,从
Azure
返回的错误对了一半; It was an invalid name used, since it was an empty var, but not at the resource level ( azurerm_application_gateway.name
), instead it was at the inner block azurerm_application_gateway.name.ssl_certificate.name
level.这是一个使用的无效名称,因为它是一个空变量,但不是在资源级别 (
azurerm_application_gateway.name
),而是在内部块azurerm_application_gateway.name.ssl_certificate.name
级别。
Code:代码:
resource "azurerm_application_gateway" "name" {
//....
ssl_certificate {
// var contents were empty
name = var.ssl_certificate_name
}
}
Already reported this issue to Azure so hopefully it gets resolved soon.已将此问题报告给Azure ,希望它能尽快得到解决。
Provider version was 3.37
提供商版本为
3.37
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.