M365Con 2027 – безкоштовна онлайн-конференція · 11–22 Jan 2027 · 120 sessions m365con.net

Terraform state

Concept

The record Terraform keeps of the infrastructure it manages, mapping resources in the configuration to real remote objects. Terraform uses it to decide which changes to make; it can contain sensitive values and is best kept in a remote, locked and access-controlled backend.

✦ CONCEPTTerraform stateM365.FM
Title graphic: Terraform state (Concept)

Часто обговорюють разом

У випусках на тему Terraform state часто обговорюють також: Amazon Web Services (AWS).

Description

Terraform state is the record that Terraform keeps of the infrastructure it manages. It maps the resources described in a configuration to the real remote objects that exist in a cloud environment. Terraform reads this record to decide which changes to make: which resources to add, which to update and which to delete. Because the state acts as the source of truth for everything Terraform manages, how it is stored and protected has a direct effect on how safely deployments run.

In practice the state is held in a state file. One M365.FM episode, "Terraform vs Azure Bicep: Which IaC Tool Should You Choose?", describes Terraform as relying on a state file to track the current status of infrastructure and stresses that state management must be handled carefully to avoid issues that can disrupt deployments. The same episode notes that the state file can be stored locally or remotely, with remote options including cloud buckets and similar storage. The choice between local and remote storage is one of the central decisions around Terraform state.

Microsoft Learn documentation on storing Terraform state in Azure Storage explains why that choice matters. By default, Terraform stores state locally. The documentation describes this as a poor fit for teams, because the file may expose sensitive information, since it can contain secrets in plain text, and because there is a greater risk of accidental deletion. The recommended pattern is to keep the state remotely in an Azure Storage blob container through the azurerm backend. That backend is configured with the storage account name, the container name and a key that names the state file.

The documentation also covers how access to that storage is handled. The access key is best supplied through an environment variable rather than being written to disk, and it can also be stored in Key Vault. Azure Blob storage locks the state automatically before write operations, which prevents concurrent changes that could corrupt it, and the data is encrypted at rest. The example in the documentation uses an access key and open network access, which the page marks as unsuitable for production. For production use, it points to firewalls, service endpoints or private endpoints, together with the most secure supported authentication method.

Typical situations where state comes up include team collaboration, pipeline-based deployments and reviewing planned changes. The episode "Azure Infrastructure as Code and DevOps with Maik van der Gaag [MVP]" mentions using Terraform state files to track the current state of resources, which helps in planning and applying changes safely. It places this alongside other practices such as sharing code through Terraform modules, requiring code reviews before changes are merged, and using continuous deployment to deliver updates to an Azure environment reliably and with less risk of human error. The episode also mentions combining Terraform with tools such as Ansible or PowerShell for end-to-end automation.

Taken together, the sources point to a consistent set of practices. Terraform state should be treated as sensitive data, kept in a remote backend rather than on a local machine, protected by locking so that two operations cannot change it at the same time, and placed behind access controls. Understanding what the state contains, and who or what can read or modify it, is part of operating Terraform responsibly, particularly when several people or automated pipelines work against the same infrastructure. The same concern for state handling is one of the points the first episode raises when comparing Terraform with Azure Bicep for infrastructure as code.

Overview compiled with AI from M365.FM episodes and the facts on this page. You can improve it with the edit button below.

TypeConcept

Articles about Terraform state (2)

Статті, у яких розглядається Terraform state:

Glossary

Community wiki

Short info above, community knowledge below: add practical tips, examples or corrections. New contributions are reviewed first; trusted members publish directly.

Experts and companies for this topic

Nobody has listed this topic yet. Add it to your profile.

Sources

Maintained by Mirko Peters (Microsoft MVP) · Last updated: