Recall & Review
beginner
What is the basic syntax to declare a variable in Terraform?
Use the
variable block with a name and optional attributes like type, default, and description.<br><br>Example:<br>variable "region" {<br> type = string<br> default = "us-west-1"<br> description = "AWS region to deploy resources"<br>}Click to reveal answer
beginner
What does the
default attribute do in a Terraform variable declaration?It sets a value that Terraform uses if no other value is provided when running.<br><br>This makes the variable optional because it has a fallback value.
Click to reveal answer
intermediate
How do you specify the type of a variable in Terraform?
Use the
type attribute inside the variable block.<br><br>Common types: string, number, bool, list(string), map(string).<br><br>Example:<br>variable "ports" {<br> type = list(number)<br>}Click to reveal answer
beginner
Can you declare a variable without a default value in Terraform? What happens then?
Yes, you can declare a variable without a default.<br><br>Terraform will require you to provide a value when you run your configuration, or it will show an error.
Click to reveal answer
beginner
How do you add a description to a Terraform variable and why is it useful?
Use the
description attribute inside the variable block.<br><br>This helps others (and yourself) understand what the variable is for.<br><br>Example:<br>variable "env" {<br> type = string<br> description = "The environment to deploy to, e.g., dev or prod"<br>}Click to reveal answer
Which block is used to declare a variable in Terraform?
✗ Incorrect
The
variable block is used to declare variables in Terraform.What happens if you declare a variable without a default value and do not provide a value when running Terraform?
✗ Incorrect
Terraform requires a value for variables without defaults; otherwise, it throws an error.
How do you specify that a variable should be a list of strings?
✗ Incorrect
Terraform uses
list(string) to specify a list of strings.Which attribute is used to provide a fallback value for a variable?
✗ Incorrect
The
default attribute sets a fallback value for a variable.Why is adding a description to a variable useful?
✗ Incorrect
Descriptions help explain the purpose of variables to users.
Explain how to declare a variable in Terraform including type, default, and description.
Think about the structure of a variable block and what each attribute does.
You got /4 concepts.
What happens if you declare a variable without a default and do not provide a value when running Terraform?
Consider Terraform's behavior when required inputs are missing.
You got /2 concepts.