Resources, variables, and outputs

A resource describes an object Terraform can manage. Variables let configuration accept values; outputs expose useful results after Terraform evaluates the configuratio

A resource describes an object Terraform can manage. Variables let configuration accept values; outputs expose useful results after Terraform evaluates the configuration.

Example local resource

hcl · static example

variable "message" {
  type    = string
  default = "Hello from Terraform"
}

resource "local_file" "welcome" {
  filename = "${path.module}/welcome.txt"
  content  = var.message
}

output "welcome_path" {
  value = local_file.welcome.filename
}

This example writes a file in the module directory through the local provider. Review the target path before applying.

Read a named output value

Outputs can provide values such as generated addresses or resource identifiers, depending on the configuration.

terraform output welcome_path

Static example · not executed

Knowledge check

What does a Terraform variable help with?

Pick an answer to check.

    Resources, variables, and outputs · Terraform Foundations | Nestify Campus