Skip to content

Instantly share code, notes, and snippets.

@soerenmartius
Created June 9, 2020 14:40
Show Gist options
  • Select an option

  • Save soerenmartius/e5f5e28b0de1ab45c9d20eef3b9c722c to your computer and use it in GitHub Desktop.

Select an option

Save soerenmartius/e5f5e28b0de1ab45c9d20eef3b9c722c to your computer and use it in GitHub Desktop.
Terraform Custom Validation Rule Examples
## Custom Validation Rule Examples
variable "alias_attributes" {
type = set(string)
description = "(Optional) Attributes supported as an alias for this user pool. Possible values: 'phone_number', 'email', or 'preferred_username'."
default = [
"email",
"preferred_username",
]
validation {
condition = can([for a in var.alias_attributes : regex("^(phone_number|email|preferred_username)$", a)])
error_message = "The alias_attributes value must be a list with one or multiple of the following possible values: 'phone_number', 'email', or 'preferred_username'."
}
}
variable "auto_verified_attributes" {
type = set(string)
description = "(Optional) The attributes to be auto-verified. Possible values: 'email', 'phone_number'."
default = [
"email"
]
validation {
condition = can([for a in var.auto_verified_attributes : regex("^(phone_number|email)$", a)])
error_message = "The auto_verified_attributes value must be a list with one or multiple of the following possible values: 'phone_number', 'email'."
}
}
variable "email_message" {
type = string
description = "(Optional) The email message template. Must contain the {####} placeholder."
default = "Your verification code is {####}."
validation {
condition = length(regexall("{####}", var.email_message)) > 0
error_message = "The message must contain the {####} placeholder, which will be replaced with the verification code."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment