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
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
}
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
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).
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.
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.)
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.
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
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
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
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.
Eltooth
Highly Voted 2 years, 3 months agoPietjeplukgeluk
1 year, 8 months agoTyler2023
11 months, 4 weeks agodeepeshukla
1 year, 3 months agojoyboy23
1 year, 3 months agoaanataliya
Highly Voted 1 year, 1 month agoAntonyPeter7
Most Recent 7 months, 3 weeks agoerhard
8 months agoAlandt
9 months agoTigerInTheCloud
10 months, 1 week agoRamdi1
11 months agoghostGuiggs
11 months, 4 weeks agoMisterR0B0T
11 months, 4 weeks agoMisterR0B0T
11 months, 4 weeks agoMauroSoli
1 year agoAman726
1 year agoAlex1atd
1 year agoadityanarayan
1 year agogofavad926
1 year agoHalimb
1 year, 1 month agoSpandrop
1 year, 1 month ago