allow aspects of the module to be customized without altering the module's own source code, and allowing modules to be shared between different configurations.
kind of like function arguments
Can also validate vars (i.e. see if they are in a certain range)
variable "image_id" {
type = string
description = "The id of the machine image (AMI) to use for the server."
}
Input variables
variable "mytype" {
type = string
description = "The type of instance to create"
}
resource "aws_instance" "example" {
ami = "ami-0817d428a6fb68645"
instance_type = var.mytype
}
Input variables
The previous example will prompt for the variable value at runtime. You can also:
pass in variable at command line like terraform apply -var="mytype=t2.micro"
put them in a .tfvars file. and terraform apply -var-file="foo.tfvars"
in the file you just assign the variables like: mytype="t2.micro"
also can pass in as ENV var like export TF_VAR_mytype=t2.micro
Output values
Only rendered when tf applies your plan.
Are like a function return values
output "instance_ip_addr" {
value = aws_instance.server.private_ip
}