Terraform Variables, Outputs, and Types

How Terraform modules accept typed inputs, reuse local values, and expose selected results through outputs.

On this page

Variables define a module’s input interface, outputs expose selected results, and local values name expressions reused inside one module. HashiCorp’s values guide describes these boundaries.

 1variable "environment" {
 2  type        = string
 3  description = "Deployment environment"
 4}
 5
 6locals { name_prefix = "app-${var.environment}" }
 7
 8output "service_name" {
 9  value = local.name_prefix
10}

Use type constraints to make the input contract clear: list and tuple are ordered collections, set contains unique unordered values, map is keyed, and object has named attributes. Choose the narrowest shape that callers need.

Mark a secret sensitive to redact it in normal output, but do not assume it will be absent from state. Outputs do not replace state or establish an access-control boundary.

Revised on Friday, September 11, 2026