1. Variable declaration
A variable block declares an input named region that callers can override.
variable "region" {Typorithm · medium
Step 1 of 8 · intro card
HCL Basics
A variable block declares a typed, optionally defaulted input; you read it elsewhere with var.<name>, like var.region inside a resource.
Input variables parameterize a configuration so the same code can be reused across environments without editing it.
A variable block sets a type constraint (string, number, bool, list, map, object) and an optional default; with a default the variable is optional, without one it is required.
Anywhere in the configuration you read the value with var.<name>, for example var.region, and Terraform substitutes the resolved value.
variable "name" { } declares an input.
type constrains accepted values.
Read it with var.<name>.
variable "region" {
type = string
default = "us-east-1"
}
resource "aws_s3_bucket" "this" {
bucket = "my-bucket"
tags = {
Region = var.region
}
}Connect each part of the code to the concept before you type.
A variable block declares an input named region that callers can override.
variable "region" {type constrains the accepted value; string rejects numbers, lists, and maps.
type = stringdefault makes the variable optional; if no value is passed, this is used.
default = "us-east-1"var.region reads the variable's value inside a resource.
Region = var.regionRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.