Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam Terraform Associate All Questions

View all questions & answers for the Terraform Associate exam

Exam Terraform Associate topic 1 question 88 discussion

Actual exam question from HashiCorp's Terraform Associate
Question #: 88
Topic #: 1
[All Terraform Associate Questions]

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

  • A. Code contains tabs indentation instead of spaces
  • B. There is missing value for a variable
  • C. The state files does not match the current infrastructure
  • D. None of the above
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
Eltooth
Highly Voted 2 years, 4 months ago
Selected Answer: B
B is correct answer. The terraform validate command is used to validate the syntax of the terraform files. Terraform performs a syntax check on all the terraform files in the directory, and will display an error if any of the files doesn't validate. This command does not check formatting (e.g. tabs vs spaces, newlines, comments etc.). The following can be reported: invalid HCL syntax (e.g. missing trailing quote or equal sign) invalid HCL references (e.g. variable name or attribute which doesn't exist) same provider declared multiple times same module declared multiple times same resource declared multiple times invalid module name interpolation used in places where it's unsupported (e.g. variable, depends_on, module.source, provider) missing value for a variable (none of -var foo=... flag, -var-file=foo.vars flag, TF_VAR_foo environment variable, terraform.tfvars, or default value in the configuration) https://www.typeerror.org/docs/terraform/commands/validate https://learning-ocean.com/tutorials/terraform/terraform-validate
upvoted 29 times
Pietjeplukgeluk
1 year, 9 months ago
Just tested this in lab, and "missing value for a variable (none of -var foo=... flag, -var-file=foo.vars flag, TF_VAR_foo environment variable, terraform.tfvars, or default value in the configuration)" is untrue, it is required to declare the variable type (but a value is not required to pass the "terraform validate")e.g. validates if referred somewhere else : variable "ami_type" { type = string }
upvoted 5 times
joyboy23
1 year, 4 months ago
I tested the same too. VSCode is detecting it but not terraform validate.From exam point of view, I wonder which one is the correct answer
upvoted 1 times
...
deepeshukla
1 year, 5 months ago
Agree. D is the correct answer. I tested in Lab. Missing variable value will not be reported in terraform valid, because it can be passed while running code (hence not invalid code).
upvoted 5 times
...
Tyler2023
1 year ago
Agree on this, D is the correct answer Terraform Validate runs checks that verify whether a configuration is syntactically valid and internally consistent, regardless of any provided variables or existing state. To verify configuration in the context of a particular run (a particular target workspace, input variable values, etc), use the terraform plan command instead, which includes an implied validation check. https://developer.hashicorp.com/terraform/cli/commands/validate
upvoted 3 times
...
...
...
aanataliya
Highly Voted 1 year, 2 months ago
Selected Answer: D
Confusion between B and D. B was correct in older version of terraform. it was correct until v0.12.9 but then it was removed in later version. see below documentation links. As per latest documentation B is incorrect when we have option D available. https://github.com/hashicorp/terraform/blob/v0.12.9/website/docs/commands/validate.html.markdown https://github.com/hashicorp/terraform/blob/v0.12.10/website/docs/commands/validate.html.markdown please vote for correct answer to help others.
upvoted 17 times
...
AntonyPeter7
Most Recent 8 months, 3 weeks ago
Selected Answer: D
D is the correct answer. Without value for variable, if we run terraform apply, it will ask for value via CLI.
upvoted 4 times
...
erhard
9 months ago
Selected Answer: D
https://developer.hashicorp.com/terraform/cli/commands/validate ... regardless of any provided variables or existing state
upvoted 1 times
...
Alandt
10 months ago
Selected Answer: D
Newer version of Terraform does not require you to give up values.
upvoted 2 times
...
TigerInTheCloud
11 months, 1 week ago
Selected Answer: D
$ cat main.tf variable "cmd" {} resource "null_resource" "cmd" { provisioner "local-exec" { command = "${var.cmd}" } } $ terraform validate Success! The configuration is valid.
upvoted 2 times
...
Ramdi1
12 months ago
Selected Answer: B
I think it is B
upvoted 1 times
...
ghostGuiggs
1 year ago
Selected Answer: B
B is the answer
upvoted 1 times
...
MisterR0B0T
1 year ago
D - The terraform validate command is used to validate the syntax of the terraform files. Terraform performs a syntax check on all the terraform files in the directory, and will display an error if any of the files doesn't validate. This command does not check formatting (e.g. tabs vs spaces, newlines, comments etc.)
upvoted 1 times
...
MisterR0B0T
1 year ago
A terraform validate is a command that validates the configuration files in a directory, referring only to the configuration and not accessing any remote services such as remote state, provider APIs, etc1. It runs checks that verify whether a configuration is syntactically valid and internally consistent, regardless of any provided variables or existing state 1. Therefore, it reports syntax check errors if there are any syntax errors in the code 1. Therefore, the correct answer is A. Code contains tabs indentation instead of spaces.
upvoted 1 times
...
MauroSoli
1 year, 1 month ago
Also input variable of a root module is a variable. So if a variable of an used module haven't a default value terraform validate return error. Answer is B
upvoted 1 times
...
Aman726
1 year, 1 month ago
Selected Answer: D
D is correct
upvoted 1 times
...
Alex1atd
1 year, 1 month ago
Selected Answer: D
You can have missing value on variable, so D is the answer
upvoted 2 times
...
adityanarayan
1 year, 1 month ago
i have checked practiacally with none variable value output say its valid so option D
upvoted 1 times
...
gofavad926
1 year, 1 month ago
Selected Answer: B
B. There is missing value for a variable Terraform validate will check for syntax errors in your Terraform configuration, including the following: Missing or invalid variable values Invalid resource references Invalid attribute values Invalid data source references Invalid module references Terraform validate will not check for the following: Code indentation State file consistency Other configuration errors, such as logical errors or errors in the desired state of your infrastructure
upvoted 1 times
...
Halimb
1 year, 2 months ago
Selected Answer: D
D. None of the above. Ref: https://developer.hashicorp.com/terraform/cli/commands/validate
upvoted 1 times
...
Spandrop
1 year, 2 months ago
D is the correct answer "Validate runs checks that verify whether a configuration is syntactically valid and internally consistent, regardless of any provided variables or existing state. It is thus primarily useful for general verification of reusable modules, including correctness of attribute names and value types." https://developer.hashicorp.com/terraform/cli/commands/validate
upvoted 2 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...