hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.46k stars 4.54k forks source link

Error: updating Application Gatewa network.ApplicationGatewaysClient#CreateOrUpdate: Failure sending request #25852

Open amanpruthi opened 2 months ago

amanpruthi commented 2 months ago

Is there an existing issue for this?

Community Note

We have created dynamic private link configuration inside applicate gateway with flag private_link true then create private link configuration otherwise create simple applicate gateway

Terraform Version

1.7.4

AzureRM Provider Version

3.17

Affected Resource(s)/Data Source(s)

azurerm_application_gateway

Terraform Configuration Files

terraform {
  required_version = "~> 1.0"
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 3.17"
    }
  }
}

resource "azurerm_public_ip" "default" {
  name                = "public-ip"
  resource_group_name = var.resource_group.name
  location            = var.location
  sku                 = "Standard"
  allocation_method   = "Static"
  domain_name_label   = "public-ip"
}

locals {
  backend_address_pool_name      = "${var.network.name}-beap"
  frontend_port_name             = "${var.network.name}-feport"
  frontend_ip_configuration_name = "${var.network.name}-feip"
  gateway_ip_configuration_name  = "${var.network.name}-gwip"
  http_setting_name              = "${var.network.name}-be-htst"
  listener_name                  = "${var.network.name}-httplstn"
  request_routing_rule_name      = "${var.network.name}-rqrt"
  redirect_configuration_name    = "${var.network.name}-rdrcfg"
}

resource "azurerm_application_gateway" "default" {
  name                = "${var.namespace}-ag"
  resource_group_name = var.resource_group.name
  location            = var.location

  tags = var.tags

  sku {
    name = "Standard_v2"
    tier = "Standard_v2"
  }

  autoscale_configuration {
    min_capacity = 2
    max_capacity = 5
  }

  gateway_ip_configuration {
    name      = local.gateway_ip_configuration_name
    subnet_id = var.public_subnet.id
  }

  frontend_port {
    name = local.frontend_port_name
    port = 80
  }

  frontend_port {
    name = "https"
    port = 443
  }

  frontend_ip_configuration {
    name                 = local.frontend_ip_configuration_name
    public_ip_address_id = azurerm_public_ip.default.id
  }

  frontend_ip_configuration {
    name                            = "${local.frontend_ip_configuration_name}-private"
    subnet_id                       = var.public_subnet.id
    private_ip_address_allocation   = "Static"
    private_ip_address              = "10.10.0.10"
    private_link_configuration_name = var.private_link ? "${var.namespace}-private-link" : null
  }

  backend_address_pool {
    name = local.backend_address_pool_name
  }

  backend_http_settings {
    name                  = local.http_setting_name
    cookie_based_affinity = "Disabled"
    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
    priority                   = 1
  }

  dynamic "private_link_configuration" {
    for_each = var.private_link == true ? [1] : []
    content {
      name = "${var.namespace}-private-link"

      ip_configuration {
        name                          = "primary"
        subnet_id                     = var.private_subnet
        private_ip_address_allocation = "Dynamic"
        primary                       = true
      }
    }
  }
}

Debug Output/Panic Output

Error: updating Application Gateway: (Name "ag" / Resource Group "hdgsfsdc"): network.ApplicationGatewaysClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidResourceReference" Message="Resource /subscriptions/***/resourceGroups/providers/Microsoft.Network/applicationGateways/***/privateLinkConfigurations/private-link referenced by resource /subscriptions/***/resourceGroups/**/providers/Microsoft.Network/applicationGateways/**/frontendIPConfigurations/behdgsfsdc-vpc-feip-private was not found. Please make sure that the referenced resource exists, and that both resources are in the same region." Details=[]
│ 
│   with module.wandb.module.app_lb.azurerm_application_gateway.default,
│   on ../../modules/app_lb/main.tf line 22, in resource "azurerm_application_gateway" "default":
│   22: resource "azurerm_application_gateway" "default" {

Expected Behaviour

It should be create private link inside applicate gateway ... but got the error

Actual Behaviour

Updating Application Gateway: (Name "ag" / Resource Group "behdgsfsdc"): network.ApplicationGatewaysClient#CreateOrUpdate: Failure sending request: StatusCode=400

Steps to Reproduce

Terraform init Terraform plan Terraform apply

Important Factoids

No

References

No solution

Chambras commented 2 months ago

@amanpruthi those are really old versions of Terraform and azurerm. Have you tried with the latest ones? terraform 1.8.2 and azurerm 3.102.0?