Search⌘ K
AI Features

Variable Defaults

Explore how to use default values in Terraform variables to streamline AWS resource creation. Understand variable syntax, concatenation for resource names, and how defaults simplify Terraform runs. This lesson helps you manage optional variable input and configure projects efficiently.

We'll cover the following...

Project example

Consider the following project:

C++
provider "aws" {
region = "us-east-2"
}
variable "bucket_name" {
description = "the name of the bucket you wish to create"
}
variable "bucket_suffix" {
default = "-abcd"
}
resource "aws_s3_bucket" "bucket" {
bucket = "${var.bucket_name}${var.bucket_suffix}"
}

We have extended the first example and added a second variable "bucket_suffix" which has its default set to "-abcd". Setting a default on a variable means that if you do not provide a value for that variable, then the default will be used. We then use the value of the ...