The type argument in a variable block allows you to restrict the type of value that will be accepted as the value for a variable. If no type constraint is set then a value of any type is accepted.
Source: https://www.terraform.io/language/values/variables
Correct is E
Terraform CLI defines the following OPTIONAL arguments for variable declarations:
default - A default value which then makes the variable optional.
type - This argument specifies what value types are accepted for the variable.
description - This specifies the input variable's documentation.
validation - A block to define validation rules, usually in addition to type constraints.
sensitive - Limits Terraform UI output when the variable is used in configuration.
nullable - Specify if the variable can be null within the module.
we can define variables without type, default, and description.
default argument will require and value when terraform apply is executed. So in the context of this question is it required and answer is not
variable "prefix" {
}
variable "location" {
}
When declaring a variable in Terraform, no arguments are required. However, there are optional arguments you can include for clarity and readability:
description: This is a string that describes the purpose of the variable.
default: This is the default value that Terraform will use if no other value is provided.
type: This constrains the type of value the variable will accept, such as string, list, map, number, or bool.
Here's an example of a variable declaration with no arguments:
variable "example" {
}
And here's an example with all optional arguments included:
variable "example" {
description = "An example variable used for demonstration purposes"
default = "Hello, World!"
type = string
}
Arguments
Terraform CLI defines the following optional arguments for variable declarations:
default - A default value which then makes the variable optional.
type - This argument specifies what value types are accepted for the variable.
description - This specifies the input variable's documentation.
validation - A block to define validation rules, usually in addition to type constraints.
sensitive - Limits Terraform UI output when the variable is used in configuration.
nullable - Specify if the variable can be null within the module.
E is correct.
It is possible to declare a variable without any of the given arguments (type, default, description). In fact, a variable declaration only requires a name and an optional type constraint.
So the correct answer is E. None of the above.
None of the above arguments are required when declaring a Terraform variable. However, at least one of the following arguments is required:
type: Specifies the data type of the variable. Valid types include string, number, bool, list, map, and object.
default: Specifies the default value of the variable. If no default value is specified, the variable is considered required and must be set by the user when running Terraform.
description: Provides a description of the variable and its intended use. This is optional but recommended to make the purpose of the variable clear to users.
In addition to these arguments, there are several other optional arguments that can be used when declaring a Terraform variable, including validation, sensitive, and allowed_values.
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.
Egger1992
Highly Voted 2 years, 8 months agoAWS_PT
2 years, 1 month agoShane_C
1 year, 5 months agogcpz
Highly Voted 2 years, 8 months agoanand0310
Most Recent 3 months, 4 weeks agoMolly1994
6 months, 3 weeks agosamimshaikh
12 months agoghostGuiggs
1 year, 1 month agoTyler2023
1 year, 2 months agoBere
1 year, 5 months agomirekbehan
1 year, 5 months agoShane_C
1 year, 5 months agovj_dhaksh
1 year, 6 months agoNi33
1 year, 7 months agoAzRNoob
1 year, 8 months agoFaaizz
1 year, 8 months agocamps
1 year, 9 months agoPower123
1 year, 9 months agosahara99
1 year, 10 months ago