TERRAFORM-ASSOCIATE-003 practice question 7 of 30

[Understand Terraform Basics and CLI] terraform validate confirms that your infrastructure matches the Terraform state file.

Full set: 226 questions
Answer options
A: True
B: False
Correct Answer:
FALSE
Explanation

The terraform validate command is used to check whether a set of configuration files are syntactically valid and internally consistent. It performs a static analysis of the .tf files in the current directory to catch syntax errors, incorrect argument types, and other code-level issues. It does not access any remote services, provider APIs, or the Terraform state file, and therefore cannot confirm if the deployed infrastructure matches the state.

Why Incorrect

The statement is false because it incorrectly describes the function of terraform validate. The command that compares the current configuration against the existing infrastructure (as recorded in the state file) to determine what changes are needed is terraform plan. A terraform plan that results in no proposed changes indicates that the deployed infrastructure matches the configuration.

References

1. HashiCorp Terraform Documentation, "Command: validate": "The terraform validate command validates the configuration files in a directory, referring only to the configuration and not accessing any remote services such as remote state, provider APIs, etc. Validate runs checks that require access to both the configuration and the state, and reports inconsistencies." This source explicitly states that validate does not access remote state or infrastructure.

2. HashiCorp Terraform Documentation, "The Core Terraform Workflow": In the "Write" and "Validate" step, the documentation describes terraform validate as a command to "check your configuration for syntax errors and other issues." In the subsequent "Plan" step, it describes terraform plan as the command to "preview the changes Terraform will make to match your configuration." This clearly separates the roles of the two commands.

3. HashiCorp Learn, "Validate Terraform Configuration": This tutorial states, "The terraform validate command validates the syntax of your Terraform code. It is a good practice to run this command before you run terraform plan or terraform apply to get fast feedback on any syntax errors in your configuration." This reinforces that its purpose is a pre-check on the code itself, not a comparison with live infrastructure.

Scroll to Top