Skip to content

Instantly share code, notes, and snippets.

@guillermo-musumeci
Created October 6, 2022 21:08
Show Gist options
  • Select an option

  • Save guillermo-musumeci/1953fa6a394ce1f45efaeab2b3b10646 to your computer and use it in GitHub Desktop.

Select an option

Save guillermo-musumeci/1953fa6a394ce1f45efaeab2b3b10646 to your computer and use it in GitHub Desktop.
Variable Validation in Terraform
variable "storage_account_name" {
type = string
description = "Azure Storage Account Name (3 to 24 characters, lowercase letters and numbers only)"
validation {
condition = length(var.storage_account_name) >= 3 && length(var.storage_account_name) <= 24
error_message = "The storage_account_name variable name must be 3-24 characters in length"
}
validation {
condition = can(regex("^[0-9A-Za-z]+$", var.storage_account_name))
error_message = "The storage account name variable must have letters and numbers only"
}
validation {
condition = lower(var.storage_account_name) == var.storage_account_name
error_message = "The storage account name value must be in all lowercase"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment