Created
February 21, 2022 21:38
-
-
Save brunopadz/d138178fa1034b75df28d9d2ca70558e to your computer and use it in GitHub Desktop.
Terraform variable 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
# 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