Forked from karl-cardenas-coding/input-validation-example.tf
Created
May 29, 2020 15:29
-
-
Save nicerobot/6e3566cf9fce623d79c9a387240dbe03 to your computer and use it in GitHub Desktop.
input-validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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