Closed snooyen closed 5 months ago
Upon further inspection, we realized that the issue lies in our specified default values. Specifically:
variable "spotinst_ocean_vngs" {
type = map(object({
. . .
instance_types = optional(list(string), null)
instance_types_filters = optional(
. . .
exclude_metal = optional(bool, false)
. . .
default = {}
resulting in an incorrect evaluation of the for_each
statement inside the dynamic instance_types_filters
nested block.
Changing things to the following resulted in expected behavior:
# eks/spotinst-ocean-vng.tf
variable "spotinst_ocean_vngs" {
type = map(object({
. . .
instance_types = optional(list(string), null)
instance_types_filters = optional(
object({
categories = optional(list(string), null)
disk_types = optional(list(string), null)
exclude_families = optional(list(string), null)
exclude_metal = optional(bool, null)
hypervisor = optional(list(string), null)
include_families = optional(list(string), null)
is_ena_supported = optional(bool, null)
max_gpu = optional(number, null)
max_memory_gib = optional(number, null)
max_network_performance = optional(number, null)
max_vcpu = optional(number, null)
min_enis = optional(number, null)
min_gpu = optional(number, null)
min_memory_gib = optional(number, null)
min_network_performance = optional(number, null)
min_vcpu = optional(number, null)
root_device_types = optional(list(string), null)
virtualization_types = optional(list(string), null)
}), {})
. . .
}))
description = "List of objects defining a Spotinst Ocean Virtual Node Group for the cluster"
default = null
}
resource "spotinst_ocean_aws_launch_spec" "this" {
for_each = local.enabled ? var.spotinst_ocean_vngs : {}
. . .
instance_types = each.value.instance_types
dynamic "instance_types_filters" {
for_each = each.value.instance_types_filters != null ? [each.value.instance_types_filters] : []
content {
categories = instance_types_filters.value.categories
disk_types = instance_types_filters.value.disk_types
exclude_families = instance_types_filters.value.exclude_families
exclude_metal = instance_types_filters.value.exclude_metal
hypervisor = instance_types_filters.value.hypervisor
include_families = instance_types_filters.value.include_families
is_ena_supported = instance_types_filters.value.is_ena_supported
max_gpu = instance_types_filters.value.max_gpu
max_memory_gib = instance_types_filters.value.max_memory_gib
max_network_performance = instance_types_filters.value.max_network_performance
max_vcpu = instance_types_filters.value.max_vcpu
min_enis = instance_types_filters.value.min_enis
min_gpu = instance_types_filters.value.min_gpu
min_memory_gib = instance_types_filters.value.min_memory_gib
min_network_performance = instance_types_filters.value.min_network_performance
min_vcpu = instance_types_filters.value.min_vcpu
root_device_types = instance_types_filters.value.root_device_types
virtualization_types = instance_types_filters.value.virtualization_types
}
}
. . .
}
Terraform Version
Affected Resource(s)
Terraform Configuration Files
Debug Output
Here's an excerpt where we were trying to update the AMI for a specific VNG that was using
instance_types
attribute:Expected Behavior
instance_types_filters
nested block attribute.Actual Behavior
instance_types_filters
shown in planundefined -> SOME_DEFAULT
Steps to Reproduce
Important Factoids
instance_types_filters
instance_types
and theinstance_types_filters
attributes here is because we have our configurations wrapped up in a module which is consumed by different teams. Some VNGs want specific instance types while others are satisfied with filters.Community Note