Difference between revisions of "Terraform variable validation"
Jump to navigation
Jump to search
↑ https://www.hashicorp.com/blog/custom-variable-validation-in-terraform-0-13
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
<code>[[validation]]</code> [[Terraform variables|variable]] validation <ref>https://www.hashicorp.com/blog/custom-variable-validation-in-terraform-0-13</ref> | <code>[[validation]]</code> [[Terraform variables|variable]] validation <ref>https://www.hashicorp.com/blog/custom-variable-validation-in-terraform-0-13</ref> | ||
+ | |||
+ | variable "aws_region" { | ||
+ | type = string | ||
+ | description = "region used to deploy workloads" | ||
+ | default = "us-east-1" | ||
+ | validation { | ||
+ | condition = can(regex("^us-", var.aws_region)) | ||
+ | error_message = "The aws_region value must be a valid region in the USA, starting with \"us-\"." | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | * Since [[Terraform 1.2]] (2022): <code>[[precondition]]</code> and <code>[[postcondition]]</code> added for improving code and input [[validation]] | ||
== See also == | == See also == | ||
− | * {{Terraform}} | + | * {{Terraform variables}} |
[[Category:Terraform]] | [[Category:Terraform]] |
Latest revision as of 16:16, 4 April 2023
validation
variable validation [1]
variable "aws_region" { type = string description = "region used to deploy workloads" default = "us-east-1" validation { condition = can(regex("^us-", var.aws_region)) error_message = "The aws_region value must be a valid region in the USA, starting with \"us-\"." } }
- Since Terraform 1.2 (2022):
precondition
andpostcondition
added for improving code and input validation
See also[edit]
- Terraform variables, types, env variables,
variables.tf
,.tfvars
,nullable
,validation
,terraform.tfvars
Advertising: