Backend IAM and Access Control
What you'll learn: How to grant Terraform only the minimum permissions it needs to manage remote state backends safely.
The Principle of Least Privilege
When Terraform accesses remote state backends like S3, Azure Storage, or GCS, it needs credentials—but not unlimited power. Think of it like giving a house-sitter a key: they need access to water your plants, but they don't need permission to sell your house.
Least privilege means Terraform gets only the permissions required to read, write, and lock state files—nothing more. This limits damage if credentials are compromised.
What Terraform Actually Needs
For an S3 backend with DynamoDB locking, Terraform requires:
- S3:
s3:GetObject,s3:PutObject,s3:ListBucketon the state bucket - DynamoDB:
dynamodb:PutItem,dynamodb:GetItem,dynamodb:DeleteItemon the lock table
It does not need s3:DeleteBucket, iam:*, or broad admin rights.
Practical IAM Configuration
Create dedicated IAM users or roles for Terraform. Attach policies scoping permissions tightly:
- Restrict actions to only state operations
- Limit resource ARNs to specific buckets/tables
- Use conditions (like IP restrictions) where appropriate
For team environments, use separate credentials per environment (dev, staging, prod) and consider role assumption with time-limited tokens instead of long-lived keys.
Why This Matters
Overly permissive credentials are a security nightmare. If your CI/CD pipeline or developer laptop is compromised, attackers shouldn't be able to delete all cloud resources—just because Terraform had excessive permissions.
Key Takeaway: Always configure IAM policies for Terraform state backends using least privilege—grant only the specific read/write/lock permissions needed for state management, scoped to exact resources.