惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Martin Fowler
Martin Fowler
Schneier on Security
Schneier on Security
S
Schneier on Security
A
Arctic Wolf
L
LangChain Blog
T
Threatpost
GbyAI
GbyAI
V2EX - 技术
V2EX - 技术
Jina AI
Jina AI
U
Unit 42
P
Proofpoint News Feed
M
MIT News - Artificial intelligence
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
Spread Privacy
Spread Privacy
F
Fortinet All Blogs
Y
Y Combinator Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
月光博客
月光博客
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
F
Full Disclosure
博客园 - 【当耐特】
S
Secure Thoughts
美团技术团队
N
News | PayPal Newsroom
爱范儿
爱范儿
Latest news
Latest news
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
S
Security @ Cisco Blogs
V
V2EX
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
腾讯CDC
The Hacker News
The Hacker News
V
Vulnerabilities – Threatpost
Cyberwarzone
Cyberwarzone
Google Online Security Blog
Google Online Security Blog
N
Netflix TechBlog - Medium
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Last Watchdog
The Last Watchdog
N
News and Events Feed by Topic
T
Tor Project blog
博客园 - 三生石上(FineUI控件)
Security Archives - TechRepublic
Security Archives - TechRepublic
大猫的无限游戏
大猫的无限游戏
Security Latest
Security Latest

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Build the infrastructure and understand Terraform
Do Ngoc Tuan · 2026-05-14 · via DEV Community

Senerio

In the previous section, we know how to set up Terraform on Ubuntu24.04. Now, in this section we will learn how to use the Terraform to Initialize and manage the infrastructure. Not by using AWS console, but use the CLI instead.

By the end of this article, you'll:
✅ Understand the Terraform workflow
✅ Write .tf file
✅ Create an actual S3 bucket and EC2 on AWS
✅ Understand what a state file
✅ Clean up resources properly

Quick Theory: The Terraform Workflow

Before we dive in, there are 4 commands that we need to know form the core Terraform workflow. You'll use these commands in every project, whether you're creating a simple S3 bucket or a complex multi-tier application with many services on AWS.

terraform init      #Initialize the providers
terraform plan      #See what resources will change
terraform apply     #Build the real insfrastructure
terraform destroy   #Clean up the resources after using

Enter fullscreen mode Exit fullscreen mode

📝 Understanding Terraform Files

Terraform uses files extension .tf written in HCL (HashiCorp Configuration Language). Don't worry - it's much simpler than it sounds!

Basic Structure:

# This is a comment

block_type "label" "name" {
  argument = "value"
  another_argument = 1234
}

Enter fullscreen mode Exit fullscreen mode

Three main block types we'll use when edit the configuration:

terraform - Configuration settings
provider - Which cloud (AWS, Azure, GCP)
resource - What to create (S3, EC2, RDS etc...)
Ok now you see it simlifier than before right. Let's see them in action!

🛠️ Hands-On: Create Your First S3 Bucket

Step 1: Create Your Project Directory

# Create a directory for Terraform project
mkdir -p ~/terraform-project
cd ~/terraform-project

Enter fullscreen mode Exit fullscreen mode

Create mns3.tf

nano mns3.tf # or use your favorite editor vim, vscode, etc...

Step 2: Write Your First Terraform Code

terraform {
  required_version = ">= 1.0"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

provider "aws" {
  region = "ap-southeast-1" #Choose the region that closest your country
}

# Create two S3 buckets
resource "aws_s3_bucket" "logs" {
  bucket = "my-app-logs-shoeshop-2026"

  tags = {
    Name        = "Application Logs"
    Environment = "Development"
    Purpose     = "Logging"
  }
}

resource "aws_s3_bucket" "backups" {
  bucket = "my-app-backups-shoeshop-2026"

  tags = {
    Name        = "Application Backups"
    Environment = "Development"
    Purpose     = "Backup Storage"
  }
}

# Outputs
output "logs_bucket_id" {
  value = aws_s3_bucket.logs.id
}

output "backups_bucket_id" {
  value = aws_s3_bucket.backups.id
}

Enter fullscreen mode Exit fullscreen mode

⚠️ Important: Change the bucket name = "my-app-logs-shoeshop-2026" and "my-app-backups-shoeshop-2026" to differnt name because S3 bucket names must be globally unique across ALL AWS accounts!

Save the file

🚀 The 4 Commands in Action

Now comes the exciting part! Let's run our 4 magic commands.

Command 1: terraform init

This downloads the AWS provider plugin.

terraform init

Enter fullscreen mode Exit fullscreen mode

You'll see:

What just happened?

  • Terraform downloaded the AWS provider plugin
  • Created a .terraform/ directory (hidden folder)
  • Created .terraform.lock.hcl file (locks provider versions) Pro Tip: You only need to run init once per project, or when you add new providers.

Command 2: terraform plan

This show you what Terraform will create (you can preview the change before apply it).

terraform plan

Enter fullscreen mode Exit fullscreen mode

You'll see:


Understanding the output:

  • means "will be created" ~ means "will be modified" (you'll see this later)
  • means "will be destroyed" (known after apply) means AWS will generate this value This is your safety check! Always review the plan before applying.

Command 3: terraform apply

This actually creates the resources on AWS.

terraform apply

Enter fullscreen mode Exit fullscreen mode

Type yes and press Enter.

You'll see:


🎉 Congratulations! You just created your first AWS resource with code!

Verify in AWS Console

Let's confirm it's really there:

Go to AWS S3 Console
You should see two bucket: my-app
Click on it and check the Tags tab - you'll see all the tags you defined!
This is the "enjoy!" moment - you created AWS infrastructure without clicking through the console!

🗂️ Understanding the State File

After running terraform apply, you'll notice a new file: terraform.tfstate

ls -al

Enter fullscreen mode Exit fullscreen mode

You'll see:

.terraform/
.terraform.lock.hcl
main.tf
terraform.tfstate

Enter fullscreen mode Exit fullscreen mode

What is the State File?

The state file is Terraform's memory. It stores:

  • What resources Terraform created
  • Current configuration of those resources
  • Metadata and dependencies Let's peek inside:
cat terraform.tfstate

Enter fullscreen mode Exit fullscreen mode

You'll see JSON with details about your S3 bucket - its name, ARN, region, tags, etc.

Why Does State Matter?

When you run terraform plan or terraform apply again, Terraform:

  • Reads the state file to know what exists
  • Compares it with your .tf files
  • Calculates what needs to change Without state, Terraform wouldn't know what it created!

⚠️ Important State Rules:

Never edit state files manually
Never delete state files (you'll lose track of resources)
Never commit state files to Git (they contain sensitive data)

🧪 Let's Make a Change

Now let's see Terraform's power - making changes to existing infrastructure.

Edit mns3.tf file and add a new tag:

terraform {
  required_version = ">= 1.0"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

provider "aws" {
  region = "ap-southeast-1"
}

# Create two S3 buckets
resource "aws_s3_bucket" "logs" {
  bucket = "my-app-logs-shoeshop-2026"

  tags = {
    Name        = "Application Logs"
    Environment = "Development"
    Purpose     = "Logging"
    LastUpdated = "Today" # <- Add this new tag
  }
}

resource "aws_s3_bucket" "backups" {
  bucket = "my-app-backups-shoeshop-2026"

  tags = {
    Name        = "Application Backups"
    Environment = "Development"
    Purpose     = "Backup Storage"
    LastUpdated = "Today"  # <- Add this new tag
  }
}

# Outputs
output "logs_bucket_id" {
  value = aws_s3_bucket.logs.id
}

output "backups_bucket_id" {
  value = aws_s3_bucket.backups.id
}

Enter fullscreen mode Exit fullscreen mode

Run plan again:
terraform plan
You'll see:

# aws_s3_bucket.backups will be updated in-place
  ~ resource "aws_s3_bucket" "backups" {
        id                          = "my-app-backups-shoeshop-2026"
      ~ tags                        = {
            "Environment" = "Development"
          + "LastUpdated" = "Today"
            "Name"        = "Application Backups"
            "Purpose"     = "Backup Storage"
        }
      ~ tags_all                    = {
          + "LastUpdated" = "Today"
            # (3 unchanged elements hidden)
        }
        # (14 unchanged attributes hidden)

        # (3 unchanged blocks hidden)
    }

  # aws_s3_bucket.logs will be updated in-place
  ~ resource "aws_s3_bucket" "logs" {
        id                          = "my-app-logs-shoeshop-2026"
      ~ tags                        = {
            "Environment" = "Development"
          + "LastUpdated" = "Today"
            "Name"        = "Application Logs"
            "Purpose"     = "Logging"
        }
      ~ tags_all                    = {
          + "LastUpdated" = "Today"
            # (3 unchanged elements hidden)
        }
        # (14 unchanged attributes hidden)

        # (3 unchanged blocks hidden)
    }

Plan: 0 to add, 2 to change, 0 to destroy.

Enter fullscreen mode Exit fullscreen mode


Notice the ~ symbol - it means "modify existing resource"!
Apply the change:
terraform apply
Type yes when prompted.


Check AWS Console - your bucket now has the new tag!


This is Infrastructure as Code magic - you changed infrastructure by editing a text file!

🧹 Command 4: terraform destroy

Always clean up resources you're not using (to avoid unexpected charges).

terraform destroy

Terraform will show what it will delete:

# aws_s3_bucket.logs will be destroyed
  - resource "aws_s3_bucket" "logs" {
      - bucket                      = "my-app-logs-shoeshop-2026" -> null
          - "Environment" = "Development"
          - "LastUpdated" = "Today"
          - "Name"        = "Application Logs"
          - "Purpose"     = "Logging"
        } -> null
          .....
        }
    }

Plan: 0 to add, 0 to change, 2 to destroy.

Enter fullscreen mode Exit fullscreen mode

Type yesto confirm.


Verify in AWS Console - your bucket is gone!

🎓 What You Just Learned

Let's recap what you accomplished:

✅ The Terraform Workflow:
init - Initialize project
plan - Preview changes
apply - Create resources
destroy - Clean up
✅ HCL Basics:
terraform block (configuration)
provider block (cloud provider)
resource block (what to create)
output block (display information)
✅ State Management:

  1. State file tracks resources
  2. Never edit state manually
  3. State enables change detection
    ✅ Real Infrastructure:

  4. Created actual AWS S3 bucket

  5. Modified existing resource

  6. Destroyed resources cleanly