Skip to content

Instantly share code, notes, and snippets.

@straubt1
Created September 10, 2020 13:35
Show Gist options
  • Save straubt1/e8fd8716e1e9133884005cc6c7cac8e4 to your computer and use it in GitHub Desktop.
Save straubt1/e8fd8716e1e9133884005cc6c7cac8e4 to your computer and use it in GitHub Desktop.
Terraform 0.13 Variable Validation Rule
terraform {
required_version = "~> 0.13.0"
}
variable "environment_name" {
description = "The environment name."
type = string
validation {
condition = contains(["develop", "stage", "production"], var.environment_name)
error_message = "The environment_name value is not allowed. [\"develop\", \"stage\", \"production\"]."
}
}
# Notes:
# `condition` The condition for variable "environment_name" can only refer to the variable itself, using var.environment_name.
# `error_message` Validation error message must be at least one full English sentence starting with an uppercase letter and ending with a period or question mark.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment