Skip to content

Instantly share code, notes, and snippets.

@brunopadz
Created February 21, 2022 21:38
Show Gist options
  • Save brunopadz/d138178fa1034b75df28d9d2ca70558e to your computer and use it in GitHub Desktop.
Save brunopadz/d138178fa1034b75df28d9d2ca70558e to your computer and use it in GitHub Desktop.
Terraform variable validation
# Using anytrue()
variable "instance_size" {
type = string
description = "RDS Instance Size"
validation {
condition = anytrue([
var.instance_size == "db.t3.micro",
var.instance_size == "db.t3.small",
var.instance_size == "db.t3.medium"
])
error_message = "Instance size does not match db.t3.micro, db.t3.small or db.t3.medium."
}
}
# Using contains()
variable "bucket_acl" {
type = string
description = "ACL to be set on S3 bucket"
validation {
condition = contains(["private", "public-read", "authenticated-read"], var.bucket_acl)
error_message = "S3 bucket ACL must be 'private', 'public-read' or 'authenticated-read'."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment