I am trying to set default values on my map(objects) variable in terraform but I am getting the following error when using my module:
The given value is not suitable for child module variable "virtual_servers"
│ defined at .terraform/modules/{module_name}/variables.tf:122,1-27: element
│ "{element_name}": attributes "client_profiles", "irules", "profiles",
│ "rev_zone", "server_profiles", and "source_address_translation" are
│ required.
My understanding is that I should be able to provide sensible defaults in my module and then override those defaults when calling the module.
Here is the code:
Module
variables.tf:
variable "virtual_servers" {
type = map(object({
port = number
fwd_zone = string
rev_zone = string
source_address_translation = string
irules = list(string)
profiles = list(string)
client_profiles = list(string)
server_profiles = list(string)
}))
default = {
default = {
port = 1
fwd_zone = "test"
rev_zone = "test"
source_address_translation = "test"
irules = null
profiles = null
client_profiles = null
server_profiles = null
}
}
}
main.tf
resource "virtual_server" "this" {
for_each = var.virtual_servers
port = each.value.port
source_address_translation = each.value.source_address_translation
irules = each.value.irules
profiles = each.value.profiles
client_profiles = each.value.client_profiles
server_profiles = each.value.server_profiles
}
Making use of the module
main.tf
module "module_name" {
source = "module_source"
virtual_servers_1 = {
"name" = {
port = 80
fwd_zone = "override"
}
"virtual_servers_2" = {
port = 80
fwd_zone = "override"
}
}
}
Can anyone point me in the direction of where I am going wrong?
EDIT: If I pass in all the values required to virtual_servers_1 and virtual_servers_2 it works. However I want to be able to supply default values.