O'Reilly logo

Getting Started with Terraform - Second Edition by Kirill Shirinkin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using variable files

When running Terraform commands, you can optionally supply a variable file via the -var-file argument. The syntax of these files is the good old HCL, familiar to you from Terraform templates themselves. Create a new file named development.tfvars and set your variables there:

region = "eu-central-1" 
vpc_cidr = "172.0.0.0/16" 
subnet_cidrs = { 
  public = "172.0.16.0/24" 
  private = "172.0.17.0/24" 
} 

To use it, run terraform plan command with -var-file argument:

$> terraform plan -var-file=./development.tfvars 

It's much more reliable to use variable files for production stacks: you always know which values are there and you can store them in version control. And for sensitive things, such as a personal password to access ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required