Terraform provider boundaries and state
Configuration, provider and state
Terraform describes desired infrastructure using configuration files. A provider is a plugin implementing resource operations for a particular API. State maps configured resource addresses to managed remote objects and stores metadata and values. Unlike CDK and SAM, the AWS provider normally operates AWS APIs directly rather than generating a CloudFormation stack. OpenTofu is a separate tool with related syntax; verify provider, backend and version compatibility instead of assuming interchangeability.
A private-bucket configuration
Read this static HCL example: the AWS provider is explicitly scoped to us-east-1, and the public-access block references the bucket ID, creating a dependency. Constraints are illustrative for Terraform 1.x and AWS provider 6.x; no provider was downloaded or tested. In a real project commit the reviewed dependency lock file, pin module versions separately and check the exact provider schema. The example does not configure retention, backups or a backend.
terraform { required_version = ">= 1.10, < 2.0" required_providers { aws = { source = "hashicorp/aws" version = "~> 6.0" } }}provider "aws" { region = "us-east-1"}resource "aws_s3_bucket" "archive" {}resource "aws_s3_bucket_public_access_block" "archive" { bucket = aws_s3_bucket.archive.id block_public_acls = true block_public_policy = true ignore_public_acls = true restrict_public_buckets = true}The plan and state boundary
terraform init installs or locates required components and initializes the backend. terraform plan typically refreshes information from remote objects before proposing changes; it is not guaranteed offline. terraform apply can create, update or destroy resources. A plan may become stale; review exact target scope and approved changes, then replan when inputs change. Use access-controlled encrypted state storage, backups/version history and a locking-capable backend. Sensitive markings hide some display output but do not necessarily remove values from state or saved plans. Do not commit state or plans to Git.
Ownership, migration and drift
Use one lifecycle owner for each resource. CDK and SAM can both generate CloudFormation resources, while Terraform can manage AWS resources through providers. Do not allow two stacks or a Terraform state and a CloudFormation stack to manage the same bucket independently. Import is an ownership/mapping operation, not a backup or automatic configuration migration. Plan a controlled handover, preserve data, review dependencies and verify rollback. Separate application code tests, static checks, provider validation, real plan and provisioning evidence.
Practice
In the lab, a fictional plan proposes replacing a bucket with no backup and an overlapping owner. Reject it, even if syntax is valid. Compare CDK for reusable AWS components, SAM for serverless shorthand and Terraform for provider-based infrastructure. The next chapter builds review and approval into CI/CD.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Terraform provider boundaries and state — knowledge check
Review infrastructure artifacts and evidence without deploying resources.
What maps a configured Terraform address to a managed object?
What creates the dependency in the HCL example?
What must you assume about terraform plan?
How should a team protect shared state?
CloudFormation and Terraform both claim the same bucket. What is the next step?