liveBook · Manning

Environment

As explained in Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu

An environment is an isolated instance of a software system with independently managed infrastructure, configuration, and state.

An environment is an isolated instance of a software system with independently managed infrastructure, configuration, and state. A feature environment lets a developer run terraform apply against a local backend, test changes safely, then run terraform destroy before opening a pull request. section 8.2.2

Environments can represent development, staging, production, geographic regions, or customer-specific installations. Their number and structure follow business needs: staging commonly supports manual testing, while regional separation can address legal requirements or reduce latency. section 8.2.2

Terraform supports two complementary ways to distinguish environments:

  • Use root-level module input variables to change the generated resource graph, such as an environment’s base domain or enabled features. section 5.4
  • Create one thin root module per environment and point each to an application module. This permits independent application-module versions and environment-specific parameters. section 8.4.2
  • Keep sensitive values as inputs rather than saving them in source control; a shared repository usually simplifies management when one team owns the environments. section 8.4.2

A thin staging environment

A staging/main.tf root module can call an application module at version 1.1.1, set network_name, db_size, and num_tasks directly, pass a sensitive logging_api_key variable, and expose module.application.url as application_url. Separate production and future directories can use the same pattern while selecting their own module versions and settings. section 8.4.2

Figure 8.7 Staging and production flow

Use the staging-and-production flow to compare how isolated environments support testing before customer-facing deployment. section 8.2.2

How Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu covers it

How deep it goes
Explains lifecycle, environment types, variable-based variation, and thin root modules, but defers sensitive-value handling details.
Examples
Uses a Factory Analytics developer instance, staging and production flow, regional deployments, and an application-module configuration.
What it assumes
Assumes Terraform modules, root-level inputs, state, and resource graphs while demonstrating environment variation through concrete configurations.
What you can do after
Operate environments via Terraform by applying isolated instances, configuring differences, and destroying temporary feature environments.
How it connects
Connects environments to Terraform modules, root modules, state, feature environments, staging, production, and continuous integration.

Also explained in

Compare how 8 books explain environment →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu. The section links point to the parts of the book it draws on.