liveBook · Manning

Hierarchical naming system

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

A hierarchical naming scheme assigns names by extending a parent component's name with identifiers for nested subcomponents.

A hierarchical naming system builds each component name by extending its parent name with identifiers for nested components. In Terraform, module depth appears in resource addresses, command output, and state, making the naming structure visible operationally. section 10.1.2

Naming an Acme application

Set a stable application name and combine it with the environment: acme-production. Pass distinct extensions to child modules, such as acme-production-api and acme-production-db. Inside the service module, continue the hierarchy with names such as -lb, -logs, -cluster, and -service.

Use unique suffixes for each module and resource to prevent naming conflicts. When a provider imposes additional constraints, append a generated suffix; the example uses a six-character, lowercase, non-special random string for a secret.

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

How deep it goes
Explains recursive naming through module paths and worked Terraform listings, then addresses provider-specific suffix constraints.
Examples
Uses DNS names, Acme API and database modules, nested service resources, and a randomized Secrets Manager name.
What it assumes
Assumes Terraform modules and variables, while defining hierarchical naming through concrete module and resource examples.
What you can do after
Apply it via Terraform by composing environment-aware names and extending them consistently through nested modules and resources.
How it connects
Connects Terraform modules, resource addresses, Terraform state, environments, dependencies, and provider naming constraints.

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.