Skip to content

Instantly share code, notes, and snippets.

@karl-cardenas-coding
Last active May 29, 2020 15:29
Show Gist options
  • Save karl-cardenas-coding/4d89c6ed42efeb4803483e55256fe5e6 to your computer and use it in GitHub Desktop.
Save karl-cardenas-coding/4d89c6ed42efeb4803483e55256fe5e6 to your computer and use it in GitHub Desktop.
input-validation
### Test scenario for "can"
variable "word-length" {
validation {
# The condition here identifies if the integer if greater than 1
condition = var.word-length > 1
error_message = "The variable is not greater than 5. Word length has to be at a minimum > 1."
}
}
variable "os" {
validation {
# The condition here identifies if the variable contains the string "linxu" OR "windows".
condition = can(regex("linux|windows", var.os))
error_message = "ERROR: Operating System must be Windows OR Linux."
}
}
resource "random_pet" "pet" {
length = var.word-length
keepers = {
pet-name = timestamp()
}
}
output "pet" {
value = "${random_pet.pet.id}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment