DEV Community

Arun Kumar Singh
Arun Kumar Singh

Posted on

3

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 control the values.

variable "cloudenv" {
  type        = string
  description = "Cloud Environment"

  validation {
    condition = anytrue([
      var.cloudenv == "prd",
      var.cloudenv == "qa",
      var.cloudenv == "uat",
      var.cloudenv == "dev"
    ])
    error_message = "Must be a valid Cloud Env, values can be prd, qa, uat, or dev."
  }
}

Enter fullscreen mode Exit fullscreen mode

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
}
Enter fullscreen mode Exit fullscreen mode

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" 
Enter fullscreen mode Exit fullscreen mode

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (2)

Collapse
 
dogers profile image
Dogers

Unless something has changed in TF 1.x, your first example won't work - "var.env" should be "var.cloudenv" as the validation can only reference the variable it's validating..

Collapse
 
arunksingh16 profile image
Arun Kumar Singh

Good catch.. Sorry for typo, corrected now. Thanks a lot @dogers

Playwright CLI Flags Tutorial

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • 0:56 --last-failed: Zero in on just the tests that failed in your previous run
  • 2:34 --only-changed: Test only the spec files you've modified in git
  • 4:27 --repeat-each: Run tests multiple times to catch flaky behavior before it reaches production
  • 5:15 --forbid-only: Prevent accidental test.only commits from breaking your CI pipeline
  • 5:51 --ui --headed --workers 1: Debug visually with browser windows and sequential test execution

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Click on any timestamp above to jump directly to that section in the tutorial!

Watch Full Video 📹️

👋 Kindness is contagious

DEV shines when you're signed in, unlocking a customized experience with features like dark mode!

Okay