Terraform validate reports syntax check errors from which of the following scenarios?
Terraform validate reports syntax check errors from which of the following scenarios?
B
Reference:
http://man.hubwiz.com/docset/Terraform.docset/Contents/Resources/Documents/docs/commands/validate.html
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).
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
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 is the correct answer. Without value for variable, if we run terraform apply, it will ask for value via CLI.
Newer version of Terraform does not require you to give up values.
You can have missing value on variable, so D is the answer
https://developer.hashicorp.com/terraform/cli/commands/validate ... regardless of any provided variables or existing state
$ cat main.tf variable "cmd" {} resource "null_resource" "cmd" { provisioner "local-exec" { command = "${var.cmd}" } } $ terraform validate Success! The configuration is valid.
I think it is B
B is the answer
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
D is correct
i have checked practiacally with none variable value output say its valid so option D
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. None of the above. Ref: https://developer.hashicorp.com/terraform/cli/commands/validate
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