<?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>DEV Community: Prajwal KP</title>
    <description>The latest articles on DEV Community by Prajwal KP (@prajwal_kp).</description>
    <link>https://dev.to/prajwal_kp</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%2F1827356%2Fb9b29e6e-aede-4b70-ad7f-bfc1ac49a680.png</url>
      <title>DEV Community: Prajwal KP</title>
      <link>https://dev.to/prajwal_kp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/prajwal_kp"/>
    <language>en</language>
    <item>
      <title>Brew Your Own Compiler: Building LLVM/Clang from Source on Any OS!</title>
      <dc:creator>Prajwal KP</dc:creator>
      <pubDate>Sun, 14 Sep 2025 13:47:36 +0000</pubDate>
      <link>https://dev.to/prajwal_kp/brew-your-own-compiler-building-llvmclang-from-source-on-any-os-4kh8</link>
      <guid>https://dev.to/prajwal_kp/brew-your-own-compiler-building-llvmclang-from-source-on-any-os-4kh8</guid>
      <description>&lt;p&gt;Building LLVM/Clang from Source: Ubuntu, Fedora, Arch, Windows, macOS&lt;br&gt;
Why build LLVM/Clang from source? Because pre-built binaries are like instant coffee functional, but you miss the aroma of roasting your own beans! Let’s brew the freshest compiler toolchain for your system, whether it’s Linux, Windows, or macOS.&lt;/p&gt;

&lt;p&gt;👋 Hey there! I'm Prajwal from Bengaluru a relentless explorer in computing.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Started with crafting sleek, user-focused web apps, then dove deep into infrastructure automation and DevOps.&lt;/li&gt;
&lt;li&gt;Now passionate about systems programming, compiler engineering, and the Rust ecosystem.&lt;/li&gt;
&lt;li&gt;I thrive where software meets hardware: building safe, fast, and efficient code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;✨ Turning caffeine into code (and occasional bugs) since 2023 &lt;br&gt;
🔭 Interests: Systems programming • Compilers • The Rust ecosystem🦀 Advocate for: Safe, fast, and reliable software craftsmanship&lt;br&gt;
🤝 Open to collaborate on: Rust, low-level projects, compiler toolchains&lt;br&gt;
💡 Still hands-on with: TypeScript, Go, DevOps, Web Development but my heart beats in &lt;code&gt;cargo run&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;🧑‍💻 Tech I use:    Rust | Go | C/C++ | Java | TypeScript | React/Next.js | Linux | Docker | Kubernetes | Bash | Git &lt;/p&gt;

&lt;p&gt;⚙️ What drives me:    &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Systems Programming: kernel dev, OS work, drivers, performance tuning
&lt;/li&gt;
&lt;li&gt;Compiler Construction: language design, parsing, LLVM, optimizations
&lt;/li&gt;
&lt;li&gt;DevOps: modern infra, automation, CI/CD workflows
&lt;/li&gt;
&lt;li&gt;The Rust &amp;amp; Go Philosophy: safety, concurrency, and zero-cost abstractions
&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;Prerequisites by OS&lt;br&gt;
Ubuntu / Debian&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update
sudo apt install -y build-essential git cmake ninja-build \
    python3-dev libtinfo-dev libxml2-dev zlib1g-dev \
    libedit-dev swig curl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Installs GCC/g++, CMake, Ninja, Python headers, and necessary dev libraries.&lt;/p&gt;

&lt;p&gt;Fedora&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo dnf install -y @development-tools git cmake ninja-build \
    python3-devel ncurses-devel libxml2-devel zlib-devel \
    libedit-devel swig curl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Uses Fedora’s package groups and development headers.&lt;/p&gt;

&lt;p&gt;Arch Linux&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo pacman -Syu --needed base-devel git cmake ninja \
    python ncurses libxml2 zlib libedit swig curl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Uses pacman and Arch-specific base-devel group.&lt;/p&gt;

&lt;p&gt;Windows&lt;br&gt;
Requirements:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Visual Studio 2019 or newer (Community Edition OK)&lt;/li&gt;
&lt;li&gt;Latest CMake (comes with recent Visual Studio)&lt;/li&gt;
&lt;li&gt;Git for Windows&lt;/li&gt;
&lt;li&gt;Python 3.x (from &lt;a href="https://python.org" rel="noopener noreferrer"&gt;https://python.org&lt;/a&gt; or Microsoft Store)&lt;/li&gt;
&lt;li&gt;Optional: Ninja build system&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open x64 Native Tools Command Prompt for VS.&lt;/li&gt;
&lt;li&gt;Install Git for Windows and ensure git is in your PATH.&lt;/li&gt;
&lt;li&gt;Clone the repository:git clone --depth 1 &lt;a href="https://github.com/llvm/llvm-project.git" rel="noopener noreferrer"&gt;https://github.com/llvm/llvm-project.git&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;cd llvm-project&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Create a build directory:mkdir build&lt;br&gt;
&lt;code&gt;cd build&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Configure with CMake and Visual Studio:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cmake -G "Visual Studio 17 2022" -A x64 ../llvm ^
  -DCMAKE_BUILD_TYPE=Release ^
  -DLLVM_ENABLE_PROJECTS="clang;lld" ^
  -DLLVM_ENABLE_ASSERTIONS=ON
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Ninja (if installed): Use -G "Ninja" instead.&lt;/p&gt;

&lt;p&gt;Build LLVM (all targets in Release mode):&lt;br&gt;
&lt;code&gt;cmake --build . --config Release -- /m&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Optionally run tests:&lt;br&gt;
&lt;code&gt;ctest -C Release&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Install:&lt;br&gt;
&lt;code&gt;cmake --install . --config Release&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For full instructions, see LLVM + Visual Studio Setup.&lt;/p&gt;

&lt;p&gt;macOS&lt;br&gt;
Requirements:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Xcode (install from App Store)&lt;/li&gt;
&lt;li&gt;Homebrew (&lt;a href="https://brew.sh" rel="noopener noreferrer"&gt;https://brew.sh&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Install tools:brew install cmake ninja git python3 swig curl&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Some systems may need:&lt;br&gt;
&lt;code&gt;brew install bzip2 xz zlib lz4 zstd coreutils make&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Clone LLVM:git clone --depth 1 &lt;a href="https://github.com/llvm/llvm-project.git" rel="noopener noreferrer"&gt;https://github.com/llvm/llvm-project.git&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;cd llvm-project&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Create a build directory:&lt;br&gt;
&lt;code&gt;mkdir build &amp;amp;&amp;amp; cd build&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Configure the build:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cmake -G Ninja ../llvm \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_INSTALL_PREFIX=/usr/local \
  -DLLVM_ENABLE_PROJECTS="clang;lld" \
  -DLLVM_ENABLE_ASSERTIONS=ON
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Build:ninja&lt;br&gt;
Run tests:&lt;br&gt;
&lt;code&gt;ninja check-llvm&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Install (may require sudo):&lt;br&gt;
&lt;code&gt;sudo ninja install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;macOS builds use Clang and Xcode-provided SDKs by default.&lt;/p&gt;
&lt;h3&gt;
  
  
  General Build and Project Structure
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;These steps are the same across all platforms (use platform-specific package install and generator):&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Clone Repository:  git clone --depth 1 &lt;a href="https://github.com/llvm/llvm-project.git" rel="noopener noreferrer"&gt;https://github.com/llvm/llvm-project.git&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;cd llvm-project&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Out-of-Source Build:&lt;br&gt;
&lt;code&gt;mkdir build &amp;amp;&amp;amp; cd build&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CMake Configuration:cmake -G Ninja ../llvm \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_INSTALL_PREFIX=/usr/local \
  -DLLVM_ENABLE_PROJECTS="clang;lld" \
  -DLLVM_TARGETS_TO_BUILD="X86" \
  -DLLVM_ENABLE_ASSERTIONS=ON
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use -G "Visual Studio 17 2022" and -A x64 on Windows.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Build:&lt;br&gt;&lt;br&gt;
Linux/macOS: &lt;code&gt;ninja&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Windows:&lt;br&gt;
&lt;code&gt;cmake --build . --config Release -- /m&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Run Tests (Optional):&lt;/p&gt;

&lt;p&gt;Linux/macOS: &lt;code&gt;ninja check-llvm&lt;/code&gt;&lt;br&gt;
Windows: &lt;code&gt;ctest -C Release&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Install:&lt;br&gt;&lt;br&gt;
Linux/macOS: &lt;code&gt;sudo ninja install&lt;/code&gt;&lt;br&gt;
Windows: &lt;code&gt;cmake --install . --config Release&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Platform-Specific Notes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Windows: Only Visual Studio builds are officially supported. If forced to use MinGW, expect compatibility issues.&lt;/li&gt;
&lt;li&gt;macOS: Must have Xcode's command-line tools. Some library locations may differ (Homebrew paths).&lt;/li&gt;
&lt;li&gt;Linux: Most distros already provide LLVM as packages; building source is for custom/bleeding-edge needs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Management: Uninstallation and Upgrades
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Linux/macOS
&lt;/h4&gt;

&lt;p&gt;Use install_manifest.txt after install to track files:cd build&lt;br&gt;
sudo xargs rm -vf &amp;lt; install_manifest.txt&lt;/p&gt;

&lt;p&gt;Or, prefer a custom install prefix and simply delete the install directory.&lt;/p&gt;
&lt;h4&gt;
  
  
  Windows
&lt;/h4&gt;

&lt;p&gt;If you used the default CMake install, files were put under the chosen prefix (e.g., C:\Program Files\LLVM).&lt;br&gt;
Use the Windows installer or simply remove the install folder.&lt;/p&gt;
&lt;h3&gt;
  
  
  Checking Installation
&lt;/h3&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;clang --version
llc --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If these return your custom version info, installation succeeded!&lt;br&gt;
Additional Resources&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Congratulations, you’ve just compiled LLVM/Clang like a coding wizard! Now go forth and optimize the world or at least your next project. And if your compiler crashes, don’t blame me; I’m just the guide, not the gremlin in your machine!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>clang</category>
      <category>llvm</category>
      <category>compiler</category>
      <category>systemsprogramming</category>
    </item>
    <item>
      <title>Introduction to AWS CloudFormation: A Beginner's Guide to Infrastructure as Code</title>
      <dc:creator>Prajwal KP</dc:creator>
      <pubDate>Fri, 28 Feb 2025 18:59:29 +0000</pubDate>
      <link>https://dev.to/prajwal_kp/introduction-to-aws-cloudformation-a-beginners-guide-to-infrastructure-as-code-1k6d</link>
      <guid>https://dev.to/prajwal_kp/introduction-to-aws-cloudformation-a-beginners-guide-to-infrastructure-as-code-1k6d</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;AWS CloudFormation is like a service that helps you model and set up your AWS resources so that you can like spend less time managing those resources and more time focusing on what matters most that is your application. The best part is you don't need to individually create and configure AWS resources and figure out what's dependent on what Cloud Formation handles that for you.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;I am Prajwal KP, a second-year student from Bangalore, passionate about full-stack web development and DevOps.&lt;br&gt;
Here is my &lt;a href="https://www.linkedin.com/in/prajwal-kp-04a471285/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;, &lt;a href="https://github.com/Prajwal-kp-18" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  What is AWS CloudFormation?
&lt;/h2&gt;

&lt;p&gt;AWS CloudFormation is an Infrastructure as Code( IAC ) service that allows you to define and provision AWS resources in a declarative way.&lt;br&gt;
We use CloudFormation templates which can be written in YAML or JSON to like describe the desired state of the infrastructure.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why do we need CloudFormation?
&lt;/h2&gt;

&lt;p&gt;Managing cloud infra manually can quickly become complex and error-prone, mainly on a application scale.&lt;/p&gt;

&lt;p&gt;AWS CloudFormation solves this by offering a way to define, deploy, and manage cloud resources using code. Here’s why it’s essential:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automation and Consistency&lt;/strong&gt;: With CloudFormation, we can automate resource creation and ensure every deployment is consistent — no more accidental misconfigurations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Infrastructure as Code (IaC)&lt;/strong&gt;: It lets us version-control your infrastructure the same way we manage application code, making rollbacks and collaboration easier.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dependency Management&lt;/strong&gt;: CloudFormation automatically handles resource dependencies, so we don’t have to worry about creating resources in the correct order — it figures that out for us.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability&lt;/strong&gt;: Need to spin up identical environments for development, testing, or production? CloudFormation makes it seamless by deploying the same stack repeatedly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Change Management&lt;/strong&gt;: It allows you to preview changes (using Change Sets) before applying them, reducing the risk of unexpected updates breaking your setup.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cross-Region and Cross-Account Deployments&lt;/strong&gt;: Easily replicate infrastructure across AWS regions and accounts using a single template.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Now lets look into some terminology
&lt;/h2&gt;

&lt;p&gt;Understanding AWS CloudFormation involves a few key terms. Let’s break them down simply and clearly!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Templates&lt;/strong&gt;: These are text files written in either JSON or YAML that acts as the "scripts" for CloudFormation.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CloudFormation reads templates as inputs.&lt;/li&gt;
&lt;li&gt;They describe the desired state of your infrastructure.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Stacks&lt;/strong&gt;: A stack is a collection  of AWS resources that CloudFormation manages as a single unit.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CloudFormation uses templates to create stacks.&lt;/li&gt;
&lt;li&gt;To make changes, you updates the template and apply the changes by updating the stack.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;ChangeSet&lt;/strong&gt;: Before updating a stack, you can generate a change set.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A change set shows how proposed changes will affect your existing resources.&lt;/li&gt;
&lt;li&gt;This is crucial for live systems to prevent unexpected disruptions.&lt;/li&gt;
&lt;li&gt;For example, renaming an RDS instance will:

&lt;ul&gt;
&lt;li&gt;Create a new instance.&lt;/li&gt;
&lt;li&gt;Delete the old one.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Result: This could cause data loss if not handled carefully.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Now lets look into Templates.
&lt;/h2&gt;

&lt;p&gt;In AWS CloudFormation, templates are written with either JSON or YAML files that define the AWS resources you want to create, like EC2 instances, S3 buckets, or IAM roles. These templates act as blueprints for your infrastructure.&lt;/p&gt;
&lt;h3&gt;
  
  
  Templates Formats
&lt;/h3&gt;

&lt;p&gt;CloudFormation supports two formats for writing templates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;YAML: A human-readable format, easier to write and maintain.&lt;/li&gt;
&lt;li&gt;JSON: A structured format, more rigid but familiar to developers used to working with APIs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most developers prefer YAML because of its simplicity, especially for larger templates. Both formats work the same way, so it's just a matter of readability and convenience.&lt;/p&gt;

&lt;p&gt;Example for  template(JSON)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "AWSTemplateFormatVersion": "version date",
  "Description": "JSON string",
  "Metadata": {},
  "Parameters": {},
  "Rules": {},
  "Mappings": {},
  "Conditions": {},
  "Transform": {},
  "Resources": {},
  "Outputs": {}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example for  template(YAML)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---
AWSTemplateFormatVersion: version date
Description: String
Metadata: template metadata
Parameters: set of parameters
Rules: set of rules
Mappings: set of mappings
Conditions: set of conditions
Transform: set of transforms
Resources: set of resources
Outputs: set of outputs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Now lets start an instance.
&lt;/h2&gt;

&lt;p&gt;create a file named &lt;code&gt;.yaml&lt;/code&gt; extenstion and write down the below code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Resources:
  MyInstance:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: t2.micro
      ImageId: ami-0ff8a91507f77f867
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Now lets run the above template
&lt;/h3&gt;

&lt;p&gt;Search for the CloudFormation service in AWS.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on create task.&lt;/li&gt;
&lt;li&gt;Click on Template is ready -&amp;gt; Upload a template file.&lt;/li&gt;
&lt;li&gt;Select the file and upload it.&lt;/li&gt;
&lt;li&gt;Give the stack name -&amp;gt; Click Next.&lt;/li&gt;
&lt;li&gt;U can give some tags if required -&amp;gt; u continue with the default -&amp;gt; Next.&lt;/li&gt;
&lt;li&gt;Last in review section just check everything and then click Create stack.&lt;/li&gt;
&lt;li&gt;We can see that in events tab u can look at the status-it might say CREATE_IN_PROGRESS.&lt;/li&gt;
&lt;li&gt;Click on refresh to see the updated status.&lt;/li&gt;
&lt;li&gt;It says CREATE_COMPLETE after the completion.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;now for updating the name we add tags to specify the instance name&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Resources:
  MyInstance:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: t2.micro
      ImageId: ami-0ff8a91507f77f867
      Tags:
        - Key: "Name"
          Value: "MyFirstInstance"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now back to AWS console click on Update stack -&amp;gt; Replace current template -&amp;gt; Update a template file -&amp;gt; Click Next -&amp;gt; Keep everything default and click next -&amp;gt; At last click Update stack.&lt;/li&gt;
&lt;li&gt;After it updates we can verify it by checking the EC2 instance and the name of it should be updated.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is it for the introduction to AWS CloudFormation.&lt;/p&gt;

&lt;h3&gt;
  
  
  In the next blog, we'll tackle Intrinsic Functions, Change Sets, and how to manage multiple resources using Mappings and Pseudo Parameters. Stay tuned there’s a lot more to uncover!
&lt;/h3&gt;

</description>
      <category>devops</category>
      <category>aws</category>
      <category>cloudformation</category>
      <category>gitops</category>
    </item>
    <item>
      <title>Automate Spotify Playlist Management Using Terraform: A Step-by-Step Guide</title>
      <dc:creator>Prajwal KP</dc:creator>
      <pubDate>Sat, 22 Feb 2025 07:28:34 +0000</pubDate>
      <link>https://dev.to/prajwal_kp/automate-spotify-playlist-management-using-terraform-a-step-by-step-guide-39jo</link>
      <guid>https://dev.to/prajwal_kp/automate-spotify-playlist-management-using-terraform-a-step-by-step-guide-39jo</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;If you're new to Terraform and infrastructure as code (IaC), I recommend going through my previous post &lt;a href="https://dev.to/prajwal_kp/getting-started-with-terraform-automating-aws-infrastructure-3leg"&gt;here&lt;/a&gt;, where I covered the fundamentals of Terraform. Understanding the basics will help you follow along smoothly as we dive into provisioning an AWS EC2 instance using Terraform. Once you're comfortable with the core concepts, you can continue with this guide to apply Terraform in a real-world use case.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;I am Prajwal KP, a second-year student from Bangalore, passionate about full-stack web development and DevOps.&lt;br&gt;
Here is my &lt;a href="https://www.linkedin.com/in/prajwal-kp-04a471285/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;, &lt;a href="https://github.com/Prajwal-kp-18" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Terraform Spotify Playlist Automation
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Project Overview
&lt;/h3&gt;

&lt;p&gt;This project automates the creation and management of multiple Spotify playlists using Terraform. It utilizes the Spotify API to interact with your Spotify account and create playlists tailored for different occasions such as morning, evening, party night, etc.&lt;/p&gt;
&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;Before starting, make sure you have the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Terraform Installed&lt;/strong&gt;: Ensure Terraform is installed on your machine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Docker Installed&lt;/strong&gt;: Make sure Docker is installed and running.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spotify Account&lt;/strong&gt;: You need a Spotify account (free tier is sufficient).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spotify Developer Account&lt;/strong&gt;: Register and create an application to get the Client ID and Client Secret.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;VS Code Editor&lt;/strong&gt;: Recommended for editing Terraform files.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Steps to Complete the Project
&lt;/h3&gt;
&lt;h4&gt;
  
  
  1. Set Up Terraform Project
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Create a new directory for your Terraform project and navigate to it in your terminal.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  2. Store Credentials Securely
&lt;/h4&gt;

&lt;p&gt;Create a &lt;code&gt;.env&lt;/code&gt; file to store your Spotify application's Client ID and Secret:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SPOTIFY_CLIENT_ID=&amp;lt;your_spotify_client_id&amp;gt;
SPOTIFY_CLIENT_SECRET=&amp;lt;your_spotify_client_secret&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Obtain Spotify API Credentials&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To interact with Spotify's API, you need to create a Spotify Developer App:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to the &lt;a href="https://developer.spotify.com/dashboard/" rel="noopener noreferrer"&gt;Spotify Developer Dashboard&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Log in with your Spotify account.&lt;/li&gt;
&lt;li&gt;Click on "Create an App" and fill in the required details.&lt;/li&gt;
&lt;li&gt;Set the &lt;code&gt;Redirect URLS&lt;/code&gt; as &lt;code&gt;http://localhost:27228/spotify_callback&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;U can get the client id here.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuc1s4y9z92rcua3erlm7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuc1s4y9z92rcua3erlm7.png" alt="Spotify" width="800" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Define Spotify Provider
&lt;/h4&gt;

&lt;p&gt;Create file named &lt;code&gt;provider.tf&lt;/code&gt; and paste the below content&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform {
  required_providers {
    spotify = {
      source  = "conradludgate/spotify"
      version = "0.2.7"
    }
  }
}

provider "spotify" {
  # Configuration options
  api_key = var.spotify_api_key
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also create a &lt;code&gt;.env&lt;/code&gt; and fill in the details&lt;/p&gt;

&lt;p&gt;Now under &lt;code&gt;variables.tf&lt;/code&gt; paste the below code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;variable "spotify_api_key" {
  type = string
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now create &lt;code&gt;terraform.tfvars&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;spotify_api_key = &amp;lt;Paste_Your_Api_key&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To get this  keymake sure to run the below command and verify it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;--rm&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; 27228:27228 &lt;span class="nt"&gt;--env-file&lt;/span&gt; .env ghcr.io/conradludgate/spotify-auth-proxy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now finally create &lt;code&gt;playlist.tf&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "spotify_playlist" "tearraform" {
  name = "Tearraform"
  tracks = ["2plbrEY59IikOBgBGLjaoe", "0VjIjW4GlUZAMYd2vXMi3b"]
}

data "spotify_search_track" "Eminem" {
  artist = "Eminem"
  limit = 10
}

resource "spotify_playlist" "From_Eminem" {
  name = "From Eminem"
  tracks = data.spotify_search_track.Eminem.tracks[*].id
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Breakdown
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Create a playlist with specific tracks:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "spotify_playlist" "tearraform" {
  name   = "Tearraform"
  tracks = ["2plbrEY59IikOBgBGLjaoe", "0VjIjW4GlUZAMYd2vXMi3b"]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Creates a playlist&lt;/strong&gt; named &lt;strong&gt;"Tearraform"&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Adds tracks using &lt;strong&gt;Spotify track IDs&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Search for Eminem's top 10 tracks:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data "spotify_search_track" "Eminem" {
  artist = "Eminem"
  limit  = 10
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fetches top 10 tracks by Eminem&lt;/strong&gt; from Spotify's API.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Create a playlist with Eminem's tracks:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "spotify_playlist" "From_Eminem" {
  name   = "From Eminem"
  tracks = data.spotify_search_track.Eminem.tracks[*].id
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Creates a playlist&lt;/strong&gt; named &lt;strong&gt;"From Eminem"&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamically adds&lt;/strong&gt; the top 10 tracks found in the search.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4. Start Spotify Authorization Proxy
&lt;/h4&gt;

&lt;p&gt;Ensure Docker Desktop is running, then start the authorization proxy server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;--rm&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; 27228:27228 &lt;span class="nt"&gt;--env-file&lt;/span&gt; .env ghcr.io/conradludgate/spotify-auth-proxy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Initialize and Apply Terraform Configuration
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Initialize the Terraform configuration:
&lt;/li&gt;
&lt;/ul&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;ul&gt;
&lt;li&gt;Plan the Terraform configurations
&lt;/li&gt;
&lt;/ul&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;ul&gt;
&lt;li&gt;Apply the Terraform configuration:
&lt;/li&gt;
&lt;/ul&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;h4&gt;
  
  
  6. Verify Playlists on Spotify
&lt;/h4&gt;

&lt;p&gt;After applying the Terraform configuration, log in to your Spotify account and verify that the playlists have been created and populated with the specified tracks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Automating Spotify playlist management with Terraform streamlines the process of creating and maintaining playlists for various occasions. Customize the playlists and tracks according to your preferences to enhance your music listening experience.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>terraform</category>
      <category>gitops</category>
      <category>automation</category>
    </item>
    <item>
      <title>Infrastructure as Code: Creating an AWS EC2 Instance with Terraform</title>
      <dc:creator>Prajwal KP</dc:creator>
      <pubDate>Fri, 07 Feb 2025 21:39:23 +0000</pubDate>
      <link>https://dev.to/prajwal_kp/infrastructure-as-code-creating-an-aws-ec2-instance-with-terraform-3074</link>
      <guid>https://dev.to/prajwal_kp/infrastructure-as-code-creating-an-aws-ec2-instance-with-terraform-3074</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;If you're new to Terraform and infrastructure as code (IaC), I recommend going through my previous post &lt;a href="https://dev.to/prajwal_kp/getting-started-with-terraform-automating-aws-infrastructure-3leg"&gt;here&lt;/a&gt;, where I covered the fundamentals of Terraform. Understanding the basics will help you follow along smoothly as we dive into provisioning an AWS EC2 instance using Terraform. This guide is beginner-friendly, so even if you're just getting started, you'll be able to follow along and apply Terraform in a real-world use case with ease.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;I am Prajwal KP, a second-year student from Bangalore, passionate about full-stack web development and DevOps.&lt;br&gt;
Here are my &lt;a href="https://www.linkedin.com/in/prajwal-kp-04a471285/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;, &lt;a href="https://github.com/Prajwal-kp-18" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  What Is Terraform?
&lt;/h2&gt;

&lt;p&gt;Terraform, developed by HashiCorp, is a powerful open-source Infrastructure as Code (IaC) tool that enables declarative provisioning, management, and automation of infrastructure across multiple cloud providers and on-premises environments.&lt;/p&gt;

&lt;p&gt;It allows users to define infrastructure using a high-level configuration language (HCL) and facilitates infrastructure lifecycle management through execution plans, resource graphs, and state management. Terraform’s provider ecosystem extends beyond traditional cloud platforms like AWS, Azure, and Google Cloud to include Kubernetes, databases, networking, and even SaaS applications, making it a highly versatile tool for modern DevOps and cloud-native architectures.&lt;/p&gt;
&lt;h2&gt;
  
  
  Spinning Up an EC2 Instance with Terraform Magic
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Let's Start Writing Some Terraform Code.
&lt;/h3&gt;

&lt;p&gt;In this post, I'll walk you through the step-by-step process of launching an AWS EC2 instance using Terraform, making infrastructure deployment seamless and automated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Open your VS Code or any other code editor to start coding.&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1: Find instanceId to launch an instance
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create a new file named &lt;code&gt;instId.tf&lt;/code&gt; and copy the below code into it.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# data "resource type" "resource name"
data "aws_ami" "amiId" {
  most_recent = true

  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["099720109477"]
}

# output block

output "instance_id" {
  description = "AMI ID of the instance"
  value       = data.aws_ami.amiId.id
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Breakdown:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;This file is basically used to find an instance Id to launch an instance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To launch an EC2 instance, we'll create additional &lt;code&gt;.tf&lt;/code&gt; files to define the required configurations. Additionally, since an instance requires a key pair and a security group, I'll organize these resources into separate folders for better structure and maintainability.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2: Create &lt;code&gt;provider.tf&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Our provider for this setup will be AWS, where we can specify important details such as the desired region, the key pair to use, and additional provider configurations to customize our deployment. &lt;/li&gt;
&lt;li&gt;Paste the below code.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;provider "aws" {
  region = "us-east-1"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;For more details click &lt;a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs" rel="noopener noreferrer"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Step 3: Set Up a Key Pair and Security Group
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a new file under the same directory as &lt;code&gt;KeyPair.tf&lt;/code&gt; and one more file as &lt;code&gt;SecGrp.tf&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open file &lt;code&gt;KeyPair.tf&lt;/code&gt; and paste the following&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "aws_key_pair" "my-key" {
  key_name   = "my-key"
  public_key = ""
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;To generate the keys&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open the terminal in the same directory and type &lt;code&gt;ssh-keygen&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Enter the name as &lt;code&gt;mykey&lt;/code&gt; and let other fields be default.&lt;/li&gt;
&lt;li&gt;Then type &lt;code&gt;ls&lt;/code&gt; and check whether the private and public keys are present.&lt;/li&gt;
&lt;li&gt;Then type &lt;code&gt;cat mykey.pub&lt;/code&gt; and copy the output and paste it as the value for public_key inside &lt;code&gt;KeyPair.tf&lt;/code&gt; and save it.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now let's create the security group&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Open the &lt;code&gt;SecGrp.tf&lt;/code&gt; and paste the code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "aws_security_group" "my-sg" {
  name        = "my-sg"
  description = "my-sg"

  tags = {
    Name = "my-sg"
  }
}

resource "aws_vpc_security_group_ingress_rule" "sshfromyIp" {
  security_group_id = aws_security_group.my-sg.id
  cidr_ipv4         = "Your_Ip/32"
  from_port         = 22
  ip_protocol       = "tcp"
  to_port           = 22
}

resource "aws_vpc_security_group_ingress_rule" "allow_http" {
  security_group_id = aws_security_group.my-sg.id
  cidr_ipv4         = "0.0.0.0/0"
  from_port         = 80
  ip_protocol       = "tcp"
  to_port           = 80
}

resource "aws_vpc_security_group_egress_rule" "allow_all_outbound_ipv4" {
  security_group_id = aws_security_group.my-sg.id
  cidr_ipv4         = "0.0.0.0/0"
  ip_protocol       = "-1" # -1 for all incoming protocols
}

resource "aws_vpc_security_group_egress_rule" "allow_all_outbound_ipv6" {
  security_group_id = aws_security_group.my-sg.id
  cidr_ipv6         = "::/0"
  ip_protocol       = "-1" # -1 for all incoming protocols
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Breaking Down the Security Group Configuration
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Creating the Security Group – Defines a security group named my-sg with basic tagging for identification.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Allowing SSH Access – Enables SSH (port 22) access only from your IP for security. Replace &lt;code&gt;Your_Ip&lt;/code&gt; with your actual public IP find it &lt;a href="//checkip.amazonaws.com"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Allowing HTTP Access – Opens port 80 to allow HTTP traffic from anywhere (0.0.0.0/0).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Allowing All Outbound Traffic – Ensures the instance can access the internet by allowing unrestricted outbound traffic for both IPv4 and IPv6.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 4:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Let's write the code to launch instance or we can say that to maintain an instance&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a new file as &lt;code&gt;instance.tf&lt;/code&gt; and copy the below code.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "aws_instance" "web" {
  ami                    = data.aws_ami.amiId.id
  instance_type          = "t2.micro"
  key_name               = aws_key_pair.my-key.key_name
  vpc_security_group_ids = [aws_security_group.my-sg.id]
  availability_zone      = "us-east-1a"

  tags = {
    Name    = "my-web"
    Project = "First"
  }
}

resource "aws_ec2_instance_state" "web-state" {
  instance_id = aws_instance.web.id
  state = "running"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Breaking Down the EC2 Instance Configuration&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Defining the EC2 Instance&lt;/strong&gt; – Creates an EC2 instance using an AMI (&lt;code&gt;amiId&lt;/code&gt;), sets the instance type to &lt;code&gt;t2.micro&lt;/code&gt;, and assigns it a key pair for SSH access.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security Group Association&lt;/strong&gt; – Attaches the previously created security group (&lt;code&gt;my-sg&lt;/code&gt;) to control inbound and outbound traffic.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Availability Zone Selection&lt;/strong&gt; – Specifies the instance should launch in &lt;strong&gt;&lt;code&gt;us-east-1a&lt;/code&gt;&lt;/strong&gt;, ensuring control over its placement within the AWS region.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Tagging for Organization&lt;/strong&gt; – Adds metadata with the name &lt;code&gt;"my-web"&lt;/code&gt; and associates it with the project &lt;code&gt;"First"&lt;/code&gt;.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ensuring the Instance is Running&lt;/strong&gt; – Uses a separate resource to maintain the EC2 instance in a &lt;code&gt;"running"&lt;/code&gt; state, preventing unintended shutdowns.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cool! Now that we've defined our infrastructure, let's put it into action by executing our Terraform commands. We'll initialize the configuration, review the changes, and apply them to deploy our EC2 instance. 🚀&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;terraform init&lt;/code&gt; ( to download all the required libraries from the registry)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;terraform fmt&lt;/code&gt; ( to correct the format )&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;terraform validate&lt;/code&gt; ( to check the syntax )&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;terraform plan&lt;/code&gt; ( it is important to read all the changes )&lt;/li&gt;
&lt;li&gt;&lt;code&gt;terraform apply&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Voila! 🎉 If everything executed without errors, your EC2 instance should now be up and running. To verify, head over to the &lt;strong&gt;AWS Management Console&lt;/strong&gt;, ensure you're in the correct &lt;strong&gt;region&lt;/strong&gt;, and navigate to the &lt;strong&gt;EC2 Dashboard&lt;/strong&gt;. Here, you can check the instance state to confirm it's running. Also, review the &lt;strong&gt;Security Group&lt;/strong&gt; settings to ensure the correct inbound and outbound rules are applied. Happy automating! 🚀&lt;/p&gt;

&lt;p&gt;After checking it and using it to delete the instance we can type &lt;code&gt;terraform destroy&lt;/code&gt; to completely delete the instance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;And that’s a wrap! 🎉 You’ve successfully deployed and managed an EC2 instance using Terraform, making infrastructure automation easier and more efficient. But this is just the beginning! There’s so much more to explore in cloud computing, DevOps, and automation.  &lt;/p&gt;

&lt;p&gt;Stay tuned for my upcoming posts, where I'll dive into more exciting topics and hands-on guides to help you level up your skills. 🚀 See you in the next one! 😊&lt;/p&gt;

</description>
      <category>devops</category>
      <category>terraform</category>
      <category>aws</category>
      <category>gitops</category>
    </item>
    <item>
      <title>Getting Started with Terraform: Automating AWS Infrastructure</title>
      <dc:creator>Prajwal KP</dc:creator>
      <pubDate>Wed, 05 Feb 2025 18:51:00 +0000</pubDate>
      <link>https://dev.to/prajwal_kp/getting-started-with-terraform-automating-aws-infrastructure-3leg</link>
      <guid>https://dev.to/prajwal_kp/getting-started-with-terraform-automating-aws-infrastructure-3leg</guid>
      <description>&lt;h2&gt;
  
  
  What Is Terraform?
&lt;/h2&gt;

&lt;p&gt;It is a tool from HashiCorp, and its primary purpose is to manage the infrastructure on the cloud.&lt;/p&gt;

&lt;p&gt;It's also called as Infrastructure as a code(IaC).&lt;/p&gt;

&lt;p&gt;Terraform has become a default standard for cloud automation, and today's time it can manage almost all the cloud providers like AWS, Azure, Google Cloud, Oracle Cloud, even Docker, and even Kubernetes.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Does It Look?
&lt;/h2&gt;

&lt;p&gt;Terraform code is structured and declarative, similar to JSON or YAML, but with its own HCL (HashiCorp Configuration Language) syntax. Here’s an example of a simple Terraform configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;provider "aws" {
  region = "us-east-1"
}

resource "aws_instance" "web" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"

  tags = {
    Name = "WebServer"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Breakdown:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Provider Block: Specifies the cloud provider (AWS, Azure, etc.) and its configurations.&lt;/li&gt;
&lt;li&gt;Resource Block: Defines the infrastructure resource (e.g., an EC2 instance).&lt;/li&gt;
&lt;li&gt;Attributes: Properties like &lt;code&gt;ami&lt;/code&gt;, &lt;code&gt;instance_type&lt;/code&gt;, and &lt;code&gt;tags&lt;/code&gt; configure the resource.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After writing this, running &lt;code&gt;terraform apply&lt;/code&gt; provisions the instance. Terraform ensures that the infrastructure matches the defined state, making it a powerful tool for Infrastructure as Code (IaC).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To get started, install Terraform by following the official installation guide &lt;a href="https://developer.hashicorp.com/terraform/install" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To check the version to ensure it's installed, run:&lt;br&gt;
&lt;code&gt;terraform --version&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Up AWS Access for Terraform
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Breakdown:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Go to your AWS account and create an IAM user.&lt;/li&gt;
&lt;li&gt;Save the access key on your device.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Ok Let's Begin:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;First log in to your AWS account search for IAM(Identify and Access Management)&lt;/li&gt;
&lt;li&gt;Go to users -&amp;gt; create user -&amp;gt; enter name -&amp;gt; next.&lt;/li&gt;
&lt;li&gt;For Set permissions select &lt;strong&gt;Attach policies directly&lt;/strong&gt; -&amp;gt; Choose administratorAccess -&amp;gt; next and finally create user.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Now User Is Created So Lets Create The Access Key:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Click on the newly created username -&amp;gt; click on Security credentials tab.&lt;/li&gt;
&lt;li&gt;Find Create access key -&amp;gt; Click on Create access key -&amp;gt; Select Command Line Interface(CLI) -&amp;gt; Next -&amp;gt; Create the access key.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Configure AWS CLI:
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Open Git Bash or any other terminal and run:&lt;/strong&gt;&lt;br&gt;
Run &lt;code&gt;aws configure&lt;/code&gt;. It will prompt you for an Access Key and Secret Key—paste them from your AWS account and keep the rest as default.&lt;/p&gt;

&lt;h4&gt;
  
  
  Let's Start Writing Some Terraform Code.
&lt;/h4&gt;

&lt;p&gt;In this post, I'll cover how to find an amiId for an EC2 instance.&lt;br&gt;
&lt;strong&gt;Steps:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open your VS Code or any other code editor to start coding.&lt;/li&gt;
&lt;li&gt;create a file called &lt;code&gt;instId.tf&lt;/code&gt; and paste the code given below.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# The "data" block is used to fetch data from an existing resource
# This block retrieves information about the latest Amazon Machine Image (AMI) for Ubuntu 22.04
data "aws_ami" "amiId" {
  most_recent = true  # Ensures that the most recent AMI matching the filters is selected

  # First filter to match AMI names following a specific pattern
  filter {
    name   = "name"  
    values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]  
    # The wildcard (*) ensures it picks up all versions of Ubuntu 22.04 server AMIs
  }

  # Second filter to ensure the AMI uses HVM (Hardware Virtual Machine) virtualization
  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["099720109477"]  
  # Specifies that the AMI must be owned by Canonical (official Ubuntu provider)
}

# Output block to display the fetched AMI ID
output "instance_id" {
  description = "AMI ID of the instance"  # Provides a description for the output
  value       = data.aws_ami.amiId.id  # Outputs the ID of the selected AMI
}

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Breakdown:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Data Source Block (&lt;code&gt;data "aws_ami" "amiId"&lt;/code&gt;)

&lt;ul&gt;
&lt;li&gt;Uses Terraform’s &lt;code&gt;data&lt;/code&gt; block to query an existing AWS resource (AMI).&lt;/li&gt;
&lt;li&gt;Fetches the latest AMI that meets the specified filters.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;most_recent = true&lt;/code&gt; ensures the newest AMI is selected.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Filtering AMI by Name

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;filter { name = "name" }&lt;/code&gt; applies a filter based on the AMI name.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;Ensures that the AMI belongs to the Ubuntu 22.04 LTS (Jammy Jellyfish) Server series.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;*&lt;/code&gt; wildcard picks up all minor versions.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Filtering by Virtualization Type

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;filter { name = "virtualization-type" }&lt;/code&gt; ensures that only HVM (Hardware Virtual Machine) AMIs are selected.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;values = ["hvm"]&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;HVM provides full virtualization and is required for most modern AWS instance types.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Restricting to Official Ubuntu AMIs

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;owners = ["099720109477"]&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;Specifies that the AMI must be owned by Canonical (Ubuntu’s official publisher).&lt;/li&gt;
&lt;li&gt;Prevents fetching AMIs from untrusted sources.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Output Block (&lt;code&gt;output "instance_id"&lt;/code&gt;)

&lt;ul&gt;
&lt;li&gt;Outputs the selected AMI ID so it can be referenced elsewhere in the Terraform configuration.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;description = "AMI ID of the instance"&lt;/code&gt; provides a human-readable explanation.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;value = data.aws_ami.amiId.id&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;Retrieves the &lt;code&gt;id&lt;/code&gt; of the AMI selected from the &lt;code&gt;data&lt;/code&gt; block.&lt;/li&gt;
&lt;li&gt;Useful for provisioning EC2 instances with the latest Ubuntu AMI.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Running the Terraform Commands
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Open your terminal in the same directory where the file is located and start typing the following commands:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;terraform fmt&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;It will check the format and fixes it if there is an issue.&lt;/li&gt;
&lt;li&gt;It will give a standard form.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;terraform init&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;This command reads all the &lt;code&gt;.tf&lt;/code&gt; files in the current directory, checks the required resources, and downloads the necessary plugins from the Terraform registry.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;terraform validate&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;This command ensures that all the mentioned arguments and values are syntactically correct.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;terraform plan&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;This command creates an execution plan by comparing the current state with the desired configuration.&lt;/li&gt;
&lt;li&gt;It shows what changes Terraform will make without actually applying them.&lt;/li&gt;
&lt;li&gt;Helps in reviewing resource additions, modifications, or deletions before running terraform apply.&lt;/li&gt;
&lt;li&gt;Ensures there are no unexpected infrastructure changes.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;terraform apply&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;This command executes the planned changes to create, update, or delete resources as defined in the configuration.&lt;/li&gt;
&lt;li&gt;It prompts for confirmation before making any changes (unless -auto-approve is used).&lt;/li&gt;
&lt;li&gt;After successful execution, it provisions the infrastructure and displays the applied changes.&lt;/li&gt;
&lt;li&gt;Uses the Terraform state file to track managed resources.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Finally after apply is completed it prints out the output.&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;By following these steps, you can efficiently validate, plan, and apply your Terraform configurations to manage infrastructure. Ensuring proper validation and planning helps avoid unexpected changes and keeps your deployments smooth.&lt;/p&gt;

&lt;p&gt;🚀 Stay tuned for my next post, where I'll cover launching an EC2 instance using Terraform!&lt;/p&gt;

</description>
      <category>devops</category>
      <category>terraform</category>
      <category>aws</category>
      <category>gitops</category>
    </item>
  </channel>
</rss>
