Skip to content

Fix strict vs non-strict default value - main.tf#110

Open
k0eff wants to merge 1 commit intocastai:mainfrom
k0eff:bedegaming-tf-cast-fix
Open

Fix strict vs non-strict default value - main.tf#110
k0eff wants to merge 1 commit intocastai:mainfrom
k0eff:bedegaming-tf-cast-fix

Conversation

@k0eff
Copy link
Copy Markdown

@k0eff k0eff commented Jul 11, 2025

I believe the errors below are due to using lookup() which doesn't expect a different datatype.
A quick fix would be to use try() instead which could work with the currently given defaults such as []. A more proper fix might be desired on the long run though

example data being passed:

# Custom implementation passing the following values to cast.ai's castai/aks/castai=8.0.3
      + PlatformApi        = {
          + configuration_id = "<<redacted>>"
          + constraints      = {
              + fallback_restore_rate_seconds                 = "1800"
              + on_demand                                     = "false"
              + spot                                          = "true"
              + spot_interruption_predictions_type            = "interruption-predictions"
              + spot_reliability_enabled                      = "true"
              + spot_reliability_price_increase_limit_percent = "20"
              + use_spot_fallbacks                            = "true"
            }
          + custom_labels    = {
              + "platform.api" = "true"
            }
          + should_taint     = false
        }
# the node template outputted from cast.ai's castai/aks/castai=8.0.3
{
      + cluster_id                                    = "<<redacted>>"
      + configuration_id                              = "<<redacted>>"
      + constraints                                   = [
          + {
              + architecture_priority                         = []
              + architectures                                 = [
                  + "amd64",
                ]
              + azs                                           = []
              + bare_metal                                    = "unspecified"
              + burstable_instances                           = ""
              + compute_optimized                             = false
              + compute_optimized_state                       = ""
              + cpu_manufacturers                             = []
              + custom_priority                               = []
              + customer_specific                             = ""
              + dedicated_node_affinity                       = []
              + enable_spot_diversity                         = false
              + fallback_restore_rate_seconds                 = 1800
              + gpu                                           = []
              + instance_families                             = []
              + is_gpu_only                                   = false
              + max_cpu                                       = 0
              + max_memory                                    = 0
              + min_cpu                                       = 0
              + min_memory                                    = 0
              + on_demand                                     = false
              + os                                            = [
                  + "linux",
                ]
              + resource_limits                               = [
                  + {
                      + cpu_limit_enabled   = false
                      + cpu_limit_max_cores = 0
                    },
                ]
              + spot                                          = true
              + spot_diversity_price_increase_limit_percent   = null
              + spot_interruption_predictions_enabled         = false
              + spot_interruption_predictions_type            = "interruption-predictions"
              + spot_reliability_enabled                      = true
              + spot_reliability_price_increase_limit_percent = 20
              + storage_optimized                             = false
              + storage_optimized_state                       = ""
              + use_spot_fallbacks                            = true
            },
        ]
      + custom_instances_enabled                      = false
      + custom_instances_with_extended_memory_enabled = false
      + custom_labels                                 = {
          + "platform.api" = "true"
        }
      + custom_taints                                 = []
      + gpu                                           = [
          + {
              + default_shared_clients_per_gpu = 0
              + enable_time_sharing            = false
              + sharing_configuration          = []
            },
        ]
      + id                                            = "PlatformApi"
      + is_default                                    = false
      + is_enabled                                    = true
      + name                                          = "PlatformApi"
      + rebalancing_config_min_nodes                  = 0
      + should_taint                                  = false
      + timeouts                                      = null
    }

the following errors are generated:

│ Error: Invalid function argument
│ 
│   on .terraform/modules/mod_castai.connected/main.tf line 170, in resource "castai_node_template" "this":
│  170:         for_each = [for instance_families in flatten([lookup(constraints.value, "instance_families", [])]) : instance_families if instance_families != null]
│ 
│ Invalid value for "default" parameter: the default value must have the same
│ type as the map elements.
╵
╷
│ Error: Invalid function argument
│ 
│   on .terraform/modules/mod_castai.connected/main.tf line 179, in resource "castai_node_template" "this":
│  179:         for_each = [for custom_priority in flatten([lookup(constraints.value, "custom_priority", [])]) : custom_priority if custom_priority != null]
│ 
│ Invalid value for "default" parameter: the default value must have the same
│ type as the map elements.
╵
╷
│ Error: Invalid function argument
│ 
│   on .terraform/modules/mod_castai.connected/main.tf line 189, in resource "castai_node_template" "this":
│  189:         for_each = [for gpu in flatten([lookup(constraints.value, "gpu", [])]) : gpu if gpu != null]
│ 
│ Invalid value for "default" parameter: the default value must have the same
│ type as the map elements.
╵
╷
│ Error: Invalid function argument
│ 
│   on .terraform/modules/mod_castai.connected/main.tf line 201, in resource "castai_node_template" "this":
│  201:         for_each = [for resource_limits in flatten([lookup(constraints.value, "resource_limits", [])]) : resource_limits if resource_limits != null]
│ 
│ Invalid value for "default" parameter: the default value must have the same
│ type as the map elements.
╵

@k0eff k0eff requested a review from a team as a code owner July 11, 2025 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant