All technological notes.
In Terraform, it is allowed to interpolate other values using ${}
Interpolation types:
${var.variable_name}${aws_instance.name.id}${data.template_file.name.rendered}| Variable Type | Syntax | Example |
|---|---|---|
| String | var.VAR_NAME |
${var.aws_region} |
| Map | var.MAP_NAME["key_name"] |
${var.amis["us-east-1"]}/${lookup(var.amis, var.aws_region)} |
| List | var.LIST_NAME,var.LIST_NAME[index] |
${var.subnets[i]},${join(",",var.subnets)} |
| Outputs of a module | module.NAME.output |
${module.aws_vpc.vpcid} |
| Count informatnion | count.FIELD | ${count.index} |
| Path information | path.TYPE |
path.cwd(current dir), path.module(module path),path.root(root module path) |
| Meta information | terraform.FIELD |
terraform.env(active workspace) |
${2 + 3 * 4}condition ? trueval : falseval
resource "aws_instance" "myinstance"{
count = ${var.env == "prod" ? 2 : 1} # if the env is prod, then provision 2 instances, otherwise just 1.
}
==!=<, <=>,>=&&, ||, !