How to Override Variables using Terraform CLI

Tek Loon
Mar 6, 2022

--

This post explains two scenarios:

  • Override a variable
  • Override Multiple Variables

Let’s start.

variable “instance_name” {
description = “Value of the name tag for EC2 Instance
type = string
default = “TFExampleApp”
}
variable "instance_type" {|
description = "EC2 instance type"
type = string
default = "t2.micro"
}

I have declared 2 variables which is instance_nameand instance_type

Scenario 1 — Override A Variable

Given that you only want to override instance_name. The terraform command would look like this:

terraform apply -var “instance_name=quote-backend-v2”

Scenario 2 — Override Multiple Variables

Given that you want to override both instance_name and instance_type . The terraform command would look like this:

terraform apply -var “instance_name=quote-backend-v2” -var “instance_type=t2.nano”

--

--

Tek Loon

Coder and Writer. If you enjoy my stories— support me by https://www.buymeacoffee.com/tekloon so I can keep writing articles for the community.