Created
July 16, 2020 11:28
-
-
Save deanwilson/1f764eaa930fa5fd9222fbd05a3a5b14 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
## cat main.tf | |
variable "vpc_id" { | |
type = string | |
description = "VPC ID to deploy to" | |
validation { | |
#condition = can(regex("^vpc-", var.vpc_id)) | |
condition = length(var.vpc_id) > 4 && substr(var.vpc_id, 0, 4) == "vpc-" | |
error_message = "The vpc_id must be a valid VPC ID of the form 'vpc-'." | |
} | |
} | |
####################### Pass an invalid value | |
./terraform plan -var vpc_id=foo | |
Error: Invalid value for variable | |
on main.tf line 1: | |
1: variable "vpc_id" { | |
The vpc_id must be a valid VPC ID of the form 'vpc-'. | |
This was checked by the validation rule at main.tf:6,3-13. | |
####################### Pass a valid value | |
./terraform plan -var vpc_id=vpc-200 | |
No changes. Infrastructure is up-to-date. | |
# Other neat example - is something valid yaml? | |
condition = var.custom_vars != "" ? can(yamldecode(var.custom_vars)) : true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment