<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Abiodun Lasisi on Medium]]></title>
        <description><![CDATA[Stories by Abiodun Lasisi on Medium]]></description>
        <link>https://medium.com/@lasisiabioduntowobola?source=rss-ab7f1d7cdcde------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*mUlnUNyrYtqNtXzQ</url>
            <title>Stories by Abiodun Lasisi on Medium</title>
            <link>https://medium.com/@lasisiabioduntowobola?source=rss-ab7f1d7cdcde------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 09:09:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lasisiabioduntowobola/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Setting Up MySQL on Kubernetes: Hands-On Deployment on AWS EC2]]></title>
            <link>https://medium.com/@lasisiabioduntowobola/setting-up-mysql-on-kubernetes-hands-on-deployment-on-aws-ec2-363d74084e71?source=rss-ab7f1d7cdcde------2</link>
            <guid isPermaLink="false">https://medium.com/p/363d74084e71</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Abiodun Lasisi]]></dc:creator>
            <pubDate>Fri, 28 Feb 2025 21:40:20 GMT</pubDate>
            <atom:updated>2025-02-28T21:40:20.683Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction</strong></p><p>Kubernetes has become the go-to platform for orchestrating containerized workloads, offering scalability and resilience for applications like databases.</p><p>In this guide, we’ll walk through deploying MySQL — a popular relational database — on a Kubernetes cluster running on AWS EC2 instances. Whether you’re a developer testing an application or an administrator setting up a proof-of-concept, this tutorial is designed for you. We’ll assume you have a basic cluster with one master and one worker node already set up, and we’ll cover everything from securing credentials to ensuring persistent storage, all within the default namespace. By the end, you’ll have a fully functional MySQL instance ready to serve your needs — let’s dive in!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HvR2bonjZJcRzYGL.png" /></figure><blockquote><strong><em>Prerequisites</em></strong></blockquote><p>Before we dive into the implementation, ensure you have the following prerequisites in place:</p><ol><li><strong>Kubernetes Cluster</strong>: Already installed on your EC2 instances (1 master-node, 1 worker-node).</li><li><strong>kubectl</strong>: Installed and configured on your local machine or master node to interact with the cluster.</li><li><strong>MySQL Image</strong>: We’ll use the official MySQL Docker image from Docker Hub (e.g., mysql:8.0).</li><li><strong>Persistent Storage</strong>: A Persistent Volume (PV) and Persistent Volume Claim (PVC) to store MySQL data.</li><li><strong>Configuration</strong>: A Secret for MySQL root password and a Deployment for MySQL.</li><li><strong>Network Access</strong>: A Service to expose MySQL within the cluster.</li></ol><h3>Step-by-Step Guide</h3><p><strong>Step 1</strong>: Verify Your Cluster</p><p>Ensure your Kubernetes cluster is running and accessible.</p><p>Run this command:</p><pre>kubectl get nodes</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SQPql6nlsmAuO6qAzDX7tw.png" /></figure><p><strong>Step 2</strong>: Create a Secret for MySQL Password</p><p>MySQL requires a root password. We’ll store it securely in a Kubernetes Secret.</p><p>Create a file named mysql-secret.yaml:</p><pre>apiVersion: v1<br>kind: Secret<br>metadata:<br>  name: mysql-secret<br>  namespace: default<br>type: Opaque<br>data:<br>  mysql-root-password: cm9vdHBhc3N3b3Jk  # Base64 encoded &quot;rootpassword&quot;</pre><p>Explanation:</p><p>mysql-root-password is the key.</p><p>cm9vdHBhc3N3b3Jk is “rootpassword” encoded in base64.</p><p>To encode your own password, use:</p><pre>echo -n &quot;yourpassword&quot; | base64</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WVbbDF5tAjdqdfp-Zp5Ggw.png" /></figure><p>Apply the Secret:</p><pre>kubectl apply -f mysql-secret.yaml</pre><p>Verify the secret:</p><pre>kubectl get secret mysql-secret -o yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tBUcAmub_175QNGMRrTK_g.png" /><figcaption>verify secret</figcaption></figure><p><strong>Step 3</strong>: Create a Persistent Volume (PV) and Persistent Volume Claim (PVC)</p><p>MySQL needs persistent storage. Since you’re on EC2, we’ll manually define a PV using local storage on the worker node.</p><p>On the master node,</p><p>create mysql-pv.yaml:</p><pre>apiVersion: v1<br>kind: PersistentVolume<br>metadata:<br>  name: mysql-pv<br>spec:<br>  capacity:<br>    storage: 5Gi<br>  accessModes:<br>    - ReadWriteOnce<br>  persistentVolumeReclaimPolicy: Retain<br>  storageClassName: manual<br>  hostPath:<br>    path: &quot;/mnt/mysql-data&quot;  # Directory on worker node</pre><p>Create mysql-pvc.yaml:</p><pre>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  name: mysql-pvc<br>  namespace: default<br>spec:<br>  accessModes:<br>    - ReadWriteOnce<br>  resources:<br>    requests:<br>      storage: 5Gi<br>  storageClassName: manual</pre><p>Prepare the worker-node:</p><p>SSH into the worker-node and create the directory:</p><pre>sudo mkdir -p /mnt/mysql-data<br>sudo chmod 777 /mnt/mysql-data  # Adjust permissions as needed</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xZVxAS2WsbcxNjYapRnp1Q.png" /></figure><p>Apply the PV and PVC:</p><pre>kubectl apply -f mysql-pv.yaml<br>kubectl apply -f mysql-pvc.yaml</pre><p>Verify:</p><pre>kubectl get pv<br>kubectl get pvc</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iwdlwUZc-t-w37IKRsyx_A.png" /></figure><p><strong>Step 4</strong>: Deploy MySQL</p><p>Create mysql-deployment.yaml:</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: mysql<br>  namespace: default<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: mysql<br>  template:<br>    metadata:<br>      labels:<br>        app: mysql<br>    spec:<br>      containers:<br>      - name: mysql<br>        image: mysql:8.0<br>        env:<br>        - name: MYSQL_ROOT_PASSWORD<br>          valueFrom:<br>            secretKeyRef:<br>              name: mysql-secret<br>              key: mysql-root-password<br>        ports:<br>        - containerPort: 3306<br>        volumeMounts:<br>        - name: mysql-storage<br>          mountPath: /var/lib/mysql<br>      volumes:<br>      - name: mysql-storage<br>        persistentVolumeClaim:<br>          claimName: mysql-pvc</pre><p>Apply the Deployment</p><pre>kubectl apply -f mysql-deployment.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*VFcunJGAhGmq1AN8sqlVQg.png" /></figure><p>Verify the pod is running:</p><pre>kubectl get pods</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*hZgVUSskZfizlg4hGSZY8g.png" /></figure><p><strong>Step 5</strong>: Expose MySQL with a Service</p><p>Create mysql-service.yaml:</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: mysql-service<br>  namespace: default<br>spec:<br>  selector:<br>    app: mysql<br>  ports:<br>  - protocol: TCP<br>    port: 3306<br>    targetPort: 3306<br>  type: ClusterIP  # Default, accessible only within cluster</pre><p>Apply the Service:</p><pre>kubectl apply -f mysql-service.yaml</pre><p>Verify</p><pre>kubectl get svc</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*3iitZvQsbSxltn08JsLpLg.png" /></figure><p><strong>Step 6</strong>: Test the Deployment</p><p>Access the MySQL container:</p><pre>kubectl exec -it &lt;mysql-pod-name&gt; -- bash</pre><p>Log in to MySQL:</p><pre>mysql -u root -p</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6QNkn41sKHFInUd6xlI8yQ.png" /></figure><p>Enter the password to the database</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NoB6vEbWj4S7wmDFNnNctg.png" /></figure><p>Run a test query:</p><pre>SHOW DATABASES;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qC4xp6YasRIwlHKxOwei6g.png" /><figcaption>mysql database</figcaption></figure><p><strong>Conclusion</strong></p><p>You’ve successfully deployed MySQL on a Kubernetes cluster running on AWS EC2 instances. The deployment uses a secret for secure password management, a PVC for persistent storage, and a service for accessibility.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=363d74084e71" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automate the Process of Copying AMIs Across AWS Regions using Boto3]]></title>
            <link>https://medium.com/@lasisiabioduntowobola/automate-the-process-of-copying-amis-across-aws-regions-47a30eee2c7a?source=rss-ab7f1d7cdcde------2</link>
            <guid isPermaLink="false">https://medium.com/p/47a30eee2c7a</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Abiodun Lasisi]]></dc:creator>
            <pubDate>Sun, 26 May 2024 17:33:42 GMT</pubDate>
            <atom:updated>2024-05-28T10:56:49.484Z</atom:updated>
            <content:encoded><![CDATA[<p>Amazon Machine Images (AMIs) are crucial for creating virtual servers in Amazon Web Services (AWS). They provide the information required to launch an instance, including the operating system, application server, and applications. There are times when you may need to copy an AMI from one AWS region to another to improve application availability and reduce latency. In this article, we’ll explore how to accomplish this using Boto3, the AWS SDK for Python.</p><p><strong>Architecture</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8ZGSEcckRZjYmxGT47N-Iw.png" /></figure><blockquote><strong>Prerequisites</strong></blockquote><p>Before we start, ensure you have the following:</p><ol><li>AWS Account: You need an active AWS account.</li><li>IAM Permissions: Ensure your IAM user has the necessary permissions to perform AMI copy operations.</li><li>Boto3 and AWS CLI: Ensure Boto3 and the AWS CLI are installed and configured on your local machine.</li></ol><h4>Step-by-Step Guide</h4><p><strong>Step 1:</strong> Copy the AMI</p><p>To copy an AMI, you need its ID from the source region. I will be copying an AMI from us-east-1 to eu-west-2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zst64lVTmijbbfO6cDJ3Xg.png" /><figcaption>AMI</figcaption></figure><p>I have copied <strong>ami-0e879a1b306fffb22 from </strong>us-east-1 N Virginia<strong>.</strong></p><p><strong>Step 2:</strong> You can install Boto3 using pip if it’s not already installed</p><pre>pip install boto3</pre><p><strong>Step 3:</strong> Setting Up Boto3</p><p>First, configure your AWS credentials. Boto3 will use these credentials to authenticate with AWS services. You can configure the credentials using the AWS CLI</p><pre>aws configure</pre><p>This command will prompt you for your AWS Access Key ID, Secret Access Key, region, and output format.</p><p>Secondly, Initialize the Boto3 and EC2 client and specify the destination region you are copying the AMI to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vpaDxSAkALm9Y6CbGGBsRQ.png" /></figure><p>To automate the copying from one region to the other we will use the below code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*keeBwASyWmKoM8qqochIvg.png" /><figcaption>AMI copied to eu-west-2</figcaption></figure><p>To verify that the AMI has been copied to the eu-west-2 region, we will go to our console and verify it.</p><p>If we copy the imageId from the output above and search AMI in the eu-west-2 region, we will find the AMI there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FuNimcRxMRN6b1qOAZkR9g.png" /></figure><h4>Conclusion</h4><p>Copying an AMI across regions can be a straightforward process using Boto3 in Python. This capability is particularly useful for disaster recovery, scaling across multiple regions, or reducing latency for users in different geographic locations. By following the steps outlined above, you can automate the process and integrate it into your AWS infrastructure management workflows.</p><p>Always remember to clean up any resources you no longer need to avoid unnecessary charges.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47a30eee2c7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating Checkov Security Scanning into GitHub Actions Pipeline]]></title>
            <link>https://medium.com/@lasisiabioduntowobola/integrating-checkov-security-scanning-into-github-actions-pipeline-c11374e391e1?source=rss-ab7f1d7cdcde------2</link>
            <guid isPermaLink="false">https://medium.com/p/c11374e391e1</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[checkov]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[yaml]]></category>
            <category><![CDATA[prisma]]></category>
            <dc:creator><![CDATA[Abiodun Lasisi]]></dc:creator>
            <pubDate>Sat, 11 May 2024 14:14:42 GMT</pubDate>
            <atom:updated>2024-05-13T12:14:59.089Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction</strong></p><p>In an era where infrastructure as code (IaC) plays a pivotal role in modern software development and deployment, ensuring the security and compliance of our infrastructure configurations is paramount. The integration of security scanning tools into our CI/CD pipelines is essential for proactively identifying and addressing potential vulnerabilities and compliance issues early in the development lifecycle.</p><p>In this project, we embark on a journey to integrate Checkov, a leading static code analysis tool for IaC, into our GitHub Actions pipeline. By leveraging the power of automation, we aim to seamlessly integrate Checkov scans into our development workflow, enabling us to automatically assess the security posture of our Terraform configurations before deploying infrastructure changes. Through this integration, we strive to enhance the security and reliability of our infrastructure deployments while streamlining our development process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L_gl4eAq1obPg7YaIGoa4w.png" /></figure><blockquote><strong>Prerequisite</strong></blockquote><ol><li>Terraform Code</li><li>GitHub Repository</li><li>Checkov</li></ol><p>Step 1: Create a new GitHub repository to host your Terraform code. I will be using my terraform code for deploying ec2 instance from <a href="https://github.com/Towobolar/ec2-instance/tree/main"><strong><em>here</em></strong></a><strong><em>.</em></strong></p><p>Step 2: Define Checkov Workflow Steps.</p><pre>build:<br>    name: checkov<br>    runs-on: ubuntu-latest<br>    steps:<br>    - uses: actions/checkout@v2<br>    - name: Set up Python 3.8<br>      uses: actions/setup-python@v1<br>      with:<br>        python-version: 3.8<br>    - name: Test with Checkov<br>      id: checkov<br>      uses: bridgecrewio/checkov-action@master<br>      with:<br>        directory: ./ec2-instance<br>        framework: terraform</pre><p>This workflow will trigger on push events to the main branch. It checks out the repository, sets up Python, installs Checkov, and runs a scan on the specified Terraform files as seen below.</p><pre>name: Deploy EC2 Instance<br><br>on:<br>  push:<br>    branches:<br>      - main<br><br>jobs:<br>  Terraform:<br>    name: &#39;Terraform&#39;<br>    runs-on: ubuntu-latest<br>    defaults:<br>      run:<br>        shell: bash<br>        working-directory: ./ec2-instance<br><br>    steps:<br>    - name: Checkout<br>      uses: actions/checkout@v4      <br>      <br>    - name: Setup Terraform<br>      uses: hashicorp/setup-terraform@v1<br>      with:<br>        cli_config_credentials_token: ${{ secrets.tfc_team_token }}<br>      <br>    - name: Terraform Init<br>      run: terraform init<br>      <br>    - name: Terraform Validate<br>      run: terraform validate <br>       <br>    - name: Terraform Plan<br>      run: terraform plan<br><br>  build:<br>   name: checkov<br>   runs-on: ubuntu-latest<br>   steps:<br>   - uses: actions/checkout@v2<br>   - name: Set up Python 3.8<br>     uses: actions/setup-python@v1<br>     with:<br>        python-version: 3.8<br>   - name: Test with Checkov<br>     id: checkov<br>     uses: bridgecrewio/checkov-action@master<br>     with:<br>        directory: ./ec2-instance<br>        framework: terraform     <br></pre><p>We can check our runs in actions</p><p>If we check the image below, we will see that checkov has been installed and the terraform scan results as been listed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eEDZXOh-UBpNsZgN0AA9eQ.png" /></figure><p>The terraform code passed 10 checks and failed 9 checks. As we can see below the failed checks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kv6AidPviuTHf6uMfSVeJQ.png" /></figure><p>If you click on the check, you’ll get a pop-up and follow the link to the Checkov <a href="https://www.checkov.io/1.Welcome/Quick%20Start.html"><em>documentation</em></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aLrn_D_dxDXKiYXrHb82Hg.png" /></figure><p>Checkov also allows the creation of custom policies using Python or YAML. To create a custom policy, follow these steps:</p><ol><li>Establish a new directory dedicated to your custom policies, such as “custom_policies.”</li><li>Within the “custom_policies” directory, generate a new file using either Python or YAML for your custom rule, for instance, “my_custom_rule.py” or “my_custom_rule.yaml.”</li><li>Compose your custom rule using Python or YAML syntax. Consult the Checkov documentation for assistance in crafting custom policies.</li></ol><p>By completing this project, you will have successfully integrated Chekov security scanning into your GitHub Actions pipeline, allowing you to automatically identify and remediate security issues in your Terraform configurations during the development process.</p><p><strong>Conclusion</strong></p><p>Checkov stands as a formidable tool for enhancing the security and compliance of your Terraform code. Through its seamless integration into your development workflow and CI/CD pipeline, Checkov empowers you to proactively identify and rectify potential security vulnerabilities and compliance issues, thereby fortifying your infrastructure deployments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c11374e391e1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a Static Website to AWS S3 using Terraform and GitHub Actions CI/CD Pipeline]]></title>
            <link>https://medium.com/@lasisiabioduntowobola/deploying-a-static-website-to-aws-s3-using-terraform-and-github-actions-8bc932311d79?source=rss-ab7f1d7cdcde------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bc932311d79</guid>
            <category><![CDATA[cicd-pipeline]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Abiodun Lasisi]]></dc:creator>
            <pubDate>Wed, 08 May 2024 14:05:08 GMT</pubDate>
            <atom:updated>2024-05-09T11:51:05.502Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction</strong></p><p>In this article, we will explore how to deploy a static website to AWS S3 using Terraform and GitHub Actions. We will cover the steps to create a Terraform configuration file, set up a GitHub Actions workflow, and deploy our website to S3. Follow along as we break down the process into simple steps and empower you to automate your game deployment workflows.</p><p><strong>Architecture</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FN52d0dxt3hCAkIfS7-Lng.png" /></figure><blockquote><strong><em>Prerequisites</em></strong></blockquote><p>Before we dive into the implementation, ensure you have the following prerequisites in place:</p><ol><li><strong>AWS Accoun</strong>t</li><li><strong>Terraform Cloud Accoun</strong>t</li><li><strong>GitHub Repository</strong></li><li><strong>IDE</strong> of your choice (I will be using VS code)</li></ol><p><strong>Step 1</strong>: Create a Terraform Configuration File<br>Terraform is an infrastructure as code tool that allows us to define our infrastructure in a human-readable configuration file. Begin by creating a Terraform configuration file (main.tf) and define the S3 bucket resource. We will Specify the bucket name, region, and other additional configurations such as access control, bucket ownership controls, bucket public access block and bucket policy.</p><pre># AWS S3 bucket resource<br><br>resource &quot;aws_s3_bucket&quot; &quot;test-bucket&quot; {<br>  bucket = var.my_bucket_name # Name of the S3 bucket<br>}<br><br><br>resource &quot;aws_s3_bucket_ownership_controls&quot; &quot;example&quot; {<br>  bucket = aws_s3_bucket.test-bucket.id<br>  rule {<br>    object_ownership = &quot;BucketOwnerPreferred&quot;<br>  }<br>}<br><br><br>resource &quot;aws_s3_bucket_public_access_block&quot; &quot;example&quot; {<br>  bucket = aws_s3_bucket.test-bucket.id<br><br>  block_public_acls       = false<br>  block_public_policy     = false<br>  ignore_public_acls      = false<br>  restrict_public_buckets = false<br>}<br><br><br># AWS S3 bucket ACL resource<br>resource &quot;aws_s3_bucket_acl&quot; &quot;example&quot; {<br>  depends_on = [<br>    aws_s3_bucket_ownership_controls.example,<br>    aws_s3_bucket_public_access_block.example,<br>  ]<br><br>  bucket = aws_s3_bucket.test-bucket.id<br>  acl    = &quot;public-read&quot;<br>}<br><br><br><br>resource &quot;aws_s3_bucket_policy&quot; &quot;host_bucket_policy&quot; {<br>  bucket =  aws_s3_bucket.test-bucket.id # ID of the S3 bucket<br><br>  # Policy JSON for allowing public read access<br>  policy = jsonencode({<br>    &quot;Version&quot; : &quot;2012-10-17&quot;,<br>    &quot;Statement&quot; : [<br>      {<br>        &quot;Sid&quot;: &quot;PublicReadGetObject&quot;,<br>        &quot;Effect&quot; : &quot;Allow&quot;,<br>        &quot;Principal&quot; : &quot;*&quot;,<br>        &quot;Action&quot; : &quot;s3:GetObject&quot;,<br>        &quot;Resource&quot;: &quot;arn:aws:s3:::${var.my_bucket_name}/*&quot;<br>      }<br>    ]<br>  })<br>}</pre><p>We will also create variables.tf file for our bucket variables</p><pre>variable &quot;my_bucket_region&quot; {<br>    description = &quot;my default bucket region&quot;<br>    type = string<br>    default = &quot;eu-west-2&quot;<br>}<br><br>variable &quot;my_bucket_name&quot; {<br>    description = &quot;my bucket name&quot;<br>    type = string<br>    default = &quot;my-meme-card-game&quot;<br>}</pre><p>Step 2: We will write the configuration for uploading the website code to our S3 bucket and bucket website configuration. You can get the code to the website in this repository <a href="https://github.com/Towobolar/s3-code-pipeline-game"><em>here</em></a></p><pre>module &quot;template_files&quot; {<br>    source = &quot;hashicorp/dir/template&quot;<br><br>    base_dir = &quot;${path.module}/game&quot;<br>}<br><br><br>resource &quot;aws_s3_bucket_website_configuration&quot; &quot;web-config&quot; {<br>  bucket =    aws_s3_bucket.test-bucket.id  # ID of the S3 bucket<br><br>  # Configuration for the index document<br>  index_document {<br>    suffix = &quot;index.html&quot;<br>  }<br>}<br><br><br># AWS S3 object resource for hosting bucket files<br>resource &quot;aws_s3_object&quot; &quot;Bucket_files&quot; {<br>  bucket =  aws_s3_bucket.test-bucket.id # ID of the S3 bucket<br><br>  for_each     = module.template_files.files<br>  key          = each.key<br>  content_type = each.value.content_type<br><br>  source  = each.value.source_path<br>  content = each.value.content<br><br>  # ETag of the S3 object<br>  etag = each.value.digests.md5<br>}</pre><p>We will also create a provider.tf and output.tf to output the website address</p><p>provider.tf</p><pre>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;&gt;= 1.7.4&quot;<br>    }<br>  }<br>}<br><br>provider &quot;aws&quot; {<br>  region  = var.my_bucket_region<br>}</pre><p>outputs.tf</p><pre>output &quot;website_url&quot; {<br>    description = &quot;My website URL&quot;<br>    value = aws_s3_bucket_website_configuration.web-config.website_endpoint<br>}</pre><p><strong>Step 3</strong>: Create backend.tf- This is where our state file will be stored on our Terraform Cloud</p><pre> # The configuration for the `remote` backend.<br>    terraform {<br>      backend &quot;remote&quot; {<br>        # The name of your Terraform Cloud organization.<br>        organization = &quot;terraform-organization&quot;<br><br>        # The name of the Terraform Cloud workspace to store Terraform state files in.<br>        workspaces {<br>          name = &quot;work-space-name&quot;<br>        }<br>      }<br>    }</pre><p><strong>Step 4</strong>: Configure GitHub Actions workflow. Create a file named (terraform.yml) This file will define the deployment pipeline for deploying the S3 resource.</p><pre>name: Deploy website to AWS S3<br><br>on:<br>  push:<br>    branches:<br>      - main<br><br>jobs:<br>  Terraform:<br>    name: &#39;Terraform&#39;<br>    runs-on: ubuntu-latest<br><br>    steps:<br>    - name: Checkout<br>      uses: actions/checkout@v4      <br>      <br>    - name: Setup Terraform<br>      uses: hashicorp/setup-terraform@v1<br>      with:<br>        cli_config_credentials_token: ${{ secrets.tfc_team_token }}<br>      <br>    - name: Terraform Init<br>      run: terraform init<br>      <br>    - name: Terraform Validate<br>      run: terraform validate <br>       <br>    - name: Terraform Plan<br>      run: terraform plan<br>         <br>    - name: Terraform Apply<br>      run: terraform apply -auto-approve</pre><p>The tfc_team_token is the API token generated from Terraform cloud which is saved as a secret in the GitHub repository.</p><p>This workflow file triggers on push events to the main branch, checks out our code, initializes Terraform, and applies our Terraform configuration.</p><p>We are now ready to commit our changes and check the runs in Actions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sscDff3XGP-wVVZI8oEpNg.png" /><figcaption>workflow</figcaption></figure><p>We can see in the image above that our job is completed. Its time to verify from our AWS console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KOehJ3E1GblfbU5LxBzhfQ.png" /><figcaption>S3 bucket</figcaption></figure><p>We can confirm now that S3 bucket has been created and the website files uploaded in it.</p><p>Its time to connect to the website.</p><p>We will copy the website url from outputs in the workflow</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IzaRY1MBdeop10g7uKVmxg.png" /><figcaption>copy website url</figcaption></figure><p>Its time to visit the website. Paste the website url into your browser</p><pre>my-meme-card-game.s3-website.eu-west-2.amazonaws.com</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g4u_mU0msaMi7Tb7PABUNQ.png" /><figcaption>game website</figcaption></figure><p>Conclusion<br>In this article, we learned how to deploy a static website to AWS S3 using Terraform and GitHub Actions. We created a Terraform configuration file, set up a GitHub Actions workflow, and triggered the workflow to deploy our website. This automated workflow allows us to easily deploy our website to S3 without manual intervention.</p><p>You can share the link with families and friend to play with.</p><p>Remember to delete all resources when you’re done playing so you don’t continue to pay for it.</p><p>Thank you for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bc932311d79" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying AWS Infrastructure with Terraform Cloud and GitHub Actions CI/CD Pipeline]]></title>
            <link>https://medium.com/@lasisiabioduntowobola/deploying-aws-vpc-modules-with-terraform-cloud-and-github-actions-ci-cd-pipeline-4c281b82dead?source=rss-ab7f1d7cdcde------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c281b82dead</guid>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Abiodun Lasisi]]></dc:creator>
            <pubDate>Fri, 03 May 2024 12:19:17 GMT</pubDate>
            <atom:updated>2024-05-03T18:29:59.898Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><p>Deploying infrastructure on AWS efficiently and reliably is crucial for many organizations. Terraform, an Infrastructure as Code (IaC) tool, simplifies this process by allowing users to define infrastructure configurations as code. By integrating Terraform with Terraform Cloud and GitHub Actions, organizations can automate and streamline the deployment process, ensuring consistency and reliability in managing AWS resources.</p><p><strong>Architecture</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JZs9fYRdlt0YTMhf20_J6A.png" /></figure><h3>Understanding Terraform Cloud and GitHub Actions</h3><p>Terraform Cloud is a hosted service provided by HashiCorp that offers remote execution of Terraform configurations. It provides collaboration, workspace management, and state management features, making it an ideal choice for teams working on infrastructure automation projects.</p><p>GitHub Actions, on the other hand, is a powerful workflow automation tool integrated into GitHub repositories. It allows developers to build, test, and deploy code directly from their GitHub repositories, enabling seamless CI/CD pipelines.</p><blockquote><strong><em>Prerequisites</em></strong></blockquote><p>Before we dive into the implementation, ensure you have the following prerequisites in place:</p><ol><li><strong>AWS Accoun</strong>t: You need an AWS account with appropriate permissions to create VPCs.</li><li><strong>Terraform Cloud Accoun</strong>t: Sign up for a Terraform Cloud account and create an organization and workspace.</li><li><strong>GitHub Repository</strong>: Create a GitHub repository to store your Terraform configurations</li><li>IDE of your choice (I will be using VS code)</li></ol><p>Let’s start building.</p><p>Step 1: Setting up the Terraform Module- Begin by creating a Terraform module that defines your AWS VPC resources. This module encapsulates the VPC configuration, making it reusable across different projects. Define the VPC resources such as VPC, subnets, route tables, etc., within the module, and establish input variables and output values to make it configurable and flexible.</p><p>I will be using the configuration I built already. You can fork the repository on GitHub <a href="https://github.com/Towobolar/terraform-aws-vpc"><strong><em>here</em></strong></a><strong><em>.</em></strong> You can also learn how to create AWS VPC using Terraform <a href="https://medium.com/@aliatakan/terraform-create-a-vpc-subnets-and-more-6ef43f0bf4c1"><strong><em>here</em></strong></a><strong><em>.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g8NpwLyAjZJiERZ6wivVzg.png" /><figcaption>AWS VPC Module</figcaption></figure><p>Step 2: Configuring GitHub Repository- Create a GitHub repository to host your Terraform code, including the VPC module. Organize the repository structure to include the module directory containing the module’s .tf files. This setup enables version control and collaboration on your infrastructure code.</p><p>Step 3: Configure Terraform Cloud workspace:</p><ul><li>Log in to Terraform Cloud.</li><li>Create a new workspace for your project.</li><li>Connect the workspace to your GitHub repository.</li><li>Set up Terraform Cloud variables.</li></ul><p>Step 4: Create backend.tf- This is where our state file will be stored on our Terraform Cloud</p><pre> # The configuration for the `remote` backend.<br>    terraform {<br>      backend &quot;remote&quot; {<br>        # The name of your Terraform Cloud organization.<br>        organization = &quot;terraform-organization&quot;<br><br>        # The name of the Terraform Cloud workspace to store Terraform state files in.<br>        workspaces {<br>          name = &quot;work-space-name&quot;<br>        }<br>      }<br>    }</pre><p>Step 5: Create an API token from your Terraform cloud. This will be used for our Terraform configuration in our pipeline.</p><p>Go to settings from your Terraform cloud account and click Tokens. Generate API Token</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*efUnSSEBrhGWYxkSpnK7Rw.png" /><figcaption>Generate API Token</figcaption></figure><p>Step 6: Configure GitHub Actions workflow. Create a file named (terraform.yml) This file will define the CI/CD pipeline for deploying the VPC module.</p><p>For this, go to your repository where you have your Terraform modules and click Actions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0dBoC5Hr6KNQwZ49etwYhA.png" /><figcaption>Actions Page</figcaption></figure><p>On the Actions Page, click set up a workflow yourself</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e6jxBRORTq_JKgUm8cnpZA.png" /><figcaption>setting up a workflow</figcaption></figure><p>Step 7: Configuring GitHub Actions Pipeline: Create a GitHub Actions workflow to define the deployment pipeline. Write a workflow YAML file that specifies the steps to be executed during deployment.</p><p>These steps typically include checking out the code, initializing Terraform, planning, and applying changes. Integrate Terraform Cloud into the pipeline to trigger deployments directly from GitHub Actions.</p><ul><li>We have to first name our GitHub actions workflow and define the event that will trigger the workflow and the branch that specifies when the workflow should run when changes are pushed to the branch.</li></ul><pre>name: Deploy AWS VPC Module with Terraform<br><br>on:<br>  push:<br>    branches:   <br>      - main</pre><ul><li>The next section is to define the jobs that make up the workflow. A job represents a set of steps that execute on the same runner. The runs-on specifies the operating system environment for the job. We will also specify the default settings for all steps in the job, such as the shell and working directory.</li></ul><pre>jobs:<br>  Terraform:<br>    name: &#39;Terraform&#39;<br>    runs-on: ubuntu-latest<br>    defaults:<br>      run:<br>        shell: bash<br>        working-directory: ./project-zenith-example</pre><ul><li>The next section is to write the steps for the job. The steps include checking out the code from the repository using the actions/checkout@v4 action and setting up Terraform on the runner.</li></ul><pre>    steps:<br>    - name: Checkout<br>      uses: actions/checkout@v4      <br>      <br>    - name: Setup Terraform<br>      uses: hashicorp/setup-terraform@v1<br>      with:<br>        cli_config_credentials_token: ${{ secrets.tfc_team_token }}</pre><p>The secrets.tfc_team_token is the API token we generated from Terraform cloud in step 5 above. To do this, go to settings in the repository and click secrets. Settings &gt; Security &gt; Secrets and Variables &gt; Actions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l0kxY4diEkrflEvO3wLmHQ.png" /></figure><ul><li>On this page, click on New repository secret. Name your secret and put the API token we generated from Terraform cloud in the secret.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mRTzp9EpraBHdJXYuvSYFQ.png" /></figure><ul><li>The next step is to set the directory that Terraform will execute within. Go to settings in your Terraform workspace, click on remote (custom) on execution mode and set the Terraform working directory to project-zenith-example.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OsTgSSzL8oUy2W0Dk65HlQ.png" /></figure><ul><li>The next section is to Initialize terraform, validate, check the plan and apply.</li></ul><pre>    - name: Terraform Init<br>      run: terraform init<br>      <br>    - name: Terraform Validate<br>      run: terraform validate <br>       <br>    - name: Terraform Plan<br>      run: terraform plan<br>         <br>    - name: Terraform Apply<br>      run: terraform apply -auto-approve</pre><p>We are now ready to commit our changes and check our runs in Actions.</p><p>Below is the workflow in full.</p><pre>name: Terraform CI<br><br>on:<br>  push:<br>    branches:<br>      - main<br><br>jobs:<br>  Terraform:<br>    name: &#39;Terraform&#39;<br>    runs-on: ubuntu-latest<br>    defaults:<br>      run:<br>        shell: bash<br>        working-directory: ./project-zenith-example<br><br>    steps:<br>    - name: Checkout<br>      uses: actions/checkout@v4      <br>      <br>    - name: Setup Terraform<br>      uses: hashicorp/setup-terraform@v1<br>      with:<br>        cli_config_credentials_token: ${{ secrets.tfc_team_token }}<br>      <br>    - name: Terraform Init<br>      run: terraform init<br>      <br>    - name: Terraform Validate<br>      run: terraform validate <br>       <br>    - name: Terraform Plan<br>      run: terraform plan<br>         <br>    - name: Terraform Apply<br>      run: terraform apply -auto-approve<br><br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_9vZywxWWz7b6GLzOO0hkA.png" /></figure><p>Each step in the workflow performs a specific task related to deploying the AWS VPC module with Terraform. Together, these steps automate the deployment process and ensure that the infrastructure is provisioned consistently.</p><p>If we check Terraform cloud, we will notice that our run has been applied automatically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O9ELZUyV428oQTmhiChN0Q.png" /></figure><p>Its time to verify from AWS console.</p><p>This is our VPC created alongside or public and private subnets in the AZ specified.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*twftiZ68Zwu-KZqh0bMrGQ.png" /></figure><p>Don’t forget to destroy your resources after you’re done building.</p><p><strong>Conclusion</strong></p><p>Deploying AWS VPC modules with Terraform Cloud and GitHub Actions Pipeline offers a streamlined approach to managing infrastructure as code. By leveraging Terraform modules for resource encapsulation, integrating with Terraform Cloud for centralized management, and automating deployments with GitHub Actions, organizations can achieve consistency, reliability, and efficiency in deploying AWS infrastructure.</p><p>Thank you for reading 👍and give a like if you enjoyed it 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c281b82dead" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Guide to Publishing Terraform Modules on Terraform Registry]]></title>
            <link>https://medium.com/@lasisiabioduntowobola/a-guide-to-publishing-terraform-modules-on-terraform-registry-0c0270e76d98?source=rss-ab7f1d7cdcde------2</link>
            <guid isPermaLink="false">https://medium.com/p/0c0270e76d98</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Abiodun Lasisi]]></dc:creator>
            <pubDate>Thu, 11 Apr 2024 18:16:13 GMT</pubDate>
            <atom:updated>2024-04-18T10:52:24.403Z</atom:updated>
            <content:encoded><![CDATA[<p>In recent years, Infrastructure as Code (IaC) has emerged as a fundamental approach to managing and provisioning infrastructure in a scalable and efficient manner. One of the key features of Terraform is its modular approach, allowing users to create reusable components called modules. In this guide, we will explore the process of publishing Terraform modules, enabling you to share your infrastructure solutions with the wider community.</p><h4>Why Publish Terraform Modules? Publishing Terraform modules offers several benefits:</h4><ol><li>Reusability: Modules can encapsulate common infrastructure patterns, making it easier to reuse and share code across projects.</li><li>Collaboration: By publishing modules, you contribute to the Terraform community and enable collaboration with other users who may benefit from your solutions.</li><li>Versioning: Modules can be versioned, enabling users to track changes, manage dependencies, and ensure consistency across deployments.</li><li>Documentation: Publishing modules allows you to provide documentation and examples, making it easier for users to understand and utilize your infrastructure solutions.</li></ol><p>In this guide, I will be publishing a VPC Module.</p><blockquote><strong><em>Pre-requisite</em></strong></blockquote><ul><li>Terraform</li><li>GitHub account</li></ul><p>Lets get started</p><p>Step 1: Create your Terraform module configuration from any IDE of your choice. I will be using my VPC module configuration. You can fork the repository <a href="https://github.com/Towobolar/terraform_module_vpc">here</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C-QlGMePxV-07RLpxx8yfQ.png" /><figcaption>Terraform Module config</figcaption></figure><p>Step 2: Create a GitHub repository for your module in the following format — terraform-&lt;Provider_Name&gt;-&lt;Module_Name&gt;.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*58ulMxlbqGrDzU7l_C4Ocg.png" /></figure><p>Step 3: Push the configuration content of your module to the newly created repository.</p><p>Step 4: Create a tag for your repository. Click on Tags on your repository and click create a new release.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bAsCDEBB_DcV9mV5AjIKlQ.png" /></figure><p>Step 5: Assign version to your module. I will name this module v1.0.0. Click publish release once you’re done naming it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rgvH1I_30VGjWj68itwgKw.png" /><figcaption>Versioning</figcaption></figure><p>Step 6: Go to the <a href="https://registry.terraform.io/">Terraform registry</a> and sign in with GitHub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LJ-C21Mi3IHRV1UGPZ3Lpw.png" /><figcaption>Terraform registry</figcaption></figure><p>Step 7: Select the <strong>Publish → Module</strong> option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*eeDqwoUkHQ_PVOtEjKNHjg.png" /></figure><p>Step 8: In this step, I will select the repository containing the VPC module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M5szCc7Hk2gYLFSYzSz_YA.png" /><figcaption>Terraform registry</figcaption></figure><p>After you click on the <strong>Publish Module</strong> button and wait for a couple of seconds, the module will be published.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6OqV1rRi_zAxtwHjzstWFA.png" /><figcaption>vpc module</figcaption></figure><p>Conclusion</p><p>Creating and publishing a custom VPC module with Terraform empowers you to provision and manage AWS VPCs in a consistent, scalable, and efficient manner. By following the steps outlined in this guide, you can contribute to the Terraform community and enable others to leverage your VPC solution for their infrastructure needs. Start sharing your VPC module today and accelerate your AWS infrastructure deployments with Terraform.</p><p>Thank you for reading 👍and give a like if you enjoyed it 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0c0270e76d98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a Highly Available Three-Tier Architecture in AWS with Terraform Cloud]]></title>
            <link>https://medium.com/@lasisiabioduntowobola/deploying-a-highly-available-three-tier-architecture-in-aws-with-terraform-cloud-4074a2220216?source=rss-ab7f1d7cdcde------2</link>
            <guid isPermaLink="false">https://medium.com/p/4074a2220216</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[terraform-cloud]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Abiodun Lasisi]]></dc:creator>
            <pubDate>Mon, 25 Mar 2024 19:13:43 GMT</pubDate>
            <atom:updated>2024-03-28T11:02:46.577Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>Pre-requisite for this project</strong></blockquote><ul><li>AWS account is needed</li><li>IDE of your choice (I will be using VS code)</li><li>Terraform cloud account</li><li>Terraform installed.</li><li>GitHub account</li></ul><p><strong>Architecture</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mDdBov-Zli5S6p7_aGIx6g.png" /></figure><p><strong>Overview</strong></p><p><em>Three-tier architecture comprises a client-server framework organized into three distinct layers: the web layer, the application layer, and the data storage layer.</em></p><p><em>The web or presentation tier, also known as the front end, encompasses the user-facing components of the application, including web servers and the interface.</em></p><p><em>The application tier, often referred to as the back end, hosts the backend logic and source code necessary for data processing and function execution.</em></p><p><em>The data tier is responsible for housing and overseeing the application data, typically serving as the storage location for databases.</em></p><p>Before we start we will configure Terraform cloud workspace.</p><p><strong><em>Create a new workspace in Terraform Cloud and connect it to your version control system (e.g., GitHub). Configure variables and environment settings as needed.</em></strong></p><p>Follow the steps below</p><p>Step 1: Go to <a href="https://app.terraform.io/session">Terraform Cloud by HashiCorp</a> and create your Terraform cloud account.</p><p>Step 2: Create a New workspace and click Version Control</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*8DVpP_xarkkW7nVYUezZCA.png" /></figure><p>Step 3: Click on GitHub App</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*kePZFOvtNYAXq7g9Z1pZ-g.png" /></figure><p>Step 4: Add the repository to your code on this page and click create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*cNibZSMNjAYTyqCA6_o3cA.png" /></figure><p>Step 5: Go to your workspace and click variables. On this page we will add our AWS access key and secret key</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6BB-Ke481AfNg_nbMQPHFA.png" /></figure><p>Let’s start building our infrastructure.</p><p>This three tier architecture will consist of the following</p><ul><li>A Virtual private cloud</li><li>2 public subnet for our presentation layer, 2 private subnet for our application layer and 2 private subnet for our data layer</li><li>Route tables. This is a set of rules, called <em>routes</em>, that determine where network traffic from your subnet or gateway is directed.</li><li>Set up an Application Load Balancer to route traffic to the resources located in the public subnets. Additionally, another Application Load Balancer will be configured to manage traffic flow from the web tier to the app tier, ensuring efficient communication between the two tiers.</li><li>Deploy an EC2 Auto Scaling Group in each of the public subnets, which correspond to the web tier, as well as in the private subnets, which correspond to the app tier. This setup ensures high availability by distributing resources across multiple subnets and tiers.</li><li>A bastion host to connect to our private applications</li><li>A database instance for our RDS MySQL database</li></ul><p><strong>Step 1</strong>: Create a provider.tf file to state the cloud provider we are using and the region where our resources will be managed</p><pre># Configure the AWS Provider<br>provider &quot;aws&quot; {<br>  region = &quot;eu-west-2&quot;<br>}</pre><p><strong>Step 2: </strong>Create VPC (virtual private cloud) in a main.tf file which gives us full control over our virtual networking environment, including resource placement, connectivity, and security.</p><pre>/***************************<br>*     create vpc          *<br>***************************/<br><br>resource &quot;aws_vpc&quot; &quot;three-tier-vpc&quot; {<br>  cidr_block       = &quot;10.0.0.0/16&quot;<br>  instance_tenancy = &quot;default&quot;<br><br>  tags = {<br>    terraform = &quot;true&quot;<br>    Name      = &quot;three tier vpc&quot;<br>  }<br>}</pre><p>Step 3: Create 2 public subnets for our presentation tier, 2 private subnets for our application tier and 2 private subnets for our data tier.</p><pre>/***************************<br>*     public subnet        *<br>***************************/<br><br>resource &quot;aws_subnet&quot; &quot;public-subnet-1&quot; {<br>  vpc_id                  = aws_vpc.three-tier-vpc.id<br>  cidr_block              = &quot;10.0.1.0/24&quot;<br>  availability_zone       = &quot;eu-west-2a&quot;<br>  map_public_ip_on_launch = true<br><br>  tags = {<br>    Name = &quot;public subnet eu-west-2a&quot;<br>  }<br>}<br><br>resource &quot;aws_subnet&quot; &quot;public-subnet-2&quot; {<br>  vpc_id                  = aws_vpc.three-tier-vpc.id<br>  cidr_block              = &quot;10.0.2.0/24&quot;<br>  availability_zone       = &quot;eu-west-2b&quot;<br>  map_public_ip_on_launch = true<br><br>  tags = {<br>    Name = &quot;public subnet eu-west-2b&quot;<br>  }<br>}<br><br>/***************************<br>*     private subnet       *<br>***************************/<br><br>resource &quot;aws_subnet&quot; &quot;private-subnet-1&quot; {<br>  vpc_id            = aws_vpc.three-tier-vpc.id<br>  cidr_block        = &quot;10.0.3.0/24&quot;<br>  availability_zone = &quot;eu-west-2a&quot;<br><br>  tags = {<br>    Name = &quot;private subnet eu-west-2a&quot;<br>  }<br>}<br><br>resource &quot;aws_subnet&quot; &quot;private-subnet-2&quot; {<br>  vpc_id            = aws_vpc.three-tier-vpc.id<br>  cidr_block        = &quot;10.0.4.0/24&quot;<br>  availability_zone = &quot;eu-west-2b&quot;<br><br>  tags = {<br>    Name = &quot;private subnet eu-west-2b&quot;<br>  }<br>}<br><br>/******************************<br>*    database private subnet  *<br>*******************************/<br><br>resource &quot;aws_subnet&quot; &quot;private-subnet-3&quot; {<br>  vpc_id            = aws_vpc.three-tier-vpc.id<br>  cidr_block        = &quot;10.0.5.0/24&quot;<br>  availability_zone = &quot;eu-west-2a&quot;<br><br>  tags = {<br>    Name = &quot;db private subnet eu-west-2a&quot;<br>  }<br>}<br><br>resource &quot;aws_subnet&quot; &quot;private-subnet-4&quot; {<br>  vpc_id            = aws_vpc.three-tier-vpc.id<br>  cidr_block        = &quot;10.0.6.0/24&quot;<br>  availability_zone = &quot;eu-west-2b&quot;<br><br>  tags = {<br>    Name = &quot;db private subnet eu-west-2b&quot;<br>  }<br>}</pre><p>Step 4: Create ec2 autoscaling group and launch template.</p><p>To guarantee continuous availability for the web application and mitigate the risk of any single points of failure, our approach involves establishing an Auto Scaling Group (ASG). This ASG will be responsible for dynamically provisioning Amazon Elastic Compute Cloud (EC2) instances as required, distributing them across multiple Availability Zones (AZs) within our public subnets. Additionally, we will develop a template that the ASG will utilize to autonomously launch EC2 instances in our designated public subnets.</p><p>I will be using ubuntu image id. You can learn how to get one from this <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/finding-an-ami.html">page</a>.</p><pre>/***********************************************<br>*    web auto scaling launch configuration     *<br>************************************************/<br><br>resource &quot;aws_launch_configuration&quot; &quot;three-tier-web-asg-lc&quot; {<br>  name_prefix                 = &quot;three-tier-web-asg-lc&quot;<br>  image_id                    = &quot;ami-0b9932f4918a00c4f&quot;<br>  instance_type               = &quot;t2.micro&quot;<br>  key_name                    = aws_key_pair.three-tier-demo-key.id<br>  associate_public_ip_address = true<br>  security_groups             = [aws_security_group.webserver-sg.id]<br><br><br>  lifecycle {<br>    create_before_destroy = true<br>  }<br>}<br><br>/***********************************************<br>*     web auto scaling group                   *<br>************************************************/<br><br>resource &quot;aws_autoscaling_group&quot; &quot;three-tier-web-asg&quot; {<br>  name                 = &quot;three-tier-web-asg&quot;<br>  launch_configuration = aws_launch_configuration.three-tier-web-asg-lc.id<br>  min_size             = 2<br>  max_size             = 4<br>  desired_capacity     = 2<br>  vpc_zone_identifier  = [aws_subnet.public-subnet-1.id, aws_subnet.public-subnet-2.id]<br><br>  lifecycle {<br>    create_before_destroy = true<br>  }<br>}</pre><p>step 5: Repeat step 4 but configure the EC2 ASG in the private subnets</p><pre>/***********************************************<br>*    app auto scaling launch configuration     *<br>************************************************/<br><br>resource &quot;aws_launch_configuration&quot; &quot;three-tier-app-asg-lc&quot; {<br>  name_prefix     = &quot;three-tier-app-asg-lc&quot;<br>  image_id        = &quot;ami-0b9932f4918a00c4f&quot;<br>  instance_type   = &quot;t2.micro&quot;<br>  key_name        = aws_key_pair.three-tier-demo-key.id<br>  security_groups = [aws_security_group.appserver-sg.id]<br><br>  lifecycle {<br>    create_before_destroy = true<br>  }<br>}<br><br>/***********************************************<br>*     app auto scaling group                   *<br>************************************************/<br><br>resource &quot;aws_autoscaling_group&quot; &quot;three-tier-app-asg&quot; {<br>  name                 = &quot;three-tier-app-asg&quot;<br>  launch_configuration = aws_launch_configuration.three-tier-app-asg-lc.id<br>  min_size             = 2<br>  max_size             = 4<br>  desired_capacity     = 2<br>  vpc_zone_identifier  = [aws_subnet.private-subnet-1.id, aws_subnet.private-subnet-2.id]<br><br>  lifecycle {<br>    create_before_destroy = true<br>  }<br>}</pre><p>Step 6: We will create our security group for our EC2 ASG in the public and private subnets respectively.</p><pre>/***********************************************<br>*     web server security group                *<br>************************************************/<br><br>resource &quot;aws_security_group&quot; &quot;webserver-sg&quot; {<br>  name        = &quot;web-sg&quot;<br>  description = &quot;allow inbound ssh and https traffic&quot;<br>  vpc_id      = aws_vpc.three-tier-vpc.id<br><br>  ingress {<br>    protocol    = &quot;tcp&quot;<br>    self        = true<br>    from_port   = 80<br>    to_port     = 80<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    protocol    = &quot;tcp&quot;<br>    self        = true<br>    from_port   = 22<br>    to_port     = 22<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>}<br><br>/***********************************************<br>*     app server security group                *<br>***********************************************/<br><br>resource &quot;aws_security_group&quot; &quot;appserver-sg&quot; {<br>  name        = &quot;app-sg&quot;<br>  description = &quot;allow inbound ssh&quot;<br>  vpc_id      = aws_vpc.three-tier-vpc.id<br><br>  ingress {<br>    protocol    = &quot;tcp&quot;<br>    self        = true<br>    from_port   = 80<br>    to_port     = 80<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    protocol    = &quot;tcp&quot;<br>    self        = true<br>    from_port   = 22<br>    to_port     = 22<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>}</pre><p>Step 7: Create Key-pair to control login access to EC2 instances.</p><pre>resource &quot;aws_key_pair&quot; &quot;three-tier-demo-key&quot; {<br>  key_name   = &quot;demo-key&quot;<br>  public_key = &quot;ssh-rsa AAAAB3NzaC1yAABgQDuNDjqNLmFDfpAfLyk0xJI/mnsQJY7CBxcAqMOHnEUkRjdVtwDCGDadnG77iZjI0sNpVXqkZacSaxx684xGdy0tWihuixP81Kn+Zsgdwi+Mx4WjPfgT2s27lba2kZhJC0pEr5hzHEJWNwX1aOvQjGzIGr+898y6gwp/DK3cggFEQ/jNBCS76NYUFODQGpR4Wiw9cOo1B1TiGe0UW3H183+h/q1Fv3yGvFm6J0iQC83soT5hcskmuoDbstJF/y5jd7ghcQB+v67C3IWuC9oKnq+mte0oRg7+G7NnGsv1S3yBQobs8AuazOTPUmmQ/q/ThSClqwPUTd3ajfAd2sqz73+04ZDO+oZJsdYUUTl+rPzH3Qsn645iD+NJhK+G9Y8Kq6NWs2x+C2ikIPof8Qk4TNi5DwCNTnhEJthPug6Zw7MhsySNjR5B5lin2Pa9iAmKLQ5XTNDvLs+gNqeEVWoBoYvM78CEh4A7+Q2Q224DvMeKrpgiVqUdI02Ht0= example&quot;<br>}</pre><p>You can <a href="https://docs.oracle.com/en/cloud/cloud-at-customer/occ-get-started/generate-ssh-key-pair.html#GUID-8B9E7FCB-CEA3-4FB3-BF1A-FD3406A2432F"><strong><em>click here</em></strong></a> to learn how to generate key pair</p><p>Step 8: Create Database instance and database security group in our data tier private subnet.</p><pre>/**************************************<br>*      Database subnet group          *<br>**************************************/<br><br>resource &quot;aws_db_subnet_group&quot; &quot;database-sg&quot; {<br>  name       = &quot;main&quot;<br>  subnet_ids = [aws_subnet.private-subnet-3.id, aws_subnet.private-subnet-4.id]<br><br>  tags = {<br>    Name = &quot;My DB subnet group&quot;<br>  }<br>}<br><br>/************************************<br>*     Database instance             *<br>************************************/<br><br>resource &quot;aws_db_instance&quot; &quot;db-instance&quot; {<br>  allocated_storage      = 20<br>  db_name                = &quot;mydb&quot;<br>  engine                 = &quot;mysql&quot;<br>  engine_version         = &quot;5.7&quot;<br>  instance_class         = &quot;db.t3.micro&quot;<br>  username               = &quot;admin&quot;<br>  password               = &quot;password&quot;<br>  parameter_group_name   = &quot;default.mysql5.7&quot;<br>  skip_final_snapshot    = true<br>  db_subnet_group_name   = aws_db_subnet_group.database-sg.id<br>  vpc_security_group_ids = [aws_security_group.db-sg.id]<br>  multi_az               = true<br>}<br><br>/**************************************************<br>*       Security group for Database server        *<br>**************************************************/<br><br>resource &quot;aws_security_group&quot; &quot;db-sg&quot; {<br>  name        = &quot;db_sg&quot;<br>  description = &quot;Allows inbound traffic&quot;<br>  vpc_id      = aws_vpc.three-tier-vpc.id<br><br>  ingress {<br>    from_port   = 3306<br>    to_port     = 3306<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    protocol    = &quot;tcp&quot;<br>    self        = true<br>    from_port   = 22<br>    to_port     = 22<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>}</pre><p>Step 9: Create Bastion host and its security group. A bastion host is a server whose purpose is to provide access to a private network from an external network, such as the Internet. This will help us connect to our private applications.</p><pre>/*******************************<br>*        bastion host         *<br>********************************/<br>resource &quot;aws_instance&quot; &quot;bastion-host&quot; {<br>  ami                         = &quot;ami-0b9932f4918a00c4f&quot;<br>  instance_type               = &quot;t2.micro&quot;<br>  subnet_id                   = aws_subnet.public-subnet-1.id<br>  vpc_security_group_ids      = [aws_security_group.bastion-host-sg.id]<br>  key_name                    = aws_key_pair.three-tier-demo-key.id<br>  associate_public_ip_address = true<br><br>  tags = {<br>    Name = &quot;bastion host instance&quot;<br>  }<br>}<br><br>/***************************************<br>*     bastion host Security group       *<br>****************************************/<br><br>resource &quot;aws_security_group&quot; &quot;bastion-host-sg&quot; {<br>  name        = &quot;bastion host sg&quot;<br>  description = &quot;allows inbound traffic to app server from internet&quot;<br>  vpc_id      = aws_vpc.three-tier-vpc.id<br><br>  ingress {<br>    protocol    = &quot;tcp&quot;<br>    self        = true<br>    from_port   = 22<br>    to_port     = 22<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>}<br></pre><p>Next we will create internet gateway which will enable our ec2 instance in the public subnet to connect to the internet</p><p>Step 10: Create internet gateway</p><pre>/***********************************************<br>*           internet gateway                   *<br>************************************************/<br><br>resource &quot;aws_internet_gateway&quot; &quot;internet-gw&quot; {<br>  vpc_id = aws_vpc.three-tier-vpc.id<br><br>  tags = {<br>    Name = &quot;vpc internet gateway&quot;<br>  }<br>}</pre><p><strong>Step 11:</strong> Create Route table. To make the web tier and application tier talk to each other, we need two route tables — one for each tier. Route tables basically tell traffic where to go. So, we’ll make a route table for the web tier that includes the public subnet connected to our load balancer. Then, we’ll make another route table for the application tier that includes the private subnets linked to our app servers. By connecting these route tables to the right subnets, we ensure that traffic goes where it’s supposed to. This way, the web servers and app servers can chat with each other whenever they need to.</p><pre>/***********************************************<br>*           route table                        *<br>************************************************/<br><br>resource &quot;aws_route_table&quot; &quot;web-route-table&quot; {<br>  vpc_id = aws_vpc.three-tier-vpc.id<br>  tags = {<br>    Name = &quot;webroute table&quot;<br>  }<br><br>  route {<br>    cidr_block = &quot;0.0.0.0/0&quot;<br>    gateway_id = aws_internet_gateway.internet-gw.id<br>  }<br>}<br>resource &quot;aws_route_table&quot; &quot;app-route-table&quot; {<br>  vpc_id = aws_vpc.three-tier-vpc.id<br>  tags = {<br>    Name = &quot;app-route table&quot;<br>  }<br><br>  route {<br>    cidr_block = &quot;0.0.0.0/0&quot;<br>    gateway_id = aws_nat_gateway.nat-gw.allocation_id<br>  }<br>}<br><br>/***********************************************<br>*          Public route table association      *<br>************************************************/<br><br>resource &quot;aws_route_table_association&quot; &quot;public-sn1-2a&quot; {<br>  subnet_id      = aws_subnet.public-subnet-1.id<br>  route_table_id = aws_route_table.web-route-table.id<br>}<br><br>resource &quot;aws_route_table_association&quot; &quot;public-sn2-2b&quot; {<br>  subnet_id      = aws_subnet.public-subnet-2.id<br>  route_table_id = aws_route_table.web-route-table.id<br>}<br><br>/***********************************************<br>*          private route table association     *<br>************************************************/<br>resource &quot;aws_route_table_association&quot; &quot;private-sn1-2a-rt&quot; {<br>  subnet_id      = aws_subnet.private-subnet-1.id<br>  route_table_id = aws_route_table.app-route-table.id<br>}<br><br>resource &quot;aws_route_table_association&quot; &quot;private-sn2-2b-rt&quot; {<br>  subnet_id      = aws_subnet.private-subnet-2.id<br>  route_table_id = aws_route_table.app-route-table.id<br>}<br><br>resource &quot;aws_route_table_association&quot; &quot;private-sn3-2a-rt&quot; {<br>  subnet_id      = aws_subnet.private-subnet-3.id<br>  route_table_id = aws_route_table.app-route-table.id<br>}<br><br>resource &quot;aws_route_table_association&quot; &quot;private-sn4-2a-rt&quot; {<br>  subnet_id      = aws_subnet.private-subnet-4.id<br>  route_table_id = aws_route_table.app-route-table.id<br>}<br><br></pre><p><strong>Step 12:</strong> Create NAT gateway and an elastic ip. We are creating this so that our instances in private subnet can connect to services outside our VPC but external services cannot initiate a connection with the instances.</p><pre>/***********************************************<br>*           elastic ip                         *<br>************************************************/<br><br>resource &quot;aws_eip&quot; &quot;elastic-ip&quot; {<br>  domain = &quot;vpc&quot;<br><br><br>  tags = {<br>    Name = &quot;Nat eip&quot;<br>  }<br>}<br><br>/***********************************************<br>*           Nat Gateway                        *<br>************************************************/<br><br>resource &quot;aws_nat_gateway&quot; &quot;nat-gw&quot; {<br>  allocation_id = aws_eip.elastic-ip.id<br>  subnet_id     = aws_subnet.public-subnet-1.id<br><br>  tags = {<br>    Name = &quot;three-tier-nat-gw&quot;<br>  }<br><br>  # To ensure proper ordering, it is recommended to add an explicit dependency<br>  # on the Internet Gateway for the VPC.<br>  depends_on = [aws_internet_gateway.internet-gw]<br>}</pre><p>Lastly, we will create our application load balancer which automatically distributes incoming application traffic across multiple targets and virtual appliances in one or more Availability Zones (AZs).</p><p><strong>Step 13:</strong> Create application load balancer.</p><p>The load balancer will automatically distributes incoming traffic across our ASG. We will create alb for our web and app server ASG.</p><pre>/**************************************************<br>*       Application load balancer for webserver   *<br>***************************************************/<br><br>resource &quot;aws_lb&quot; &quot;webserver-asg-alb&quot; {<br>  name               = &quot;webserver-asg-lb&quot;<br>  internal           = false<br>  load_balancer_type = &quot;application&quot;<br>  security_groups    = [aws_security_group.webserver-sg.id]<br>  subnets            = [aws_subnet.public-subnet-1.id, aws_subnet.public-subnet-2.id]<br>}<br><br>resource &quot;aws_lb_target_group&quot; &quot;alb-target-grp-webserver&quot; {<br>  name        = &quot;web-alb-target-grp&quot;<br>  target_type = &quot;instance&quot;<br>  port        = 80<br>  protocol    = &quot;HTTP&quot;<br>  vpc_id      = aws_vpc.three-tier-vpc.id<br>}<br><br>/*resource &quot;aws_lb_target_group_attachment&quot; &quot;my-aws-alb1&quot; {<br>  target_group_arn = aws_lb_target_group.alb-target-grp.id<br>  target_id        = aws_instance<br>  port             = 80<br>}*/<br><br># Create a new ALB Target Group attachment<br>resource &quot;aws_autoscaling_attachment&quot; &quot;asg-attachment&quot; {<br>  autoscaling_group_name = aws_autoscaling_group.three-tier-web-asg.id<br>  lb_target_group_arn    = aws_lb_target_group.alb-target-grp-webserver.arn<br>}<br><br>resource &quot;aws_lb_listener&quot; &quot;lb_lst&quot; {<br>  load_balancer_arn = aws_lb.webserver-asg-alb.arn<br>  port              = &quot;80&quot;<br>  protocol          = &quot;HTTP&quot;<br><br>  default_action {<br>    type             = &quot;forward&quot;<br>    target_group_arn = aws_lb_target_group.alb-target-grp-webserver.arn<br>  }<br>} <br><br>/***********************************************<br>*  Application load balancer for app server    *<br>***********************************************/<br><br>resource &quot;aws_lb&quot; &quot;appserver-asg-alb&quot; {<br>  name               = &quot;appserver-asg-lb&quot;<br>  internal           = false<br>  load_balancer_type = &quot;application&quot;<br>  security_groups    = [aws_security_group.appserver-sg.id]<br>  subnets            = [aws_subnet.private-subnet-1.id, aws_subnet.private-subnet-2.id]<br>}<br><br>resource &quot;aws_lb_target_group&quot; &quot;alb-target-grp-appserver&quot; {<br>  name        = &quot;app-alb-target-grp&quot;<br>  target_type = &quot;instance&quot;<br>  port        = 80<br>  protocol    = &quot;HTTP&quot;<br>  vpc_id      = aws_vpc.three-tier-vpc.id<br>}<br><br># Create a new ALB Target Group attachment<br>resource &quot;aws_autoscaling_attachment&quot; &quot;appserver-asg-attachment&quot; {<br>  autoscaling_group_name = aws_autoscaling_group.three-tier-app-asg.id<br>  lb_target_group_arn    = aws_lb_target_group.alb-target-grp-appserver.arn<br>}<br><br><br><br>resource &quot;aws_lb_listener&quot; &quot;lb_lst-appserver&quot; {<br>  load_balancer_arn = aws_lb.appserver-asg-alb.arn<br>  port              = &quot;80&quot;<br>  protocol          = &quot;HTTP&quot;<br><br>  default_action {<br>    type             = &quot;forward&quot;<br>    target_group_arn = aws_lb_target_group.alb-target-grp-appserver.arn<br>  }<br>}</pre><p><strong>It’s time to deploy</strong></p><p>After writing our terraform configuration on our preferred IDE, we will push it to our GitHub and apply our run in Terraform cloud.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*_NN6tESFTD4QabPDvCAwgw.png" /></figure><p><strong>After Deploying, we need to go to our AWS console to verify</strong></p><ul><li>This is our VPC</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6FX6yLmb-_wBJ8SW6sX6YA.png" /></figure><p>This is our ASG instance and Bastion host</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zExRsq4AoX-O8E1YKGWN7A.png" /></figure><p>This is our Database</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9VdxhvV6UgXloabCqUrdBg.png" /></figure><p>We will now ssh into our web and app servers.</p><p>You can check how to ssh into an instance <a href="https://www.clickittech.com/aws/connect-ec2-instance-using-ssh/">here</a></p><p>Web server connection</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X9CEuT2UGeMBNS_EoutIEg.png" /></figure><p>We will ping our app server with the private ip from our private ec2 instance</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*0KcX1rRsnI9Qs4QMpnt3mg.png" /></figure><p>To connect to our database server, we will login to our app server through our bastion host server and access our database through it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*0aZMxmKjUMFpNmeFnZ3CUw.png" /><figcaption>Connection to app server from bastion host server</figcaption></figure><p>Finally, we connect to our database from our app server.</p><p>we will first install MySQL database on the server with this command</p><pre>sudo apt install mysql-client-core-8.0 </pre><p>Then we ssh in to the database with the command</p><pre>mysql -h &lt;your database endpoint&gt; -P 3306 -u &lt;database username&gt; -p</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9uoFZyNcZRH3uz_6TM1RLw.png" /><figcaption>RDS MYSQL Database</figcaption></figure><p>Don&#39;t forget to destroy your resources after you’re done building.</p><p>Thank you for reading 👍and give a like if you enjoyed it 😊</p><p>GitHub repository link <a href="https://github.com/Towobolar/three-tier-architecture"><strong><em>click here</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4074a2220216" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>