Skip to content

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

  1. Create your first variable with a block variable with type service_name
    1. type = string
    2. default is your AWS username i.e. apprentice-0
    3. description = Service name to be used in this project to determine what resource belongs to who
  2. Create a second variable called vpc_id
    1. Type is string
    2. Default is the VPC ID, which you will get from your instructor.
    3. description = VPC ID

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"
}