Menu

Variables, Outputs and Data Sources

Variables, Outputs and Data Sources

Declaring Input Variables and Using Variable Files

  • Declare inputs in `variables.tf` and set values through `terraform.tfvars`, environment variables or command-line options. Do not store passwords or long-lived credentials in ordinary variable files.
  • Use validation to reject invalid regions, CIDR ranges or environment names. Keep example variable files free of secrets and document required inputs so another learner can reproduce the project.

Working with Output Values and Local Values

  • Outputs expose useful values after an apply, such as a bucket name or instance address. Mark an output sensitive when it may reveal confidential information, while remembering that sensitive marking primarily controls display and does not remove the value from state.
  • Locals name expressions used repeatedly in a module. Use them to reduce duplication, not to hide complicated logic.

Understanding Data Sources and Retrieving Existing Infrastructure Information

  • Data sources query information about objects that already exist; they do not create those objects. For example, an AWS availability-zone data source can retrieve available zones for a region.
  • Use data sources when a configuration needs to refer to shared infrastructure managed elsewhere. Confirm filters are specific enough to select the intended object, because a broad lookup can return an unexpected match or fail when multiple objects match.

Terraform Tutorial

HA

Harini A



Learn via Video Course

undefined Logo

NaN hrs



Get in Touch For Details