Skip to content

Instantly share code, notes, and snippets.

@chanux

chanux/main.tf Secret

Created March 16, 2024 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chanux/8afa8c25bc198187eee892ab54063f3c to your computer and use it in GitHub Desktop.
Save chanux/8afa8c25bc198187eee892ab54063f3c to your computer and use it in GitHub Desktop.
Terraform: Typo in parameter name for object with two optionals
#---
# terraform plan -var complex='{one={name="jack", email="j@example.com", phon="121212"}}'
#
# This validation does not help catching typos because Terraform discards
# values not specified in the type, and without warning!
#
# https://github.com/hashicorp/terraform/issues/29204
#--
variable "complex" {
description = "Complex object with two optionals"
type = map(object({
email = optional(string)
phone = optional(string)
}))
validation {
condition = alltrue(
flatten([
for o in var.complex :
[for k in keys(o) : contains(["name", "email", "phone"], k)]
])
)
error_message = "Did you make a typo"
}
}
output "complex" {
value = var.complex
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment