Variables and Outputs
Variable Types
Section titled “Variable Types”Input Variables
- var.<“name”>
variable "instance_type" { description = "ec2 instance type" default = "t2/micro"}Setting Input Variables
(In order of precedence, lowest -> highest)
- Manual entry during plan/apply.
- Default value in declaration block.
- TF_VAR_<“name”> environment variables.
- terraform.tfvars file.
- *.auto.tfvars file.
- Command line
-varor -var-file.
Local Variables
- local.<“name”>
locals { service_name = "My Service" owner = "Justin"}Output Variables
output "instance_ip_addr" { value = aws_instance.instance.public_ip}Types & Validation
Section titled “Types & Validation”Primitive Types:
- string
- number
- bool
Complex Types:
- list(<“TYPE”>)
- set(<“TYPE”>)
- map(<“TYPE”>)
- object({<“ATTR NAME”> = <“TYPE”>, …})
- tuple([<“TYPE”>,…])
Validation:
- Type checking happens automatically.
- Custom conditions can also be enforced.
Sensitive Data
Section titled “Sensitive Data”Mark variables as sensitive:
Sensitive = true. Pass to terraform apply with:TV_VAR_variable.-var(retrieved from secret manager).
Can also use external secret store:
- AWS Secrets Manager.