Skip to content

Conversation

ramiloutfi
Copy link

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.

@ramiloutfi
Copy link
Author

/do-e2e-tests

Copy link

You are not authorized to run end to end tests

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