Terrascript supports Terraform interpolation.
from terrascript import var
from terrascript.aws.r import aws_instance
ami = var('ami')
aws_instance('instance', ami=ami, instance_type='t2.micro')
resource "aws_instance" "instance" {
ami = "${var.ami}"
instance_type = "t2.micro"
}
from terrascript import map
from terrascript.aws.r import aws_instance
amis = map('amis')
aws_instance('instance', ami=amis['us-east-1'], instance_type='t2.micro')
resource "aws_instance" "instance" {
ami = "${var.amis["us-east-1"]}"
instance_type = "t2.micro"
}
from terrascript import list
from terrascript.aws.r import aws_instance
amis = list(['ami-12345678', 'ami-98765432'])
aws_instance('instance', ami=amis[1], instance_type='t2.micro')
resource "aws_instance" "instance" {
ami = "${var.amis[1]}"
instance_type = "t2.micro"
}
first = aws_instance('first', ami='ami-12345678', instance_type='t2.micro')
# Force second instance into same AZ.
aws_instance('second', ami='ami-12345678', instance_type='t2.micro',
availability_zone=first.availability_zone)
resource "aws_instance" "first" {
ami = "ami-22b9a343"
instance_type = "t2.micro"
}
resource "aws_instance" "second" {
ami = "ami-22b9a343"
instance_type = "t2.micro"
availability_zone = "${aws_instance.first.availability_zone}"
}