Hi everyone,
I have the following variable:
variable "aks_node_pools" {
type = map(object({
name = string
node_count = optional(number)
vm_size = string
capacity_reservation_group_id = optional(string)
}))
default = {}
description = "Additional nodepools to be created on XYZ cluster."
nullable = false
}
Basically a map of objects that represent nodepools (number of attributes cut down for example purposes). What is need to do with this is make sure I add a field called “vnet_subnet_id” to each object before I can use it.
I thought that with locals block and merge function I can do the job, but I’m not sure what I do is correct
locals {
# Store the field 'vnet_subnet_id' into an object then merge it with the nodepool object
subnet_aks = {
vnet_subnet_id = data.azurerm_subnet.aks.id
}
node_pools = { for nodepool in var.aks_node_pools : nodepool => merge(nodepool, local.subnet_aks) }
}
This gives me errors:
Error: Invalid object key
│
│ on main.tf line 46, in locals:
│ 46: node_pools = { for nodepool in var.aks_node_pools : nodepool => merge(nodepool, local.subnet_aks_elk) }
│
│ The key expression produced an invalid result: string required.
My intention as you can see was to make a for loop on each object in the map and merge it with the “object” which hold the field that I need to be added.
I’m guessing that this sounds good but maybe I’m on the wrong way to solve the problem. Do you have any ideas on this?