I am trying to add a subnet to my API management via Terraform but I get the following error. From what I understand, a VMSS resource from another resource group that is not mine is blocking me from adding an external subnet. I also tried to do it via portal but it didn't work either.
I also pasted my terraform resources below the error.
│ Error: creating/updating Service (Subscription: "my-sub-id" │ Resource Group Name: "abo-dev" │ Service Name: "abo-apim-dev"): polling after Update: polling failed: the Azure API returned the following error: │ │ Status: "UpdateApiServiceFailed" │ Code: "" │ Message: "Resource /subscriptions/1a789875-5d29-4ddb-8bf9-1e830ed9ade6/resourceGroups/ABO-APIM-DEV-ZRKABDTO94F9DOO4MNEBLJGXKCHOOXFA8ZGLH/providers/Microsoft.Compute/virtualMachineScaleSets/gwhost/updateGroups/d9cf4551-c830-4ae3-b372-3043713b104a/networkInterfaceConfigurations/gwhost-nic/ipConfigurations/gwhost-ipConfig cannot be created in or updated to use the subnet /subscriptions/my-sub-id/resourceGroups/abo-dev/providers/Microsoft.Network/virtualNetworks/abo-vnet-dev/subnets/abo-apim_subnet-dev since it has delegation(s) [Microsoft.ApiManagement/service: /subscriptions/my-sub-id/resourceGroups/abo-dev/providers/Microsoft.Network/virtualNetworks/abo-vnet-dev/subnets/abo-apim_subnet-dev/delegations/apiGatewayDelegation] to external services." │ Activity Id: "" │ │ --- │ │ API Response: │ │ ----[start]---- │ {"status":"Failed","error":{"code":"UpdateApiServiceFailed","message":"Resource /subscriptions/1a789875-5d29-4ddb-8bf9-1e830ed9ade6/resourceGroups/ABO-APIM-DEV-ZRKABDTO94F9DOO4MNEBLJGXKCHOOXFA8ZGLH/providers/Microsoft.Compute/virtualMachineScaleSets/gwhost/updateGroups/d9cf4551-c830-4ae3-b372-3043713b104a/networkInterfaceConfigurations/gwhost-nic/ipConfigurations/gwhost-ipConfig cannot be created in or updated to use the subnet /subscriptions/my-sub-id/resourceGroups/abo-dev/providers/Microsoft.Network/virtualNetworks/abo-vnet-dev/subnets/abo-apim_subnet-dev since it has delegation(s) [Microsoft.ApiManagement/service: /subscriptions/my-sub-id/resourceGroups/abo-dev/providers/Microsoft.Network/virtualNetworks/abo-vnet-dev/subnets/abo-apim_subnet-dev/delegations/apiGatewayDelegation] to external services."}} │ -----[end]----- │ │ │ with module.api_management.azurerm_api_management.api_mgmt, │ on modules/api_management/main.tf line 1, in resource "azurerm_api_management" "api_mgmt": │ 1: resource "azurerm_api_management" "api_mgmt" {
resource "azurerm_subnet" "apim_subnet" {
count = 1
name = "${var.client}-apim_subnet-${var.environment}"
resource_group_name = var.resource_group_name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = [cidrsubnet(var.cidr_vnet[0], 8, count.index + 1)]
delegation {
name = "apiGatewayDelegation"
service_delegation {
name = "Microsoft.ApiManagement/service"
actions = ["Microsoft.Network/virtualNetworks/subnets/join/action", "Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action"]
}
}
}
resource "azurerm_api_management" "api_mgmt" {
name = "${var.client}-apim-${var.environment}"
location = var.location
resource_group_name = var.resource_group_name
publisher_name = var.client
publisher_email = "******@ab.com"
sku_name = lookup(var.api_sku_sizes, var.environment, "Developer_1")
virtual_network_type= "External"
virtual_network_configuration {
subnet_id = var.new_apim_subnet_id
}
tags = {
client = var.client
environment = var.environment
source = "terraform"
}
}