<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ahkar Swe</title>
    <description>The latest articles on Forem by Ahkar Swe (@ahkarswe).</description>
    <link>https://forem.com/ahkarswe</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3824056%2Fbc58cbdb-f719-451d-920f-6cfe512e220e.png</url>
      <title>Forem: Ahkar Swe</title>
      <link>https://forem.com/ahkarswe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ahkarswe"/>
    <language>en</language>
    <item>
      <title>🚀 Automating Terraform with CI/CD (GitHub Actions) — Part 10</title>
      <dc:creator>Ahkar Swe</dc:creator>
      <pubDate>Thu, 16 Apr 2026 00:30:00 +0000</pubDate>
      <link>https://forem.com/ahkarswe/automating-terraform-with-cicd-github-actions-part-10-4g8o</link>
      <guid>https://forem.com/ahkarswe/automating-terraform-with-cicd-github-actions-part-10-4g8o</guid>
      <description>&lt;p&gt;So far in this series, we’ve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Learned Terraform fundamentals&lt;/li&gt;
&lt;li&gt;Built reusable modules&lt;/li&gt;
&lt;li&gt;Managed remote state&lt;/li&gt;
&lt;li&gt;Designed production-ready structure&lt;/li&gt;
&lt;li&gt;Compared workspaces vs environments&lt;/li&gt;
&lt;li&gt;Deployed VPC and real AWS architecture&lt;/li&gt;
&lt;li&gt;Built a 3-tier system&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we complete the journey 🔥&lt;/p&gt;

&lt;p&gt;👉 Automating Terraform using CI/CD&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 What You’ll Learn
&lt;/h2&gt;

&lt;p&gt;In this guide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why CI/CD is important for Terraform&lt;/li&gt;
&lt;li&gt;How to automate Terraform with GitHub Actions&lt;/li&gt;
&lt;li&gt;Safe deployment practices&lt;/li&gt;
&lt;li&gt;Production workflow&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔁 Why CI/CD for Terraform?
&lt;/h2&gt;

&lt;p&gt;Without CI/CD:&lt;/p&gt;

&lt;p&gt;❌ Manual deployment&lt;br&gt;
❌ Human errors&lt;br&gt;
❌ No consistency&lt;/p&gt;

&lt;p&gt;With CI/CD:&lt;/p&gt;

&lt;p&gt;✅ Automated workflows&lt;br&gt;
✅ Consistent deployments&lt;br&gt;
✅ Safer infrastructure changes&lt;/p&gt;




&lt;h2&gt;
  
  
  🏗️ CI/CD Workflow Overview
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Developer → Git Push
        ↓
GitHub Actions
        ↓
Terraform Plan
        ↓
Approval (optional)
        ↓
Terraform Apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  📁 Project Structure
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.github/
  workflows/
    terraform.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 GitHub Actions Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Terraform CI/CD&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;terraform&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;

    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Checkout&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v3&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Setup Terraform&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;hashicorp/setup-terraform@v2&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Terraform Init&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform init&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Terraform Plan&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform plan&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Terraform Apply&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform apply -auto-approve&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔐 Security Best Practices
&lt;/h2&gt;

&lt;p&gt;👉 Never hardcode AWS credentials&lt;/p&gt;

&lt;p&gt;Use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GitHub Secrets&lt;/li&gt;
&lt;li&gt;IAM roles&lt;/li&gt;
&lt;li&gt;Least privilege access&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧠 DevOps Insight
&lt;/h2&gt;

&lt;p&gt;CI/CD enables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Team collaboration&lt;/li&gt;
&lt;li&gt;Safe infrastructure changes&lt;/li&gt;
&lt;li&gt;Faster deployments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 This is how modern DevOps teams operate.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ Important Note
&lt;/h2&gt;

&lt;p&gt;Avoid:&lt;/p&gt;

&lt;p&gt;❌ Direct auto-apply in production&lt;br&gt;
❌ No approval process&lt;/p&gt;

&lt;p&gt;👉 Always use review before apply&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 What You Just Learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Terraform automation&lt;/li&gt;
&lt;li&gt;CI/CD pipeline design&lt;/li&gt;
&lt;li&gt;Production workflow&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  💡 Final Thought
&lt;/h2&gt;

&lt;p&gt;You started with:&lt;/p&gt;

&lt;p&gt;👉 “What is Terraform?”&lt;/p&gt;

&lt;p&gt;Now you can:&lt;/p&gt;

&lt;p&gt;👉 Design and automate real infrastructure systems&lt;/p&gt;




&lt;h2&gt;
  
  
  🎉 Terraform Journey Complete
&lt;/h2&gt;

&lt;p&gt;You have completed:&lt;/p&gt;

&lt;p&gt;✔ Infrastructure as Code fundamentals&lt;br&gt;
✔ AWS resource provisioning&lt;br&gt;
✔ Modular Terraform design&lt;br&gt;
✔ Remote state management&lt;br&gt;
✔ Production repository structure&lt;br&gt;
✔ Real architecture (VPC + 3-tier)&lt;br&gt;
✔ CI/CD automation&lt;/p&gt;

&lt;p&gt;👉 You are now &lt;strong&gt;production-ready with Terraform&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 What’s Next?
&lt;/h2&gt;

&lt;p&gt;Continue your journey:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Terraform + Kubernetes (EKS)&lt;/li&gt;
&lt;li&gt;Terraform + Docker&lt;/li&gt;
&lt;li&gt;Advanced DevOps pipelines&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  👨‍💻 About the Author
&lt;/h2&gt;

&lt;p&gt;Hi, I’m Ahkar — sharing DevOps, AWS, and Infrastructure knowledge 🚀&lt;/p&gt;

&lt;p&gt;🌐 &lt;a href="https://mindgnite.com" rel="noopener noreferrer"&gt;https://mindgnite.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow for more DevOps content 🔥&lt;/p&gt;




&lt;h2&gt;
  
  
  📚 Terraform Learning Series (Complete)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Part 1: Introduction&lt;/li&gt;
&lt;li&gt;Part 2: Setup&lt;/li&gt;
&lt;li&gt;Part 3: EC2&lt;/li&gt;
&lt;li&gt;Part 4: Variables&lt;/li&gt;
&lt;li&gt;Part 5: Modules &amp;amp; Backend&lt;/li&gt;
&lt;li&gt;Part 6: Production Structure&lt;/li&gt;
&lt;li&gt;Part 7: Workspaces vs Environments&lt;/li&gt;
&lt;li&gt;Part 8: VPC Lab&lt;/li&gt;
&lt;li&gt;Part 9: 3-Tier Architecture&lt;/li&gt;
&lt;li&gt;Part 10: CI/CD Automation (this post)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  👉 You’ve completed the full journey 🚀
&lt;/h2&gt;

</description>
      <category>cicd</category>
      <category>devops</category>
      <category>github</category>
      <category>terraform</category>
    </item>
    <item>
      <title>🏗️ Building a 3-Tier Architecture with Terraform (ALB + EC2 + DB) — Part 9</title>
      <dc:creator>Ahkar Swe</dc:creator>
      <pubDate>Wed, 15 Apr 2026 00:30:00 +0000</pubDate>
      <link>https://forem.com/ahkarswe/building-a-3-tier-architecture-with-terraform-alb-ec2-db-part-9-po1</link>
      <guid>https://forem.com/ahkarswe/building-a-3-tier-architecture-with-terraform-alb-ec2-db-part-9-po1</guid>
      <description>&lt;p&gt;So far in this series, we’ve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Built Terraform fundamentals&lt;/li&gt;
&lt;li&gt;Created reusable modules&lt;/li&gt;
&lt;li&gt;Designed production-ready structure&lt;/li&gt;
&lt;li&gt;Compared workspaces vs environments&lt;/li&gt;
&lt;li&gt;Deployed a VPC with Terraform&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now it’s time to build something closer to real production 🔥&lt;/p&gt;

&lt;p&gt;👉 A 3-tier architecture on AWS&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 What You’ll Learn
&lt;/h2&gt;

&lt;p&gt;In this guide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What 3-tier architecture is&lt;/li&gt;
&lt;li&gt;How AWS components work together&lt;/li&gt;
&lt;li&gt;How to design scalable infrastructure&lt;/li&gt;
&lt;li&gt;Terraform-based architecture thinking&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🏗️ What is 3-Tier Architecture?
&lt;/h2&gt;

&lt;p&gt;A 3-tier architecture separates your system into:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Presentation Layer (ALB)
2. Application Layer (EC2)
3. Data Layer (Database)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🌐 Architecture Overview
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Internet
   ↓
ALB (Load Balancer)
   ↓
EC2 Instances (App)
   ↓
RDS (Database)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Layer 1: Load Balancer (ALB)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Handles incoming traffic&lt;/li&gt;
&lt;li&gt;Distributes requests&lt;/li&gt;
&lt;li&gt;Improves availability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Entry point of your system&lt;/p&gt;




&lt;h2&gt;
  
  
  🔹 Layer 2: Application (EC2)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Runs your app (Node.js, PHP, etc.)&lt;/li&gt;
&lt;li&gt;Can scale horizontally&lt;/li&gt;
&lt;li&gt;Connected to ALB&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔹 Layer 3: Database (RDS)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Stores data&lt;/li&gt;
&lt;li&gt;Private (not exposed to internet)&lt;/li&gt;
&lt;li&gt;Secured via subnet + security group&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧠 DevOps Insight
&lt;/h2&gt;

&lt;p&gt;👉 This architecture is used in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Web applications&lt;/li&gt;
&lt;li&gt;SaaS platforms&lt;/li&gt;
&lt;li&gt;Enterprise systems&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔧 Terraform Design Approach
&lt;/h2&gt;

&lt;p&gt;Instead of writing everything in one file:&lt;/p&gt;

&lt;p&gt;👉 Break into components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;modules/
  vpc/
  alb/
  ec2/
  rds/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Example: ALB Resource
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_lb"&lt;/span&gt; &lt;span class="s2"&gt;"app_lb"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;               &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"app-lb"&lt;/span&gt;
  &lt;span class="nx"&gt;load_balancer_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"application"&lt;/span&gt;
  &lt;span class="nx"&gt;subnets&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;public_subnets&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Example: EC2 Layer
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_instance"&lt;/span&gt; &lt;span class="s2"&gt;"app"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;ami&lt;/span&gt;           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ami&lt;/span&gt;
  &lt;span class="nx"&gt;instance_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"t2.micro"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Example: RDS
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_db_instance"&lt;/span&gt; &lt;span class="s2"&gt;"db"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;allocated_storage&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
  &lt;span class="nx"&gt;engine&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"mysql"&lt;/span&gt;
  &lt;span class="nx"&gt;instance_class&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"db.t3.micro"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔐 Security Design (Important)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;ALB → Public&lt;/li&gt;
&lt;li&gt;EC2 → Private&lt;/li&gt;
&lt;li&gt;RDS → Private&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Use Security Groups to control access&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 Deployment Flow
&lt;/h2&gt;



&lt;p&gt;```bash id="3tier7"&lt;br&gt;
terraform init&lt;br&gt;
terraform plan&lt;br&gt;
terraform apply&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


---

## 🧠 What You Just Built

You now understand:

* Real-world AWS architecture
* Multi-layer infrastructure
* Terraform design patterns

👉 This is production-level thinking.

---

## ⚠️ Important Note

3-tier architecture introduces:

* More cost
* More complexity

👉 Always destroy resources when not needed

---

## 🎯 What You Just Learned

* 3-tier system design
* AWS service integration
* Terraform architecture mindset

---

## 💡 Final Thought

This is where Terraform becomes powerful.

👉 You are no longer deploying resources.

👉 You are designing systems.

---

## 🚀 What’s Next?

Next, we go automation:

👉 Terraform + CI/CD (GitHub Actions)

---

## 👨‍💻 About the Author

Hi, I’m Ahkar — sharing DevOps, AWS, and Infrastructure knowledge 🚀

🌐 https://mindgnite.com

Follow for more Terraform content 🔥

---

## 📚 Terraform Learning Series

* Part 8: VPC Lab
* Part 9: 3-Tier Architecture (this post)
* Part 10: CI/CD with Terraform

👉 Follow to continue 🚀
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>architecture</category>
      <category>aws</category>
      <category>terraform</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>🌐 Deploying an AWS VPC with Terraform (Hands-On Lab) — Part 8</title>
      <dc:creator>Ahkar Swe</dc:creator>
      <pubDate>Tue, 14 Apr 2026 00:30:00 +0000</pubDate>
      <link>https://forem.com/ahkarswe/deploying-an-aws-vpc-with-terraform-hands-on-lab-part-8-npj</link>
      <guid>https://forem.com/ahkarswe/deploying-an-aws-vpc-with-terraform-hands-on-lab-part-8-npj</guid>
      <description>&lt;p&gt;So far in this series, we’ve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Built Terraform fundamentals&lt;/li&gt;
&lt;li&gt;Created reusable modules&lt;/li&gt;
&lt;li&gt;Managed remote state&lt;/li&gt;
&lt;li&gt;Designed production-ready structure&lt;/li&gt;
&lt;li&gt;Compared workspaces vs environments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now it’s time to build something real 🔥&lt;/p&gt;

&lt;p&gt;👉 A complete AWS VPC using Terraform&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 What You’ll Learn
&lt;/h2&gt;

&lt;p&gt;In this guide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What a VPC is&lt;/li&gt;
&lt;li&gt;How to design basic network architecture&lt;/li&gt;
&lt;li&gt;Create VPC using Terraform&lt;/li&gt;
&lt;li&gt;Add subnet and internet gateway&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🌐 What is a VPC?
&lt;/h2&gt;

&lt;p&gt;A VPC (Virtual Private Cloud) is:&lt;/p&gt;

&lt;p&gt;👉 Your own isolated network in AWS&lt;/p&gt;

&lt;p&gt;It allows you to control:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IP range&lt;/li&gt;
&lt;li&gt;Subnets&lt;/li&gt;
&lt;li&gt;Routing&lt;/li&gt;
&lt;li&gt;Internet access&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🏗️ Architecture We’ll Build
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;VPC (10.0.0.0/16)
│
├── Public Subnet (10.0.1.0/24)
│   └── Internet Gateway
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  📁 Project Structure
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vpc-lab/
  main.tf
  variables.tf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Step 1: Provider Configuration
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;provider&lt;/span&gt; &lt;span class="s2"&gt;"aws"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;region&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ap-southeast-1"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Step 2: Create VPC
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_vpc"&lt;/span&gt; &lt;span class="s2"&gt;"main"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;cidr_block&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"10.0.0.0/16"&lt;/span&gt;

  &lt;span class="nx"&gt;tags&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"terraform-vpc"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Step 3: Create Subnet
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_subnet"&lt;/span&gt; &lt;span class="s2"&gt;"public"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;vpc_id&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aws_vpc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;cidr_block&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"10.0.1.0/24"&lt;/span&gt;

  &lt;span class="nx"&gt;tags&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"public-subnet"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Step 4: Internet Gateway
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_internet_gateway"&lt;/span&gt; &lt;span class="s2"&gt;"igw"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;vpc_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aws_vpc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;

  &lt;span class="nx"&gt;tags&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"main-igw"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Step 5: Route Table
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_route_table"&lt;/span&gt; &lt;span class="s2"&gt;"public"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;vpc_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aws_vpc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Step 6: Add Internet Route
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_route"&lt;/span&gt; &lt;span class="s2"&gt;"internet_access"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;route_table_id&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aws_route_table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;public&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;destination_cidr_block&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"0.0.0.0/0"&lt;/span&gt;
  &lt;span class="nx"&gt;gateway_id&lt;/span&gt;             &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aws_internet_gateway&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;igw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Step 7: Associate Subnet
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_route_table_association"&lt;/span&gt; &lt;span class="s2"&gt;"a"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;subnet_id&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aws_subnet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;public&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;route_table_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aws_route_table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;public&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🚀 Deploy Infrastructure
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform init
terraform plan
terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🧠 What You Just Built
&lt;/h2&gt;

&lt;p&gt;You now have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A VPC&lt;/li&gt;
&lt;li&gt;A public subnet&lt;/li&gt;
&lt;li&gt;Internet access via IGW&lt;/li&gt;
&lt;li&gt;Routing configuration&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 This is the foundation of AWS networking.&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 DevOps Insight
&lt;/h2&gt;

&lt;p&gt;Almost every AWS architecture starts with:&lt;/p&gt;

&lt;p&gt;👉 VPC → Subnets → Routing&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ Important Note
&lt;/h2&gt;

&lt;p&gt;Always clean up resources:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Avoid unnecessary AWS cost.&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 What You Just Learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Basic AWS networking&lt;/li&gt;
&lt;li&gt;Terraform resource relationships&lt;/li&gt;
&lt;li&gt;Real infrastructure deployment&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  💡 Final Thought
&lt;/h2&gt;

&lt;p&gt;This is no longer theory.&lt;/p&gt;

&lt;p&gt;👉 You are now building real cloud infrastructure.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 What’s Next?
&lt;/h2&gt;

&lt;p&gt;Next, we go deeper:&lt;/p&gt;

&lt;p&gt;👉 Build a 3-tier architecture (ALB + EC2 + DB)&lt;/p&gt;




&lt;h2&gt;
  
  
  👨‍💻 About the Author
&lt;/h2&gt;

&lt;p&gt;Hi, I’m Ahkar — sharing DevOps, AWS, and Infrastructure knowledge 🚀&lt;/p&gt;

&lt;p&gt;🌐 &lt;a href="https://mindgnite.com" rel="noopener noreferrer"&gt;https://mindgnite.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow for more Terraform content 🔥&lt;/p&gt;




&lt;h2&gt;
  
  
  📚 Terraform Learning Series
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Part 7: Workspaces vs Environments&lt;/li&gt;
&lt;li&gt;Part 8: VPC Lab (this post)&lt;/li&gt;
&lt;li&gt;Part 9: 3-Tier Architecture 🔥&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Follow to continue 🚀&lt;/p&gt;

</description>
      <category>aws</category>
      <category>networking</category>
      <category>terraform</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>⚔️ Terraform Workspaces vs Environments — Part 7</title>
      <dc:creator>Ahkar Swe</dc:creator>
      <pubDate>Mon, 13 Apr 2026 00:30:00 +0000</pubDate>
      <link>https://forem.com/ahkarswe/terraform-workspaces-vs-environments-part-7-4ank</link>
      <guid>https://forem.com/ahkarswe/terraform-workspaces-vs-environments-part-7-4ank</guid>
      <description>&lt;p&gt;So far in this series, we’ve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deployed infrastructure with Terraform&lt;/li&gt;
&lt;li&gt;Used variables and outputs&lt;/li&gt;
&lt;li&gt;Built reusable modules&lt;/li&gt;
&lt;li&gt;Implemented remote backend (S3 + DynamoDB)&lt;/li&gt;
&lt;li&gt;Structured projects using dev / staging / prod&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, there’s an important question 👇&lt;/p&gt;

&lt;p&gt;👉 Should you use &lt;strong&gt;Terraform Workspaces&lt;/strong&gt; instead of environments?&lt;/p&gt;

&lt;p&gt;Let’s break it down.&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 What You’ll Learn
&lt;/h2&gt;

&lt;p&gt;In this guide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What Terraform workspaces are&lt;/li&gt;
&lt;li&gt;How they work&lt;/li&gt;
&lt;li&gt;Differences between workspaces and environments&lt;/li&gt;
&lt;li&gt;When to use each approach&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔹 What is a Workspace?
&lt;/h2&gt;

&lt;p&gt;A workspace is:&lt;/p&gt;

&lt;p&gt;👉 A way to manage multiple state files using the same Terraform configuration&lt;/p&gt;

&lt;p&gt;By default, Terraform uses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;terraform&lt;/span&gt; &lt;span class="nx"&gt;workspace&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;default
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Creating Workspaces
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;terraform&lt;/span&gt; &lt;span class="nx"&gt;workspace&lt;/span&gt; &lt;span class="nx"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;dev&lt;/span&gt;
&lt;span class="k"&gt;terraform&lt;/span&gt; &lt;span class="nx"&gt;workspace&lt;/span&gt; &lt;span class="nx"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;prod&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Switch between them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;terraform&lt;/span&gt; &lt;span class="nx"&gt;workspace&lt;/span&gt; &lt;span class="nx"&gt;select&lt;/span&gt; &lt;span class="nx"&gt;dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Each workspace represents a separate state.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔹 How Workspaces Work
&lt;/h2&gt;

&lt;p&gt;Terraform stores state per workspace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform.tfstate.d/
  dev/
  prod/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Same code&lt;br&gt;
👉 Different state files&lt;/p&gt;


&lt;h2&gt;
  
  
  🔁 Example
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_instance"&lt;/span&gt; &lt;span class="s2"&gt;"example"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;instance_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;terraform&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;workspace&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"prod"&lt;/span&gt; &lt;span class="err"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"t3.medium"&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"t2.micro"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;👉 Behavior changes based on workspace.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 DevOps Insight
&lt;/h2&gt;

&lt;p&gt;Workspaces allow you to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Avoid duplicating code&lt;/li&gt;
&lt;li&gt;Manage multiple environments quickly&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  ⚠️ The Problem
&lt;/h2&gt;

&lt;p&gt;Workspaces seem simple… but in real-world projects 👇&lt;/p&gt;

&lt;p&gt;❌ Not very clear for teams&lt;br&gt;
❌ Easy to select wrong workspace&lt;br&gt;
❌ Hard to manage at scale&lt;/p&gt;


&lt;h2&gt;
  
  
  🏗️ Environment-Based Approach (Recap)
&lt;/h2&gt;

&lt;p&gt;From Part 6:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;environments/
  dev/
  staging/
  prod/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Each environment has:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Separate folder&lt;/li&gt;
&lt;li&gt;Separate backend&lt;/li&gt;
&lt;li&gt;Clear structure&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ⚔️ Workspaces vs Environments
&lt;/h2&gt;

&lt;p&gt;Let’s compare 👇&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Workspaces → simple but limited&lt;/li&gt;
&lt;li&gt;Environments → structured and scalable&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧠 DevOps Insight
&lt;/h2&gt;

&lt;p&gt;👉 Workspaces are useful for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Quick testing&lt;/li&gt;
&lt;li&gt;Personal projects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Environments are better for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Production systems&lt;/li&gt;
&lt;li&gt;Team collaboration&lt;/li&gt;
&lt;li&gt;Long-term infrastructure&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🎯 Recommendation
&lt;/h2&gt;

&lt;p&gt;👉 Use &lt;strong&gt;environment-based structure&lt;/strong&gt; for real-world projects&lt;/p&gt;

&lt;p&gt;👉 Use &lt;strong&gt;workspaces only for simple use cases&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ Important Note
&lt;/h2&gt;

&lt;p&gt;Do not rely only on workspaces for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Production infrastructure&lt;/li&gt;
&lt;li&gt;Team-based deployments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 It increases risk.&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 What You Just Learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;How Terraform workspaces work&lt;/li&gt;
&lt;li&gt;Their advantages and limitations&lt;/li&gt;
&lt;li&gt;Why environments are preferred in production&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  💡 Final Thought
&lt;/h2&gt;

&lt;p&gt;Terraform gives you multiple ways to solve a problem.&lt;/p&gt;

&lt;p&gt;👉 But not all approaches scale.&lt;/p&gt;

&lt;p&gt;Choosing the right structure is what separates:&lt;/p&gt;

&lt;p&gt;👉 beginners from real DevOps engineers&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 What’s Next?
&lt;/h2&gt;

&lt;p&gt;Next, we go hands-on 🔥&lt;/p&gt;

&lt;p&gt;👉 Build a real AWS VPC using Terraform&lt;br&gt;
👉 Apply everything you’ve learned so far&lt;/p&gt;




&lt;h2&gt;
  
  
  👨‍💻 About the Author
&lt;/h2&gt;

&lt;p&gt;Hi, I’m Ahkar — sharing DevOps, AWS, and Infrastructure knowledge 🚀&lt;/p&gt;

&lt;p&gt;🌐 &lt;a href="https://mindgnite.com" rel="noopener noreferrer"&gt;https://mindgnite.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow for more Terraform content 🔥&lt;/p&gt;




&lt;h2&gt;
  
  
  📚 Terraform Learning Series
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Part 1: Why Terraform&lt;/li&gt;
&lt;li&gt;Part 2: Setup Guide&lt;/li&gt;
&lt;li&gt;Part 3: First EC2&lt;/li&gt;
&lt;li&gt;Part 4: Variables &amp;amp; Outputs&lt;/li&gt;
&lt;li&gt;Part 5: Modules &amp;amp; Backend&lt;/li&gt;
&lt;li&gt;Part 6: Production Structure&lt;/li&gt;
&lt;li&gt;Part 7: Workspaces vs Environments (this post)&lt;/li&gt;
&lt;li&gt;Part 8: VPC Lab (coming next)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Follow to continue 🚀&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>devops</category>
      <category>terraform</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>🏗️ Terraform Production Structure (Dev / Staging / Prod) — Part 6</title>
      <dc:creator>Ahkar Swe</dc:creator>
      <pubDate>Sun, 12 Apr 2026 03:34:37 +0000</pubDate>
      <link>https://forem.com/ahkarswe/terraform-production-structure-dev-staging-prod-part-6-4p3c</link>
      <guid>https://forem.com/ahkarswe/terraform-production-structure-dev-staging-prod-part-6-4p3c</guid>
      <description>&lt;p&gt;Terraform Production Structure (Dev / Staging / Prod) — Part 6&lt;/p&gt;

&lt;p&gt;So far, you've learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;EC2 deployment&lt;/li&gt;
&lt;li&gt;Variables and outputs&lt;/li&gt;
&lt;li&gt;Modules&lt;/li&gt;
&lt;li&gt;Remote backend (S3 + DynamoDB)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now it’s time to answer a critical question 👇&lt;/p&gt;

&lt;p&gt;👉 How do real companies organize Terraform projects?&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 What You’ll Learn
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Multi-environment setup (dev / staging / prod)&lt;/li&gt;
&lt;li&gt;Professional Terraform folder structure&lt;/li&gt;
&lt;li&gt;How teams manage infrastructure at scale&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ❗ The Problem
&lt;/h2&gt;

&lt;p&gt;Your current setup might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;main.tf
variables.tf
outputs.tf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Works for learning&lt;br&gt;
👉 Breaks in production ❌&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No environment separation&lt;/li&gt;
&lt;li&gt;Hard to manage changes&lt;/li&gt;
&lt;li&gt;Risk of deploying to wrong environment&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🏗️ Production Structure
&lt;/h2&gt;

&lt;p&gt;Here’s how professionals structure Terraform:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform-project/
│
├── modules/
│   └── ec2/
│       ├── main.tf
│       ├── variables.tf
│       └── outputs.tf
│
├── environments/
│   ├── dev/
│   │   ├── main.tf
│   │   └── backend.tf
│   │
│   ├── staging/
│   │   ├── main.tf
│   │   └── backend.tf
│   │
│   └── prod/
│       ├── main.tf
│       └── backend.tf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Why This Structure?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1️⃣ Separation of Environments
&lt;/h3&gt;

&lt;p&gt;Each environment is isolated:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;dev → testing&lt;/li&gt;
&lt;li&gt;staging → pre-production&lt;/li&gt;
&lt;li&gt;prod → live system&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Prevents mistakes like deploying test code to production.&lt;/p&gt;




&lt;h3&gt;
  
  
  2️⃣ Reuse with Modules
&lt;/h3&gt;

&lt;p&gt;All environments use the same module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="s2"&gt;"ec2"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"../../modules/ec2"&lt;/span&gt;

  &lt;span class="nx"&gt;instance_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"t2.micro"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Consistent infrastructure across environments.&lt;/p&gt;




&lt;h3&gt;
  
  
  3️⃣ Independent State Files
&lt;/h3&gt;

&lt;p&gt;Each environment has its own backend:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;terraform&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;backend&lt;/span&gt; &lt;span class="s2"&gt;"s3"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;bucket&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"tf-state-bucket"&lt;/span&gt;
    &lt;span class="nx"&gt;key&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"dev/terraform.tfstate"&lt;/span&gt;
    &lt;span class="nx"&gt;region&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ap-southeast-1"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Dev and prod never conflict.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔄 Workflow Example
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Deploy to Dev
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;environments/dev
terraform init
terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Deploy to Production
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;environments/prod
terraform init
terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Same code, different environment.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 DevOps Insight
&lt;/h2&gt;

&lt;p&gt;This structure enables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Safe deployments&lt;/li&gt;
&lt;li&gt;Team collaboration&lt;/li&gt;
&lt;li&gt;Scalable infrastructure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 This is how companies manage cloud at scale.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ Common Mistakes
&lt;/h2&gt;

&lt;p&gt;❌ Single folder for all environments&lt;br&gt;
❌ Sharing same state file&lt;br&gt;
❌ Hardcoding values&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 What You Just Learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Multi-environment Terraform design&lt;/li&gt;
&lt;li&gt;Production folder structure&lt;/li&gt;
&lt;li&gt;Environment isolation best practices&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  💡 Final Thought
&lt;/h2&gt;

&lt;p&gt;Infrastructure is not just code.&lt;/p&gt;

&lt;p&gt;👉 It’s a system that must be safe, scalable, and predictable.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 What’s Next?
&lt;/h2&gt;

&lt;p&gt;Next, we’ll go deeper:&lt;/p&gt;

&lt;p&gt;👉 Terraform workspaces vs environments&lt;br&gt;
👉 When to use each approach&lt;/p&gt;




&lt;h2&gt;
  
  
  📚 Terraform Learning Series
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Part 1: Introduction&lt;/li&gt;
&lt;li&gt;Part 2: Setup&lt;/li&gt;
&lt;li&gt;Part 3: EC2&lt;/li&gt;
&lt;li&gt;Part 4: Variables&lt;/li&gt;
&lt;li&gt;Part 5: Modules + Backend&lt;/li&gt;
&lt;li&gt;Part 6: Production Structure (this post)&lt;/li&gt;
&lt;li&gt;Part 7: Workspaces vs Environments&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Follow for more DevOps content 🔥&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>devops</category>
      <category>terraform</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>⚙️ Terraform Modules &amp; Remote Backend (S3 + DynamoDB) — Part 5</title>
      <dc:creator>Ahkar Swe</dc:creator>
      <pubDate>Fri, 03 Apr 2026 04:58:00 +0000</pubDate>
      <link>https://forem.com/ahkarswe/terraform-modules-remote-backend-s3-dynamodb-part-5-106b</link>
      <guid>https://forem.com/ahkarswe/terraform-modules-remote-backend-s3-dynamodb-part-5-106b</guid>
      <description>&lt;p&gt;So far in this series, we’ve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deployed an EC2 instance&lt;/li&gt;
&lt;li&gt;Used variables and outputs&lt;/li&gt;
&lt;li&gt;Understood Terraform state&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But there’s a problem 👇&lt;/p&gt;

&lt;p&gt;👉 Your code is still not production-ready&lt;/p&gt;

&lt;p&gt;Let’s fix that.&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 What You’ll Learn
&lt;/h2&gt;

&lt;p&gt;In this guide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What Terraform modules are&lt;/li&gt;
&lt;li&gt;How to structure reusable code&lt;/li&gt;
&lt;li&gt;Why remote state is critical&lt;/li&gt;
&lt;li&gt;How to use S3 + DynamoDB backend&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔁 Why Modules Matter
&lt;/h2&gt;

&lt;p&gt;Right now, your code is probably:&lt;/p&gt;

&lt;p&gt;👉 All in one file&lt;br&gt;
👉 Hard to reuse&lt;br&gt;
👉 Difficult to manage&lt;/p&gt;


&lt;h2&gt;
  
  
  🔹 What is a Module?
&lt;/h2&gt;

&lt;p&gt;A module is:&lt;/p&gt;

&lt;p&gt;👉 A reusable Terraform component&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;modules/
  ec2/
    main.tf
    variables.tf
    outputs.tf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Using a Module
&lt;/h2&gt;

&lt;p&gt;In your root &lt;code&gt;main.tf&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="s2"&gt;"ec2"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"../../modules/ec2"&lt;/span&gt;

  &lt;span class="nx"&gt;instance_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"t2.micro"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Instead of writing everything again, you reuse code.&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 DevOps Insight
&lt;/h2&gt;

&lt;p&gt;Modules help you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Standardize infrastructure&lt;/li&gt;
&lt;li&gt;Reduce duplication&lt;/li&gt;
&lt;li&gt;Scale across environments&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧠 Terraform State Problem
&lt;/h2&gt;

&lt;p&gt;So far, your state is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform.tfstate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Stored locally ❌&lt;/p&gt;

&lt;p&gt;Problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Not safe&lt;/li&gt;
&lt;li&gt;Not shareable&lt;/li&gt;
&lt;li&gt;Not suitable for teams&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔹 Solution — Remote Backend
&lt;/h2&gt;

&lt;p&gt;We move state to:&lt;/p&gt;

&lt;p&gt;👉 S3 bucket&lt;br&gt;
👉 DynamoDB (for locking)&lt;/p&gt;


&lt;h2&gt;
  
  
  🔹 Backend Configuration
&lt;/h2&gt;

&lt;p&gt;Create &lt;code&gt;backend.tf&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;terraform&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;backend&lt;/span&gt; &lt;span class="s2"&gt;"s3"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;bucket&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my-terraform-state-bucket"&lt;/span&gt;
    &lt;span class="nx"&gt;key&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"dev/terraform.tfstate"&lt;/span&gt;
    &lt;span class="nx"&gt;region&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ap-southeast-1"&lt;/span&gt;
    &lt;span class="nx"&gt;dynamodb_table&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"terraform-lock"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Initialize Backend
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Terraform will migrate state to S3.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔒 Why DynamoDB?
&lt;/h2&gt;

&lt;p&gt;DynamoDB provides:&lt;/p&gt;

&lt;p&gt;👉 State locking&lt;/p&gt;

&lt;p&gt;This prevents:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiple users applying at same time&lt;/li&gt;
&lt;li&gt;State corruption&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧠 What You Just Built
&lt;/h2&gt;

&lt;p&gt;You now have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Modular Terraform code&lt;/li&gt;
&lt;li&gt;Remote state storage (S3)&lt;/li&gt;
&lt;li&gt;State locking (DynamoDB)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 This is how real DevOps teams work.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ Important Note
&lt;/h2&gt;

&lt;p&gt;Never commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform.tfstate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Add to &lt;code&gt;.gitignore&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 What You Just Learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Modules for reusable infrastructure&lt;/li&gt;
&lt;li&gt;Remote backend best practices&lt;/li&gt;
&lt;li&gt;Production-ready Terraform setup&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  💡 Final Thought
&lt;/h2&gt;

&lt;p&gt;You are no longer writing scripts.&lt;/p&gt;

&lt;p&gt;You are designing:&lt;/p&gt;

&lt;p&gt;👉 scalable infrastructure systems&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 What’s Next?
&lt;/h2&gt;

&lt;p&gt;Next, we’ll go deeper into:&lt;/p&gt;

&lt;p&gt;👉 Multi-environment structure (dev / prod)&lt;br&gt;
👉 Professional Terraform repo design&lt;/p&gt;




&lt;h2&gt;
  
  
  👨‍💻 About the Author
&lt;/h2&gt;

&lt;p&gt;Hi, I’m Ahkar — sharing DevOps, AWS, and Infrastructure knowledge 🚀&lt;/p&gt;

&lt;p&gt;🌐 &lt;a href="https://mindgnite.com" rel="noopener noreferrer"&gt;https://mindgnite.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow for more Terraform content 🔥&lt;/p&gt;




&lt;h2&gt;
  
  
  📚 Terraform Learning Series
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Part 1: Why Terraform&lt;/li&gt;
&lt;li&gt;Part 2: Setup Guide&lt;/li&gt;
&lt;li&gt;Part 3: First EC2&lt;/li&gt;
&lt;li&gt;Part 4: Variables &amp;amp; State&lt;/li&gt;
&lt;li&gt;Part 5: Modules &amp;amp; Backend (this post)&lt;/li&gt;
&lt;li&gt;Part 6: Production Structure (coming next)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Follow to continue 🚀&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
      <category>terraform</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>🔁 Terraform Variables, Outputs &amp; State — Make Your Code Reusable (Part 4)</title>
      <dc:creator>Ahkar Swe</dc:creator>
      <pubDate>Fri, 27 Mar 2026 06:15:27 +0000</pubDate>
      <link>https://forem.com/ahkarswe/terraform-variables-outputs-state-make-your-code-reusable-part-4-13ed</link>
      <guid>https://forem.com/ahkarswe/terraform-variables-outputs-state-make-your-code-reusable-part-4-13ed</guid>
      <description>&lt;p&gt;In the previous post, you deployed your first EC2 instance using Terraform.&lt;/p&gt;

&lt;p&gt;That was a huge step.&lt;/p&gt;

&lt;p&gt;But if you look at your code now, you’ll notice something:&lt;/p&gt;

&lt;p&gt;👉 Everything is hardcoded&lt;br&gt;
👉 It’s not reusable&lt;br&gt;
👉 It’s not scalable&lt;/p&gt;

&lt;p&gt;Let’s fix that.&lt;/p&gt;


&lt;h2&gt;
  
  
  🎯 What You’ll Learn
&lt;/h2&gt;

&lt;p&gt;In this guide, you’ll understand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to use variables&lt;/li&gt;
&lt;li&gt;How to output useful data&lt;/li&gt;
&lt;li&gt;How Terraform tracks infrastructure (state)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are core concepts used in real-world DevOps projects.&lt;/p&gt;


&lt;h2&gt;
  
  
  🔁 Why Variables Matter
&lt;/h2&gt;

&lt;p&gt;Right now, your code probably looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;instance_type&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"t2.micro"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is fine for learning — but not for real projects.&lt;/p&gt;

&lt;p&gt;👉 What if you want:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;different instance types for dev vs production?&lt;/li&gt;
&lt;li&gt;reusable code?&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔹 Step 1 — Create Variables
&lt;/h2&gt;

&lt;p&gt;Create a new file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;variables.tf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"instance_type"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;default&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"t2.micro"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Step 2 — Use Variables in Your Code
&lt;/h2&gt;

&lt;p&gt;Update your &lt;code&gt;main.tf&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_instance"&lt;/span&gt; &lt;span class="s2"&gt;"web_server"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;ami&lt;/span&gt;           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ami-xxxxxxxxxxxx"&lt;/span&gt;
  &lt;span class="nx"&gt;instance_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;instance_type&lt;/span&gt;

  &lt;span class="nx"&gt;tags&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"terraform-server"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Now your code is flexible.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔹 Step 3 — Override with terraform.tfvars
&lt;/h2&gt;

&lt;p&gt;Create:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;terraform.tfvars
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;instance_type&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"t3.micro"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Now you can change behavior &lt;strong&gt;without editing code&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  📤 Outputs — See What Terraform Created
&lt;/h2&gt;

&lt;p&gt;Sometimes you want to know:&lt;/p&gt;

&lt;p&gt;👉 What is the public IP of my EC2?&lt;/p&gt;

&lt;p&gt;Create:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;outputs.tf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;output&lt;/span&gt; &lt;span class="s2"&gt;"instance_public_ip"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aws_instance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;web_server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;public_ip&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;&lt;span class="py"&gt;instance_public_ip&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;18.xxx.xxx.xxx&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🧠 Terraform State — The Brain of Terraform
&lt;/h2&gt;

&lt;p&gt;Terraform stores everything in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform.tfstate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file tracks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;what resources exist&lt;/li&gt;
&lt;li&gt;their IDs&lt;/li&gt;
&lt;li&gt;their current state&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔍 Inspect Your State
&lt;/h2&gt;

&lt;p&gt;Run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform state list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws_instance.web_server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔎 Deep Dive
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform state show aws_instance.web_server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 You’ll see full details of your EC2.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ Important Insight
&lt;/h2&gt;

&lt;p&gt;Terraform doesn’t query AWS every time.&lt;/p&gt;

&lt;p&gt;👉 It relies on &lt;strong&gt;state file&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That’s why state is critical in real systems.&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 DevOps Insight
&lt;/h2&gt;

&lt;p&gt;Right now, your setup is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Local state → terraform.tfstate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works for learning.&lt;/p&gt;

&lt;p&gt;But in real teams:&lt;/p&gt;

&lt;p&gt;❌ Not safe&lt;br&gt;
❌ Not shareable&lt;/p&gt;

&lt;p&gt;👉 In the next post, we’ll fix this using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;S3 backend&lt;/li&gt;
&lt;li&gt;DynamoDB locking&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🎯 What You Just Learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;How to use variables&lt;/li&gt;
&lt;li&gt;How to make Terraform reusable&lt;/li&gt;
&lt;li&gt;How outputs work&lt;/li&gt;
&lt;li&gt;How Terraform state works&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  💡 Final Thought
&lt;/h2&gt;

&lt;p&gt;You are no longer just writing Terraform.&lt;/p&gt;

&lt;p&gt;You are now:&lt;/p&gt;

&lt;p&gt;👉 designing reusable infrastructure&lt;/p&gt;

&lt;p&gt;That’s the difference between beginner and real DevOps.&lt;/p&gt;




&lt;h2&gt;
  
  
  👨‍💻 About the Author
&lt;/h2&gt;

&lt;p&gt;Hi, I’m Ahkar — sharing DevOps, AWS, and Infrastructure knowledge to help others grow 🚀&lt;/p&gt;

&lt;p&gt;I publish bilingual content (Myanmar 🇲🇲 + English 🇺🇸) focused on real-world cloud learning.&lt;/p&gt;

&lt;p&gt;🌐 Blog: &lt;a href="https://mindgnite.com" rel="noopener noreferrer"&gt;https://mindgnite.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you found this helpful, consider following for more Terraform &amp;amp; DevOps content 🔥&lt;/p&gt;




&lt;h2&gt;
  
  
  📚 Terraform Learning Series
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Part 1: Why Terraform&lt;/li&gt;
&lt;li&gt;Part 2: Setup Guide&lt;/li&gt;
&lt;li&gt;Part 3: First EC2 Deployment&lt;/li&gt;
&lt;li&gt;Part 4: Variables, Outputs &amp;amp; State (this post)&lt;/li&gt;
&lt;li&gt;Part 5: Modules &amp;amp; Remote Backend (coming next)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Follow to continue the journey 🚀&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>devops</category>
      <category>terraform</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>🖥️Deploy Your First EC2 with Terraform (Step-by-Step Guide) — Part 3</title>
      <dc:creator>Ahkar Swe</dc:creator>
      <pubDate>Mon, 23 Mar 2026 06:26:59 +0000</pubDate>
      <link>https://forem.com/ahkarswe/deploy-your-first-ec2-with-terraform-step-by-step-guide-part-3-2np4</link>
      <guid>https://forem.com/ahkarswe/deploy-your-first-ec2-with-terraform-step-by-step-guide-part-3-2np4</guid>
      <description>&lt;p&gt;In the previous post, you set up Terraform and AWS CLI.&lt;/p&gt;

&lt;p&gt;Now it’s time to do what really matters:&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Build real infrastructure using code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By the end of this guide, you’ll launch an EC2 instance using Terraform — no AWS Console clicks required.&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 What You’ll Build
&lt;/h2&gt;

&lt;p&gt;We’ll create:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An EC2 instance&lt;/li&gt;
&lt;li&gt;Using Terraform&lt;/li&gt;
&lt;li&gt;In just a few lines of code&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📁 Step 1 — Create Project Structure
&lt;/h2&gt;

&lt;p&gt;Create a new folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;terraform-ec2
&lt;span class="nb"&gt;cd &lt;/span&gt;terraform-ec2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;provider.tf main.tf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Step 2 — Configure AWS Provider
&lt;/h2&gt;

&lt;p&gt;Open &lt;code&gt;provider.tf&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;provider&lt;/span&gt; &lt;span class="s2"&gt;"aws"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;region&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ap-southeast-1"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Step 3 — Create EC2 Instance
&lt;/h2&gt;

&lt;p&gt;Open &lt;code&gt;main.tf&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_instance"&lt;/span&gt; &lt;span class="s2"&gt;"web_server"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;ami&lt;/span&gt;           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ami-xxxxxxxxxxxx"&lt;/span&gt;
  &lt;span class="nx"&gt;instance_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"t2.micro"&lt;/span&gt;

  &lt;span class="nx"&gt;tags&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"terraform-server"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;⚠️ Replace the AMI with a valid one from your AWS region.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🔹 Step 4 — Initialize Terraform
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This downloads the AWS provider and prepares your project.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔹 Step 5 — Preview Changes
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform plan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Terraform will show something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Plan: 1 to add, 0 to change, 0 to destroy.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 This means Terraform is about to create 1 resource (your EC2).&lt;/p&gt;




&lt;h2&gt;
  
  
  🔹 Step 6 — Apply (Create Infrastructure)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔍 Verify in AWS Console
&lt;/h2&gt;

&lt;p&gt;Go to:&lt;/p&gt;

&lt;p&gt;👉 AWS Console → EC2 → Instances&lt;/p&gt;

&lt;p&gt;You should see:&lt;/p&gt;

&lt;p&gt;👉 Your instance running 🎉&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 What Just Happened?
&lt;/h2&gt;

&lt;p&gt;Terraform just:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Read your &lt;code&gt;.tf&lt;/code&gt; files&lt;/li&gt;
&lt;li&gt;Compared desired state vs current state&lt;/li&gt;
&lt;li&gt;Called AWS API&lt;/li&gt;
&lt;li&gt;Created your EC2 instance&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;👉 This is Infrastructure as Code in action.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ Common Issue — AMI Not Found
&lt;/h2&gt;

&lt;p&gt;You might see this error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;InvalidAMIID.NotFound
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why?
&lt;/h3&gt;

&lt;p&gt;AMI IDs are &lt;strong&gt;region-specific&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  ✅ Fix
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Go to AWS Console → EC2 → AMIs&lt;/li&gt;
&lt;li&gt;Copy a valid AMI ID for your region&lt;/li&gt;
&lt;li&gt;Replace it in your code&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  💡 DevOps Insight
&lt;/h2&gt;

&lt;p&gt;Right now, we are using a &lt;strong&gt;hardcoded AMI&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This works for learning, but in production:&lt;/p&gt;

&lt;p&gt;❌ Not reusable&lt;br&gt;
❌ Not flexible&lt;/p&gt;

&lt;p&gt;👉 In the next posts, we’ll fix this using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variables&lt;/li&gt;
&lt;li&gt;Data sources (dynamic AMI selection)&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🧹 Clean Up (Important)
&lt;/h2&gt;

&lt;p&gt;To delete your infrastructure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Always clean up to avoid unnecessary AWS charges.&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 What You Just Learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;How to create an EC2 with Terraform&lt;/li&gt;
&lt;li&gt;How &lt;code&gt;init&lt;/code&gt;, &lt;code&gt;plan&lt;/code&gt;, and &lt;code&gt;apply&lt;/code&gt; work&lt;/li&gt;
&lt;li&gt;How Terraform interacts with AWS&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  💡 Final Thought
&lt;/h2&gt;

&lt;p&gt;You just replaced:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;clicking in AWS Console&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;with:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;writing infrastructure as code&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That’s a major step toward becoming a DevOps engineer 🚀&lt;/p&gt;




&lt;h2&gt;
  
  
  👨‍💻 About the Author
&lt;/h2&gt;

&lt;p&gt;Hi, I’m Ahkar — sharing DevOps, AWS, and Infrastructure knowledge to help others grow 🚀&lt;/p&gt;

&lt;p&gt;I publish bilingual content (Myanmar 🇲🇲 + English 🇺🇸) focused on real-world cloud learning.&lt;/p&gt;

&lt;p&gt;🌐 Blog: &lt;a href="https://mindgnite.com" rel="noopener noreferrer"&gt;https://mindgnite.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you found this helpful, consider following for more Terraform &amp;amp; DevOps content 🔥&lt;/p&gt;




&lt;h2&gt;
  
  
  📚 Terraform Learning Series
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Part 1: Why Terraform&lt;/li&gt;
&lt;li&gt;Part 2: Setup Guide&lt;/li&gt;
&lt;li&gt;Part 3: First EC2 Deployment (this post)&lt;/li&gt;
&lt;li&gt;Part 4: Variables, Outputs &amp;amp; State (coming next)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Follow to continue the journey 🚀&lt;/p&gt;

</description>
      <category>aws</category>
      <category>beginners</category>
      <category>terraform</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>🛠️ Terraform Setup Guide: Install Terraform, AWS CLI &amp; Prepare Your DevOps Environment (Part 2)</title>
      <dc:creator>Ahkar Swe</dc:creator>
      <pubDate>Sat, 21 Mar 2026 01:35:02 +0000</pubDate>
      <link>https://forem.com/ahkarswe/terraform-setup-guide-install-terraform-aws-cli-prepare-your-devops-environment-part-2-el5</link>
      <guid>https://forem.com/ahkarswe/terraform-setup-guide-install-terraform-aws-cli-prepare-your-devops-environment-part-2-el5</guid>
      <description>&lt;p&gt;In the previous post, we talked about &lt;strong&gt;why Terraform matters&lt;/strong&gt; and how it replaces manual AWS work.&lt;/p&gt;

&lt;p&gt;Now it’s time to set up your environment and get ready to build real infrastructure.&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 What You’ll Do in This Guide
&lt;/h2&gt;

&lt;p&gt;By the end of this post, you will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install Terraform&lt;/li&gt;
&lt;li&gt;Configure AWS CLI&lt;/li&gt;
&lt;li&gt;Verify your environment&lt;/li&gt;
&lt;li&gt;Run your first Terraform command&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧰 Environment Used
&lt;/h2&gt;

&lt;p&gt;This guide uses:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;WSL Ubuntu / Linux&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;(You can adapt these steps for macOS or Windows as well.)&lt;/p&gt;




&lt;h2&gt;
  
  
  🔹 Step 1 — Install Terraform
&lt;/h2&gt;

&lt;p&gt;Run the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; gnupg software-properties-common

wget &lt;span class="nt"&gt;-O-&lt;/span&gt; https://apt.releases.hashicorp.com/gpg | &lt;span class="se"&gt;\&lt;/span&gt;
gpg &lt;span class="nt"&gt;--dearmor&lt;/span&gt; | &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nb"&gt;sudo tee&lt;/span&gt; /usr/share/keyrings/hashicorp-archive-keyring.gpg

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
https://apt.releases.hashicorp.com &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;lsb_release &lt;span class="nt"&gt;-cs&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; main"&lt;/span&gt; | &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nb"&gt;sudo tee&lt;/span&gt; /etc/apt/sources.list.d/hashicorp.list

&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;terraform
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  ✅ Verify Installation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expected output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Terraform v1.x.x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Step 2 — Install AWS CLI
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;awscli &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Step 3 — Configure AWS Credentials
&lt;/h2&gt;

&lt;p&gt;Run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws configure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AWS Access Key ID
AWS Secret Access Key
Region (e.g. ap-southeast-1)
Output format (json)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔍 Test AWS Connection
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws sts get-caller-identity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If successful, you’ll see your AWS account details.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔹 Step 4 — Create Your First Terraform Project
&lt;/h2&gt;

&lt;p&gt;Create a new folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;terraform-test
&lt;span class="nb"&gt;cd &lt;/span&gt;terraform-test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;main.tf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;provider&lt;/span&gt; &lt;span class="s2"&gt;"aws"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;region&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ap-southeast-1"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔹 Step 5 — Initialize Terraform
&lt;/h2&gt;

&lt;p&gt;Run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expected output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Terraform has been successfully initialized!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ⚠️ Common Errors (From Real Experience)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ❌ AWS credentials not working
&lt;/h3&gt;

&lt;p&gt;Fix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws configure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  ❌ Network / STS error
&lt;/h3&gt;

&lt;p&gt;Check:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws sts get-caller-identity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  ❌ Terraform not found
&lt;/h3&gt;

&lt;p&gt;Check:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🎯 What You Just Completed
&lt;/h2&gt;

&lt;p&gt;You now have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Terraform installed&lt;/li&gt;
&lt;li&gt;AWS CLI configured&lt;/li&gt;
&lt;li&gt;Working environment&lt;/li&gt;
&lt;li&gt;Verified setup&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 You are ready to build real infrastructure.&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 DevOps Insight
&lt;/h2&gt;

&lt;p&gt;A correct setup saves hours of debugging later.&lt;/p&gt;

&lt;p&gt;Before writing Terraform code, always verify:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform version
aws sts get-caller-identity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🚀 What’s Next?
&lt;/h2&gt;

&lt;p&gt;Now that your environment is ready, let’s build something real.&lt;/p&gt;

&lt;p&gt;In the next post, we’ll:&lt;/p&gt;

&lt;p&gt;👉 Deploy your &lt;strong&gt;first EC2 instance using Terraform&lt;/strong&gt;&lt;br&gt;
👉 Understand &lt;code&gt;plan&lt;/code&gt; and &lt;code&gt;apply&lt;/code&gt; in action&lt;br&gt;
👉 See real infrastructure created from code&lt;/p&gt;

&lt;p&gt;This is where you move from setup → real DevOps work 🔥&lt;/p&gt;




&lt;h2&gt;
  
  
  👨‍💻 About the Author
&lt;/h2&gt;

&lt;p&gt;Hi, I’m Ahkar — sharing DevOps, AWS, and Infrastructure knowledge to help others grow 🚀&lt;/p&gt;

&lt;p&gt;I publish bilingual content (Myanmar 🇲🇲 + English 🇺🇸) focused on real-world cloud learning.&lt;/p&gt;

&lt;p&gt;🌐 Blog: &lt;a href="https://mindgnite.com" rel="noopener noreferrer"&gt;https://mindgnite.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you found this helpful, consider following for more Terraform &amp;amp; DevOps content 🔥&lt;/p&gt;




&lt;h2&gt;
  
  
  📚 Terraform Learning Series
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Part 1: Why Terraform&lt;/li&gt;
&lt;li&gt;Part 2: Setup Guide (this post)&lt;/li&gt;
&lt;li&gt;Part 3: First EC2 Deployment (coming next)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Follow to continue the journey 🚀&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
      <category>terraform</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>🚀 Terraform for Beginners: Stop Clicking AWS Console — Start Building Infrastructure Like a DevOps Engineer</title>
      <dc:creator>Ahkar Swe</dc:creator>
      <pubDate>Thu, 19 Mar 2026 06:18:05 +0000</pubDate>
      <link>https://forem.com/ahkarswe/terraform-for-beginners-stop-clicking-aws-console-start-building-infrastructure-like-a-devops-hgj</link>
      <guid>https://forem.com/ahkarswe/terraform-for-beginners-stop-clicking-aws-console-start-building-infrastructure-like-a-devops-hgj</guid>
      <description>&lt;p&gt;When I first started using AWS, I did everything manually:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click EC2&lt;/li&gt;
&lt;li&gt;Launch instance&lt;/li&gt;
&lt;li&gt;Configure security group&lt;/li&gt;
&lt;li&gt;Repeat again… and again&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It worked — until it didn’t.&lt;/p&gt;

&lt;p&gt;I couldn’t reproduce environments.&lt;br&gt;
I made mistakes.&lt;br&gt;
And scaling? Impossible.&lt;/p&gt;

&lt;p&gt;That’s when I discovered Terraform.&lt;/p&gt;


&lt;h2&gt;
  
  
  🔰 What is Terraform?
&lt;/h2&gt;

&lt;p&gt;Terraform is an &lt;strong&gt;Infrastructure as Code (IaC)&lt;/strong&gt; tool that lets you define cloud infrastructure using code.&lt;/p&gt;

&lt;p&gt;Instead of clicking in AWS Console, you write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_instance"&lt;/span&gt; &lt;span class="s2"&gt;"web"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;instance_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"t2.micro"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And Terraform builds it for you.&lt;/p&gt;




&lt;h2&gt;
  
  
  ❌ The Problem with Manual AWS Setup
&lt;/h2&gt;

&lt;p&gt;If you're still using the console:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can’t version control infrastructure&lt;/li&gt;
&lt;li&gt;You can’t easily replicate environments&lt;/li&gt;
&lt;li&gt;You will eventually make mistakes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This becomes a serious problem in real projects.&lt;/p&gt;




&lt;h2&gt;
  
  
  ✅ Why DevOps Engineers Use Terraform
&lt;/h2&gt;

&lt;p&gt;Terraform solves all of that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✔ Reproducible infrastructure&lt;/li&gt;
&lt;li&gt;✔ Version-controlled (Git)&lt;/li&gt;
&lt;li&gt;✔ Automated deployments&lt;/li&gt;
&lt;li&gt;✔ Multi-environment support&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ⚙️ Terraform Workflow (Core Concept)
&lt;/h2&gt;

&lt;p&gt;Every Terraform project follows this flow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform init
terraform plan
terraform apply
terraform destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What each command does:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;init&lt;/code&gt; → prepares your project&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;plan&lt;/code&gt; → shows what will happen&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;apply&lt;/code&gt; → creates infrastructure&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;destroy&lt;/code&gt; → removes everything&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📁 Your First Terraform Project Structure
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform-aws-lab/
├── provider.tf
├── main.tf
├── variables.tf
└── outputs.tf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🎯 What You Just Learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What Terraform is&lt;/li&gt;
&lt;li&gt;Why Infrastructure as Code matters&lt;/li&gt;
&lt;li&gt;How Terraform replaces manual AWS work&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  💡 Final Thought
&lt;/h2&gt;

&lt;p&gt;If you're serious about DevOps, stop thinking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“How do I click this in AWS?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Start thinking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“How do I define this in code?”&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🚀 What’s Next?
&lt;/h2&gt;

&lt;p&gt;In the next post, we’ll go hands-on:&lt;/p&gt;

&lt;p&gt;👉 Install Terraform + AWS CLI&lt;br&gt;
👉 Configure your environment&lt;br&gt;
👉 Deploy your first EC2 using Terraform&lt;/p&gt;

&lt;p&gt;Follow along — this is where things get real 🔥&lt;/p&gt;




&lt;h2&gt;
  
  
  👨‍💻 About the Author
&lt;/h2&gt;

&lt;p&gt;Hi, I’m Ahkar — sharing DevOps, AWS, and Infrastructure knowledge to help others grow 🚀&lt;/p&gt;

&lt;p&gt;I publish bilingual content (Myanmar 🇲🇲 + English 🇺🇸) focused on real-world cloud learning.&lt;/p&gt;

&lt;p&gt;🌐 Blog: &lt;a href="https://mindgnite.com" rel="noopener noreferrer"&gt;https://mindgnite.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you found this helpful, consider following for more Terraform &amp;amp; DevOps content 🔥&lt;/p&gt;




&lt;h2&gt;
  
  
  📚 Terraform Learning Series
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Part 1: Why Terraform (this post)&lt;/li&gt;
&lt;li&gt;Part 2: Setup Guide (coming next)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Follow to continue the journey 🚀&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
