Search code examples
azureterraformterraform-provider-azureazure-application-gateway

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.

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.


Solution

  • The issue was that under ssl_certificate, the name property was using a variable ssl_certificate_name which turned to be empty.

    Then, the error coming back from Azure was half correct; 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.

    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.

    Provider version was 3.37