In this article we will demonstrate various ways of passing Terraform variables.
Variable “image_id” {
type = string
description = “The id of the machine image (AMI) to use for the server.”
}
Map variables refers refers to key value pair
Usage:
Variable “mappi” {
Type = “map”
Default = {
ap-south-1=”t2.small”
us-east-1=”t2.large”
}
“In the above example keys are regions and the values associated with the keys are instance types.based on the region the instance type will be launched.
List variables take a list of values. It refers index that starts from zero.
variable “listii” {
type = list
default = [“t2.small”, “t2.large”]
}
Terraform automatically loads a number of variable definitions files if they are present:
* Files named exactly terraform.tfvars or terraform.tfvars.json.
* Any files with names ending in .auto.tfvars or .auto.tfvars.json.
The count parameter on resources can simplify configurations and let you scale resources by simply incrementing a number.
For example
Resource “aws_instance” “myserver” {
ami = “ami-05d66”
instance_type =”t2.medium”
count = 3
tags ={
name = “devservers”
}
In the above example we assigned count value is 3 so therefore it creates three instances with same tag devservers for all three instances.
To create 3 resources with 3 names that performs interation use count.index on that
$ is refered as interpolation
resource “aws_iam_user” “hello” {
name = “hello.${count.index}”
count = 3
path = “/system/”
}
We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc. Check our landing page for details.
© 2021 TheTerraform.in - All Rights Reserved.
Designed By TenXinfotech.