What is AWS Terraform?
✅ Terraform in simple words
Terraform is an Infrastructure as Code (IaC) tool by HashiCorp.
You write infrastructure in declarative config files (HCL), and Terraform creates/updates/destroys resources safely. HashiCorp Developer+1
Think of it like:
“Git for infrastructure” — your AWS setup becomes version-controlled code.
Why Terraform is needed (Real-world reasons)
1) Repeatable environments
Create identical dev / stage / prod using the same code.
2) Change control + audit
Infra changes are reviewed in PRs and tracked in Git.
3) Safer deployments (plan → apply)
Terraform shows what will change before it changes it.
4) Avoid manual console mistakes
No “clicked wrong region / deleted wrong bucket” surprises.
Basic Example: Create S3 Bucket + Allow One Role Access
✅ What we will build
-
Create an S3 bucket
-
Block public access
-
Add a bucket policy that allows one IAM role to:
-
List the bucket
-
Read/Write objects
-
AWS bucket policies are a standard way to grant access to buckets. AWS Documentation+1
📁 Folder Structure
1️⃣ main.tf
Notes:
-
aws_s3_bucketcreates the bucket. Terraform Registry -
aws_s3_bucket_policyattaches the policy to the bucket. Terraform Registry
2️⃣ variables.tf
3️⃣ outputs.tf
▶️ How to Run
1) Set variables (example)
2) Initialize / Plan / Apply
✅ Summary (Interview-ready)
-
Terraform is IaC that manages infra lifecycle using declarative code. HashiCorp Developer+1
-
You define AWS resources like
aws_s3_bucketand attach policies usingaws_s3_bucket_policy. Terraform Registry+1 -
To give a role access to a bucket, you use an S3 bucket policy (resource-based policy) listing the role as a principal. AWS Documentation+1
No comments:
Post a Comment