Fix: update filters_config type to list(object({...})) for proper con… #156
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The current variable definition for filters_config in variables.tf is:
variable "filters_config" {
description = "List of content filter configs in content policy."
type = list(map(string))
default = null
}
This approach has several issues:
Overly generic type
list(map(string)) allows any arbitrary string key-value pairs but does not enforce a schema.
This makes the variable hard to validate and can cause runtime errors when module consumers pass unexpected keys or omit required ones.
No support for optional attributes
Terraform map(string) requires all keys to be strings and does not allow optional or structured fields.
For example, if i want input_modalities = ["TEXT", "IMAGE"], this will fail because map(string) cannot handle list(string) types.
Default value mismatch
Setting default = null for a list variable often leads to confusion and validation errors.
Terraform expects list variables to default to an empty list ([]) rather than null.
Solution
Replace the map(string) type with a strongly-typed object definition that reflects the actual expected schema:
variable "filters_config" {
description = "List of content filter configs in content policy."
type = list(object({
type = string
input_strength = string
output_strength = string
input_action = optional(string)
output_action = optional(string)
input_modalities = optional(list(string))
output_modalities = optional(list(string))
}))
default = []
}
this works
Strong typing: Enforces the exact structure of each content filter configuration.
Optional fields: Uses Terraform’s optional(...) feature to allow fields that are not always required.
Mixed types: Supports both string and list(string) fields, which map(string) cannot handle.
Safer default: Uses an empty list ([]) instead of null, preventing null-handling edge cases.