A Terraform resource is the managed object Terraform creates, changes, or destroys to define desired infrastructure state. Unlike a data source, it represents something Terraform owns over time, such as a subnet, instance, or security group. Resources are the core mechanism for enforcing repeatable infrastructure changes.
What a Terraform resource is
A Terraform resource is the object in configuration that Terraform manages over time. It is the thing the tool creates, updates, or destroys to move infrastructure toward the declared desired state, so the resource is the basic unit of infrastructure change rather than a passive description of something already there.
That distinction matters because a resource is not just a label for an asset. It is the point where declarative intent becomes lifecycle control, with Terraform tracking ownership, planned drift, and eventual replacement or deletion as part of the workflow.
How resources differ from data sources
Resources and data sources often appear together, but they serve different purposes. A data source reads existing infrastructure or external information, while a resource represents something Terraform is responsible for managing. That ownership boundary is central to understanding how Terraform decides what to change and what to leave alone.
In practice, this separation helps prevent accidental interference with objects that should only be observed, not governed by Terraform. It also makes it easier to model dependencies correctly, because resources express created state and data sources express imported context.
State, lifecycle, and dependency behaviour
Terraform resource behaviour is tied to state. State records the mapping between configuration and real infrastructure, allowing Terraform to detect changes, calculate an execution plan, and determine whether an object should be modified in place or recreated.
Resources also define the dependency graph that drives ordering. When one resource depends on another, Terraform can sequence creation, updates, and destruction in a predictable way, which is why resource design has direct operational consequences for uptime, replacement windows, and rollback behaviour.
Lifecycle settings can refine that behaviour further, for example by controlling replacement triggers or protecting an object from deletion. Those controls do not remove risk entirely, but they do shape how safely Terraform can converge a live environment toward a new desired state.
Why resources matter in infrastructure security
Resources are one of the main places where infrastructure security becomes enforceable rather than aspirational. A well-defined resource model makes it possible to express repeatable configurations for network boundaries, compute, storage, and access-related infrastructure, reducing the chance that manually applied changes drift away from policy.
That is why Terraform security guidance often focuses on the resource layer, including review of plans, module boundaries, and state handling. The resource is where misconfiguration can become persistent infrastructure, and where an unsafe change can be replicated consistently across environments.
For broader Terraform security patterns, the Infrastructure as Code Security Guide covers how resources, state, modules, scanning, and drift detection fit together.
Resource lifecycle also has a secrets and credential angle when infrastructure definitions, plans, or backend state expose sensitive values. In that case, the resource is not the secret itself, but the managed infrastructure object may carry configuration that creates exposure if state, output, or pipeline handling is weak. The Terraform and IaC Pipeline Credential Security Guide explains that operational risk.
Risk and Threat Considerations
Terraform resources can create durable security exposure when their configuration is wrong, overly permissive, or left unmanaged after a change. Because resources define real infrastructure, a single insecure declaration can be propagated repeatedly through automated deployments and become part of the live environment.
Failure mechanism: Misconfigured resources, unsafe defaults, or state and plan handling weaknesses can cause persistent drift, overexposure, or unintended destruction, especially when changes are applied at scale.
Impact: The result can be exposed services, excessive privilege, broken isolation, accidental deletion, or a security control that looks correct in code but is weak in production.
When resource integrity depends on signed artifacts, provider trust, or module supply chain quality, compromise can also propagate through the infrastructure pipeline. That is why even seemingly small resource changes deserve strong review discipline and provenance checks.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
CIS Controls v8 and NIST SP 800-53 Rev 5 set the technical controls, while ISO/IEC 27001:2022 defines the regulatory obligations.
| Framework | Control / Reference | Relevance |
|---|---|---|
| CIS Controls v8 | CIS-4 — Secure Configuration of Enterprise Assets and Software | Terraform resources codify configurations that must stay secure and consistent. |
| Recommendation — Standardise and verify resource configurations before they are applied to production. | ||
| NIST SP 800-53 Rev 5 | CM-2 — Baseline Configuration | Terraform resources define controlled baselines for infrastructure state. |
| CM-6 — Configuration Settings | Resource definitions encode the settings that determine security posture. | |
| IA-5 — Authenticator Management | Terraform resources often govern infrastructure that stores or uses secrets and access material. | |
| Recommendation — Use approved baselines so resource changes are reviewed against intended state. Define and enforce secure resource settings through controlled configuration management. Protect resource-linked secrets with managed lifecycle and rotation controls. | ||
| ISO/IEC 27001:2022 | A.8.9 — Configuration management | Terraform resources are a configuration-management mechanism for infrastructure. |
| Recommendation — Maintain resource definitions under change control and review for authorised updates. | ||
Practitioner Guidance
What to watch for: Treat resource definitions as security-relevant change records, not just deployment syntax. Review them for ownership clarity, unintended replacement, and drift between declared and actual state, especially when resources control network exposure, permissions, or environment boundaries.
Governance implication: Assign clear review ownership for resource changes and keep module boundaries narrow enough that teams can reason about the blast radius of a change. A resource that is easy to create should also be easy to understand, validate, and retire.
Practitioner takeaway: If the resource is the unit of infrastructure ownership, then security depends on controlling how that unit is declared, reviewed, and reconciled over time.
Related resources from NHI Mgmt Group
- Should organisations block all non-module Terraform resource creation?
- How should security teams handle Terraform provider upgrades that can change resource behavior and break existing CI/CD pipelines?
- What is the difference between a classic portal resource and a newer portal resource in a Terraform provider?
- How should security teams prevent duplicate Terraform resource definitions from breaking infrastructure changes at scale?
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on October 30, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org