HashiCorp Certified: Terraform Associate — Question 318
You are making changes to existing Terraform code to add some new infrastructure.
When is the best time to run terraform validate?
Answer options
- A. After you run terraform plan so you can validate that your state file is consistent with your infrastructure
- B. Before you run terraform plan so you can validate your code syntax
- C. Before you run terraform apply so you can validate your infrastructure
- D. After you run terraform apply so you can validate your provider credentials
Correct answer: B
Explanation
The correct answer is B because running terraform validate before terraform plan allows you to catch any syntax errors in your code early on. Options A, C, and D are incorrect as they suggest validating at times when the code may already be in a state of execution or potential error, which does not address syntax issues beforehand.