Home > Enterprise >  What is the correct syntax for the subnet delegation block in azure/vnet/azurerm terraform module?
What is the correct syntax for the subnet delegation block in azure/vnet/azurerm terraform module?

Time:04-21

I want to deploy a Vnet to azure using the azure/vnet/azurerm Terraform module (https://registry.terraform.io/modules/Azure/vnet/azurerm/latest).

module "vnet" {
  source              = "Azure/vnet/azurerm"
  resource_group_name = "my-resources"
  address_space       = ["10.0.0.0/16"]
  subnet_prefixes     = ["10.0.1.0/24", "10.0.2.0/24"]
  subnet_names        = ["subnet1", "subnet2"]

  subnet_delegation = {
    subnet2 = {
      name    = "Microsoft.DBforPostgreSQL/flexibleServers"
      actions = "Microsoft.Network/virtualNetworks/subnets/join/action"
    }
  }
}

I wrote this code and when I want to "terraform plan" I get this error :

Error: Invalid function argument
│ 
│   on .terraform/modules/vnet/main.tf line 30, in resource "azurerm_subnet" "subnet":
│   30:         name    = lookup(delegation.value, "service_name")
│     ├────────────────
│     │ delegation.value is "Microsoft.Network/virtualNetworks/subnets/join/action"
│ 
│ Invalid value for "inputMap" parameter: lookup() requires a map as the first argument.


Error: Invalid function argument
│ 
│   on .terraform/modules/vnet/main.tf line 30, in resource "azurerm_subnet" "subnet":
│   30:         name    = lookup(delegation.value, "service_name")
│     ├────────────────
│     │ delegation.value is "Microsoft.DBforPostgreSQL/flexibleServers"
│ 
│ Invalid value for "inputMap" parameter: lookup() requires a map as the first argument.

Does someone have already used this module and used the subnet delegation ? I need the syntax of the "subnet_delegation" in order to avoid this error.

Thank You !

CodePudding user response:

Here's an example for that block, taken from here.

subnet_delegation = {
    subnet2 = {
      "Microsoft.Sql.managedInstances" = {
        service_name = "Microsoft.Sql/managedInstances"
        service_actions = [
          "Microsoft.Network/virtualNetworks/subnets/join/action",
          "Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action",
          "Microsoft.Network/virtualNetworks/subnets/unprepareNetworkPolicies/action",
        ]
      }
    }
  }

  • Related