AWS

Teraform from the scratch

CK CK 3788 
Created at  
1,356 0 0

Terraform for AWS plays a key role in infrastructure as code (IaC), allowing developers to define and manage their AWS resources using a declarative configuration language. This eliminates the need for manual configuration and promotes consistency, scalability, and repeatability. By describing the desired state of your infrastructure in Terraform code, you can automatically provision, configure, and update AWS resources like EC2 instances, S3 buckets, and VPCs, ensuring that your infrastructure is always up-to-date and compliant. 

Here’s a simple guide to getting started with Terraform. This will cover setting up Terraform, configuring a basic environment, and applying changes to create resources.

 

Step 1: Install Terraform

  1. Download the Terraform binary for your operating system from Terraform's website.
  2. Extract the binary and place it in a directory included in your PATH (e.g., /usr/local/bin on macOS/Linux or add the location to PATH on Windows).
  3. Verify installation by running:

    terraform --version

 

Step 2: Set Up Your First Terraform Project

  1. Create a directory for your Terraform configuration:

    mkdir my-terraform-project
    cd my-terraform-project
  2. Initialize Terraform:
    • Create a file, main.tf, to define your infrastructure.
    • Initialize the directory as a Terraform workspace:

      terraform init

 

Step 3: Create a Simple Configuration

Here's an example main.tf file to create an AWS EC2 instance. Replace <region> with your desired AWS region.

provider "aws" {
  region = "<region>"
}

resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0" # Amazon Linux AMI
  instance_type = "t2.micro"

  tags = {
    Name = "ExampleInstance"
  }
}

 

Step 4: Set Up Authentication

  • AWS: Terraform uses AWS CLI credentials by default. Make sure you've configured it:

    aws configure

 

Step 5: Initialize and Validate Configuration

  1. Initialize the project to download the necessary providers:

    terraform init
  2. Validate the configuration to ensure syntax and configuration are correct:

    terraform validate

 

Step 6: Review Changes

  • Plan the changes to preview what will be created, modified, or destroyed:

    terraform plan

 

Step 7: Apply Changes

  • Apply the configuration to create the resources:

    terraform apply
  • Type yes when prompted to confirm the changes.

 

Step 8: Verify and Destroy Resources

  1. Verify the created resources in your AWS Management Console.
  2. Destroy the resources when you're done (to avoid charges):

    terraform destroy
  • Again, type yes to confirm.

 

Summary

  1. Install Terraform and create a project directory.
  2. Define infrastructure in main.tf.
  3. Initialize, plan, apply, and optionally destroy resources.

This guide should get you started! Let me know if you want more examples or advanced topics, like managing states or using modules.

Tags AWS Architecture Teraform Teraform Example Teraform Guide Teraform for AWS Facebook X
Comments 0
Similar posts
  1. Product Marketing & Recommendation Architecture in AWS for e-commerce website
    10,736
  2. Predictable Ad Spend: Architecting Pacing at Hyperscale
    422
  3. AWS Lambda Example based on Teraform
    900
  4. Simple AWS ECS example based on Teraform
    988
  5. Measuring Ad Viewability: AWS Architectures for Programmatic Accountability
    476
  6. Ad Tech Multi-Tenancy: A Spectrum of Isolation Architectures on AWS
    331
  7. Enterprise Data Lake Architecture based on AWS
    10,405
  8. Media sharing service architecture in AWS
    10,366
  9. Web front-end architecture in AWS for e-commerce website
    365
  10. Web Application Hosting provides the reliable, scalable, secure, and high-performance infrastructure
    10,615
  11. Time series processing architecture in AWS
    10,559
  12. Synchronous online gaming architecutre in AWS - Highly Available, Scalable & Elastic to support Millions of Players
    10,417
  13. Secure and Scalable LAMP Service Architecture in AWS
    10,660
  14. Live streaming / Static Content & Media Service based on AWS
    10,655
  15. Large scale messenger service architecture in AWS - Slack case study
    11,674
  16. Large scale computing based on huge data sets in AWS
    10,609
  17. Image Moderation Chatbot - a serverless chatbot on AWS that monitors chat channels and removes images suggestive or explicit image
    10,425
  18. Financial services grid computing in AWS
    10,354
  19. File synchronization service architecture in AWS
    10,376
  20. Fault Tolerance & High Availability based on multi Availability zones in AWS
    10,805
  21. Disaster recovery solution in AWS for local applications
    11,178
  22. Content Distribution for VOD streaming services in AWS
    10,355
  23. Checkout service architecture in AWS for e-commerce website
    11,009
  24. Batch processing composed of job manager, job store and worker based on AWS
    10,448
  25. AWS Architecture for collecting Click-Through Events on Advertisement serving
    10,374
  26. AWS System Design Example - Instagram Architecture
    1,918
  27. Amagi CLOUDPORT Architecture based on AWS for FAST for channel playout on AWS
    1,318
  1. AWS System Design Example - Instagram Architecture
    1,918
  2. A Python script to create an EC2 Spot instance using boto3
    1,602
  3. A Python/PHP code to deregister anormalous instaces in Amazon ECS
    1,857
  4. Where to get AWS API Key at AWS Management Console?
    1,066
  5. Understanding Amazon Bedrock Agent for AI-based ChatBot
    644
  6. Media sharing service architecture in AWS
    10,366
  7. Enterprise Data Lake Architecture based on AWS
    10,405
  8. "502 Bad Gateway" Error easy to happen at the combination of nginx and node.js in AWS Elastic Beanstalk
    10,487
  9. How to Set Up and Deploy Containerized Applications with AWS ECS
    10,673
  10. Power of Containerized Deployment with AWS ECS
    10,597
  11. FAISS Already Does ANN... So Why Do Top Teams Still Pay for SageMaker?
    309
  12. Recommended Vector DB Structure for Amazon Bedrock Integration
    389
  13. Product Marketing & Recommendation Architecture in AWS for e-commerce website
    10,736
  14. What cause a 502 bad gateway error in AWS environment?
    444
  15. Building an AWS SAM(Serverless Application Model) Project
    898
  16. Check incomplete multipart uploads if AWS S3 storage size is abnormally big huge compared to the origin storage
    11,597
  17. Importing a wild card domain SSL certificate into AWS Certificate Manager
    10,348
  18. AWS Lambda Example based on Teraform
    900
  19. Simple AWS ECS example based on Teraform
    988
  20. Web front-end architecture in AWS for e-commerce website
    365
  21. Web Application Hosting provides the reliable, scalable, secure, and high-performance infrastructure
    10,615
  22. Time series processing architecture in AWS
    10,559
  23. Synchronous online gaming architecutre in AWS - Highly Available, Scalable & Elastic to support Millions of Players
    10,417
  24. Secure and Scalable LAMP Service Architecture in AWS
    10,660
  25. Live streaming / Static Content & Media Service based on AWS
    10,655
  26. Large scale messenger service architecture in AWS - Slack case study
    11,674
  27. Large scale computing based on huge data sets in AWS
    10,609
  28. Image Moderation Chatbot - a serverless chatbot on AWS that monitors chat channels and removes images suggestive or explicit image
    10,425
  29. Financial services grid computing in AWS
    10,354
  30. File synchronization service architecture in AWS
    10,376
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    40
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    34
  3. How do I create animated background for Google Meet?
    20,611
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    244
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    94
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    157
  7. Array of arguments passed to script in PHP
    90
  8. Invalid Auction Storms in Ad Tech
    98
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    202
  10. The Two Clocks of Ad Server Architecture
    70
  11. Frequency Cap Architecture Overview
    514
  12. Collecting Proof-of-Play from 100,000 Screens
    146
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    287
  14. What is RedisVL?
    109
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    230
  16. TPU & GPU Cluster Management Tools
    243
  17. The Concept of Scaffolding in AI Agents
    233
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    583
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    258
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    339
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    202
  22. Machine Learning: Training vs. Ranking
    221
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    222
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    195
  25. Designing a Data Curation System Around a Vector Database
    220
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    256
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    656
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    195
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    217
  30. Understanding Data Lineage
    260