tf_variables - henk52/knowledgesharing GitHub Wiki
-
#single line comment -
/* ... */multiline comment.
- Input variables
- output variables
- local values
-
allowing customaization without changing the modules source code.
-
provide when prompted during plan or apply
-
override default values using the cli arg
-var -
override default values using environment variables
TF_var_aa -
using
terraform.tvarsfile -
using
-var-file <ANY_NAME>.tvars -
using
auto.tfvars -
complex type constructors like list and map in input variables
-
custom validation rules
-
protect sensitive input variables.
- Allow data to be fetched or computed for use elsewhere in the tf conf.
- Allow tf conf to make us or information
- defined outside tf
- defined by another separate tf conf
- Allow tf conf to make us or information
- Each data resource is associated with a single data source
- Data resources have the same dependnecy dresolution behavior as defined for managed resources.
- Settin the
depends_onmeta-argument within a data block, defers reading ot he dat source until after all changes to the dependencies have been applied.
- Settin the
- Support
countfor_each
- are like return values of a terraform module
- A root module can use outputs to print specified values in the CLI output after running terraform apply.
- A sub module can use outputs to expose a subset of its resource attributes to a parent module.
- When using remote state, root module outputs can be accessed by other configurations via a
terraform_remote_statedata source.
variable "instance_type_list" {
description = "EC2 Instance type"
type = list(string)
default = [ "t3.micro", "t3.small" ]
}e.g. use: instance_type = var.instance_type_list[0]
variable "instance_type_map" {
description = "EC2 instance type"
type = map(string)
default = {
"dev" = "t3.micro"
"qa" = "t3.small"
"prod" = "t3.large"
}
}e.g. use: instance_type = var.instance_type_map["prod"]
output "for_output_list" {
value = [for something in aws_instance.myec2vm: something.public_dns]
}TODO what is going on here?
output "for_output_map1" {
value = {for something in aws_instance.myec2vm: something.id => something.public_dns}
}TODO what is going on here
output "for_output_map_advance" {
value = {for x, something in aws_instance.myec2vm: x => something.public_dns}
}output "legacy_splat_instance" {
description = "Legacy splat operator"
value = aws_instance.myec2vm.*.public_dns}
}output "genetalized_splat_instance" {
description = "genetalized splat operator"
value = aws_instance.myec2vm.[*].public_dns}
}- meta-argument accepts a map or a set of strings, and creates an instance for each item.
- string
- each.key == each.value
- map
- eack.key != each.value
- converts its arguments to a set value
- all elements must be of the same type.
- duplicates are coalesced.
> toset(["a", "b", 3])
[
"a",
"b",
"3",
]