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

Supplying variables inline

The easiest (after interactive mode) way to set variable values is to specify them as an argument to Terraform command. It's done with the multiple -var arguments to the command with the name and value of the variable following:

$> terraform plan -var 'environment=dev'

Note how instance type of the EC2 server is different because we set the variable environment to dev.

So far, we don't have any map or list variables for the root module. Let's add a list of CIDR blocks that are allowed to access default security group via SSH. Also, let's add map with CIDR blocks for our subnets. We will have two blocks: for private and for public subnets accordingly. In the end, variables.tf should look as follows:

 variable "region" ...

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