Variables
variables.tf
file will usually hold every single variable in your Terraform project.
Its idea is to have a centralized place to store all the variables which makes configuration of the Terraform project more DRY.
Variables can be string
, list(<type>)
, map(<type>)
, number
, bool
or even null
You can refer to your variables with the prefix of var.
i.e. var.service_name
variables.tf
file
- Create your first variable with a block
variable
with typeservice_name
type
=string
default
is your AWS username i.e.apprentice-0
description
=Service name to be used in this project to determine what resource belongs to who
- Create a second variable called
vpc_id
- Type is
string
- Default is the VPC ID, which you will get from your instructor.
description
=VPC ID
- Type is
Usually, it's good to use Descriptions to tell what the variable is.
Answer
variable "service_name" {
type = string
default = "USERNAME"
}
variable "vpc_id" {
type = string
default = "VPC_ID"
}