简体   繁体   English

无法使用 Terraform 创建 Azure 应用程序网关

[英]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.

相关问题 Azure 应用网关 terraform - Azure application Gateway terraform 尝试使用 azure terraform 在应用程序网关上附加 SSL 证书 - Trying to attach SSL certificate on application gateway using azure terraform 应用程序网关的两个前端端口使用相同的端口 443 - terraform 中的应用程序网关 Azure - two frontend ports of application gateway are using the same port 443 - Azure application gateway in terraform 将SSL证书附加到Terraform中的Azure应用程序网关 - Attaching SSL certificate to Azure application gateway in Terraform 应用程序网关和 API 管理的 InternalServerError - Azure/Terraform - InternalServerError for Application Gateway and API Management - Azure/Terraform 无法通过 terraform 使用 oauth 创建 azure 广告应用程序 - Cannot create azure ad application with oauth via terraform Terraform-Azure-无法为应用程序网关 StandardV2 创建私有 IP 配置 - Terraform-Azure-Unable to create Private IP configuration for application Gateway StandardV2 使用 terraform 创建 azure 企业应用程序 - create azure enterprise application with terraform 如何使用python SDK创建Azure应用程序网关 - How to create Azure Application gateway using python SDK Terraform Azure 应用程序网关无法与密钥保管库中的证书关联 - Terraform Azure Application Gateway unable to associate with certificate in key vault
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM