<?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: Ayush Pant</title>
    <description>The latest articles on DEV Community by Ayush Pant (@ayush_pant_67bc0b97507a25).</description>
    <link>https://dev.to/ayush_pant_67bc0b97507a25</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2935988%2Fddca9d70-28c8-4de2-be93-85740a6df430.png</url>
      <title>DEV Community: Ayush Pant</title>
      <link>https://dev.to/ayush_pant_67bc0b97507a25</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ayush_pant_67bc0b97507a25"/>
    <language>en</language>
    <item>
      <title>Automating Amazon EKS Provisioning with Terraform &amp; GitHub OIDC &amp; Actions</title>
      <dc:creator>Ayush Pant</dc:creator>
      <pubDate>Wed, 12 Mar 2025 14:49:15 +0000</pubDate>
      <link>https://dev.to/ayush_pant_67bc0b97507a25/automating-amazon-eks-provisioning-with-terraform-github-oidc-actions-5dof</link>
      <guid>https://dev.to/ayush_pant_67bc0b97507a25/automating-amazon-eks-provisioning-with-terraform-github-oidc-actions-5dof</guid>
      <description>&lt;p&gt;🚀 Automating Amazon EKS Provisioning with Terraform &amp;amp; GitHub&amp;nbsp;Actions&lt;br&gt;
&amp;nbsp;&lt;br&gt;
Managing Kubernetes clusters manually can be complex and error-prone. In this guide, we'll walk through how to automate Amazon EKS provisioning using Terraform and GitHub Actions, enabling a secure, scalable, and efficient deployment.&lt;br&gt;
By the end of this tutorial, you'll have an EKS cluster running inside an existing VPC, provisioned via GitHub PR-based automation with built-in YAML &amp;amp; Terraform validation.&lt;br&gt;
🔗 Check out the complete source code on GitHub: (&lt;a href="https://github.com/ayushpant816/tf" rel="noopener noreferrer"&gt;https://github.com/ayushpant816/tf&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;🛠 Prerequisites&amp;nbsp;&lt;br&gt;
Before we start, ensure you have:&lt;br&gt;
✅ Existing AWS VPC &amp;amp; Subnets (fetch details using AWS CLI)&amp;nbsp;&lt;br&gt;
✅ Terraform installed on your local machine&amp;nbsp;&lt;br&gt;
✅ GitHub Secrets configured for secure authentication&amp;nbsp;&lt;br&gt;
✅ IAM Role with permissions for GitHub Actions&amp;nbsp;&lt;br&gt;
✅ Security Group Rules allowing access to the EKS cluster&lt;/p&gt;

&lt;p&gt;📂 Project Directory Structure&lt;br&gt;
📦 repo-root&lt;br&gt;
┣ 📂 terraform&lt;br&gt;
┃ ┣ 📜 main.tf&lt;br&gt;
┃ ┣ 📜 variables.tf&lt;br&gt;
┃ ┣ 📜 backend.tf&lt;br&gt;
┃ ┣ 📜 outputs.tf&lt;br&gt;
┃ ┗ 📜 providers.tf&lt;br&gt;
┣ 📂&amp;nbsp;.github/workflows&lt;br&gt;
┃ ┣ 📜 terraform.yaml&lt;br&gt;
┃ ┗ 📜 tf-yaml-validator.yaml&lt;br&gt;
┣ 📜&amp;nbsp;.yamllint&lt;br&gt;
┣ 📜 README.md&lt;br&gt;
┗ 📜&amp;nbsp;.gitignore&lt;/p&gt;

&lt;p&gt;🚀 Automating EKS Deployment - Workflow Overview&lt;br&gt;
🔍 Linting: Validates YAML &amp;amp; Terraform syntax&amp;nbsp;&lt;br&gt;
🛠️ Terraform Plan: Checks infrastructure changes&amp;nbsp;&lt;br&gt;
🚀 Terraform Apply: Deploys EKS&amp;nbsp;&lt;br&gt;
🔄 PR-Based Deployment: GitHub Actions auto-runs based on PR comments&lt;/p&gt;

&lt;p&gt;🔑 Fetching Required AWS Details&amp;nbsp;&lt;br&gt;
Before deploying, fetch the VPC ID and Subnets where the EKS cluster will be created:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws ec2 describe-vpcs - query "Vpcs[].VpcId"
aws ec2 describe-subnets - query "Subnets[].SubnetId"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;-
🔐 IAM Role Creation for GitHub Actions
To allow GitHub Actions to interact with AWS securely, create an IAM role with OIDC authentication.
1️⃣ Create IAM Role
aws iam create-role - role-name eks-cluster-role \
 - assume-role-policy-document file://trust-policy.json&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;📜 trust-policy.json&lt;br&gt;
&lt;code&gt;{&lt;br&gt;
  "Version": "2012-10-17",&lt;br&gt;
  "Statement": [&lt;br&gt;
    {&lt;br&gt;
      "Effect": "Allow",&lt;br&gt;
      "Principal": {&lt;br&gt;
        "Federated": "arn:aws:iam::&amp;lt;AWS_ACCOUNT_ID&amp;gt;:oidc-provider/token.actions.githubusercontent.com"&lt;br&gt;
      },&lt;br&gt;
      "Action": "sts:AssumeRole",&lt;br&gt;
      "Condition": {&lt;br&gt;
        "StringLike": {&lt;br&gt;
          "token.actions.githubusercontent.com:sub": "repo:&amp;lt;GITHUB_ORG&amp;gt;/:*"&lt;br&gt;
        }&lt;br&gt;
      }&lt;br&gt;
    }&lt;br&gt;
  ]&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2️⃣ Attach Required Policies to IAM Role&lt;br&gt;
aws iam attach-role-policy - role-name eks-cluster-role \&lt;br&gt;
 - policy-arn arn:aws:iam::aws:policy/AmazonEKSClusterPolicy&lt;br&gt;
aws iam attach-role-policy - role-name eks-cluster-role \&lt;br&gt;
 - policy-arn arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy&lt;br&gt;
aws iam attach-role-policy - role-name eks-cluster-role \&lt;br&gt;
 - policy-arn arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly&lt;br&gt;
Verify role creation:&lt;br&gt;
aws iam get-role - role-name eks-cluster-role&lt;/p&gt;

&lt;p&gt;🚀 GitHub Actions Workflow for EKS Deployment&lt;br&gt;
1️⃣ Terraform &amp;amp; YAML Validation&lt;br&gt;
We ensure Terraform &amp;amp; YAML files are valid before deployment using&amp;nbsp;.github/workflows/tf-yaml-validator.yml.&lt;br&gt;
2️⃣ PR-Based Comment-Driven Provisioning&lt;br&gt;
Users can trigger Terraform Plan/Apply/Destroy by commenting on a PR with:&lt;br&gt;
terraform plan&lt;br&gt;
terraform apply&lt;br&gt;
terraform destroy&lt;/p&gt;

&lt;p&gt;🔑 GitHub Secrets Configuration&lt;br&gt;
To store sensitive values, set up GitHub Secrets:&lt;br&gt;
| Secret Name | Purpose |&lt;br&gt;
| - - - - - - - | - - - - -|&lt;br&gt;
| AWS_OIDC_ROLE | IAM Role for GitHub Actions |&lt;br&gt;
| VPC_ID | Existing VPC ID for EKS |&lt;br&gt;
| SUBNET_IDS | Comma-separated list of subnet IDs |&lt;/p&gt;

&lt;p&gt;🔥 Troubleshooting Common Issues&lt;/p&gt;

&lt;p&gt;| Issue | Possible Cause | Solution |&lt;br&gt;
| - - - -| - - - - - - - -| - - - - - |&lt;br&gt;
| Error acquiring state lock | Terraform state lock issue | Ensure Terraform backend is correctly configured |&lt;br&gt;
| ResourceNotFoundException | Missing DynamoDB lock table | Create a DynamoDB table named &lt;code&gt;terraform-lock&lt;/code&gt; |&lt;br&gt;
| VPC/Subnet values missing | Incorrect Terraform variables | Ensure VPC ID &amp;amp; Subnets are passed correctly |&lt;br&gt;
| YAML validation fails | Incorrect formatting | Fix YAML based on &lt;code&gt;.yamllint&lt;/code&gt; rules |&lt;/p&gt;

&lt;p&gt;🏆 Key Features &amp;amp; Security Best Practices&lt;br&gt;
✔ GitHub Actions with OIDC (No AWS access keys stored)&amp;nbsp;&lt;br&gt;
✔ PR-Based Comment Triggering (Only applies changes after review)&amp;nbsp;&lt;br&gt;
✔ YAML &amp;amp; Terraform Validation (Prevents broken deployments)&amp;nbsp;&lt;br&gt;
✔ Terraform Backend with State Locking (Avoids conflicts)&amp;nbsp;&lt;br&gt;
✔ IAM Role-Based Authentication (Secure access to AWS &amp;amp; EKS)&lt;/p&gt;

&lt;p&gt;📢 Contributors&lt;br&gt;
👤 Ayush Pant- DevOps Engineer&lt;br&gt;
If you found this helpful, feel free to like, comment, and share! 🚀&lt;/p&gt;

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