Which syntax check returns an error when you run terraform validate?
Select an option, then click Submit answer.
Reference / correct answer:
There is a missing variable block.
Most accepted answer: B. There is a missing variable block.
Community votes: B=3
Selected Answer: B I tried it tf validate ╷ │ Error: Reference to undeclared input variable │ │ on main.tf line 42, in resource "aws_instance" "tf_ec2": │ 42: Name = var.ec2name │ │ An input variable with the name "ec2name" has not been declared. This variable can be declared with a variable "ec2name" {} block. upvoted 1 times
Selected Answer: B Why "B" is the Answer If your code references a variable—for example, using var.instance_type—but you haven't actually defined that variable using a variable "instance_type" {} block, the configuration is considered incomplete. Terraform cannot proceed because it doesn't know the type or constraints of that reference, so validate will catch this and throw an error. Why the others are incorrect: C (State file mismatch): This is handled by terraform plan or terraform refresh. Validation doesn't look at the state file or your real-world resources at all. D (Tabs vs. Spaces): While the Terraform standard is two spaces, using tabs is not a syntax error. terraform fmt is the tool used to fix indentation, but validate won't fail because of it. A: Since B is a legitimate syntax/configuration error, A is incorrect. upvoted 2 times
Selected Answer: B Here’s why your explanation for A doesn’t hold up: terraform validate checks internal consistency, not just syntax. If your configuration references a variable that is not declared anywhere, Terraform will raise an error during validation. While values can be provided at runtime (CLI, env vars, tfvars), the variable itself must still be declared with a variable block. upvoted 2 times