This content originally appeared on DEV Community and was authored by Arun Kumar Singh
Terraform Validation
Starting Terraform 0.13, Hashicorp has released Custom Variable Validation in HCL. Each variable block can have zero or more validation blocks and an error message. It's quite useful feature which gives you an edge to control the values.
variable "cloudenv" {
type = string
description = "Cloud Environment"
validation {
condition = anytrue([
var.env == "prd",
var.env == "qa",
var.env == "uat",
var.env == "dev"
])
error_message = "Must be a valid Cloud Env, values can be prd, qa, uat, or dev."
}
}
Terraform Suppressing Values
There are certain cases in which you want terraform not to print the information when you run plan
or apply
. Good part is terraform has a way for you. Setting a variable as sensitive prevents Terraform from showing its value in the plan or apply output.
variable "user_information" {
type = object({
name = string
address = string
})
sensitive = true
}
Debug terraform
You can set TF_LOG to one of the log levels TRACE, DEBUG, INFO, WARN or ERROR to change the verbosity of the logs and push it to one of the files on disk for analysis.
mkdir logs
export TF_LOG_PATH="./logs/terraform.log"
export TF_LOG="INFO"
This content originally appeared on DEV Community and was authored by Arun Kumar Singh

Arun Kumar Singh | Sciencx (2021-09-12T18:00:18+00:00) Terraform: Good to know features – Post 1. Retrieved from https://www.scien.cx/2021/09/12/terraform-good-to-know-features-post-1/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.