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