Terraform: Good to know features – Post 1

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 co…


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Terraform: Good to know features – Post 1." Arun Kumar Singh | Sciencx - Sunday September 12, 2021, https://www.scien.cx/2021/09/12/terraform-good-to-know-features-post-1/
HARVARD
Arun Kumar Singh | Sciencx Sunday September 12, 2021 » Terraform: Good to know features – Post 1., viewed ,<https://www.scien.cx/2021/09/12/terraform-good-to-know-features-post-1/>
VANCOUVER
Arun Kumar Singh | Sciencx - » Terraform: Good to know features – Post 1. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/12/terraform-good-to-know-features-post-1/
CHICAGO
" » Terraform: Good to know features – Post 1." Arun Kumar Singh | Sciencx - Accessed . https://www.scien.cx/2021/09/12/terraform-good-to-know-features-post-1/
IEEE
" » Terraform: Good to know features – Post 1." Arun Kumar Singh | Sciencx [Online]. Available: https://www.scien.cx/2021/09/12/terraform-good-to-know-features-post-1/. [Accessed: ]
rf:citation
» Terraform: Good to know features – Post 1 | Arun Kumar Singh | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.