nerdexam
HashiCorp

TA-002-P · Question #88

Terraform validate reports syntax check errors from which of the following scenarios?

The correct answer is B. There is missing value for a variable. The terraform validate command checks for configuration syntax errors, inconsistent types, and missing mandatory variable values. It specifically reports errors when a required variable has no default value and no value is provided.

Use the Terraform CLI (terraform plan, apply, destroy, fmt, init, validate, workspace, import, taint, providers, output)

Question

Terraform validate reports syntax check errors from which of the following scenarios?

Options

  • ACode contains tabs indentation instead of spaces
  • BThere is missing value for a variable
  • CThe state files does not match the current infrastructure
  • DNone of the above

How the community answered

(25 responses)
  • B
    96% (24)
  • D
    4% (1)

Why each option

The `terraform validate` command checks for configuration syntax errors, inconsistent types, and missing mandatory variable values. It specifically reports errors when a required variable has no default value and no value is provided.

ACode contains tabs indentation instead of spaces

`terraform validate` does not check for stylistic issues like indentation (tabs vs. spaces); that is typically handled by `terraform fmt`.

BThere is missing value for a variableCorrect

`terraform validate` checks if the configuration is syntactically valid and internally consistent, including validating variable definitions. If a mandatory variable is declared without a default value and no value is provided via `.tfvars` file, CLI argument, or environment variable, `terraform validate` will report this as an error because the configuration is incomplete.

CThe state files does not match the current infrastructure

`terraform validate` only checks the configuration files, not the live infrastructure or its consistency with the state file. Checking state-to-infrastructure consistency is part of `terraform plan` or manual inspection.

DNone of the above

Since option B is correct, this option is incorrect.

Concept tested: Terraform validate command functionality

Source: https://developer.hashicorp.com/terraform/cli/commands/validate

Topics

#Terraform validate#Variables#Configuration validation#Terraform CLI

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice