<?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 Sunday Nwoye on Medium]]></title>
        <description><![CDATA[Stories by Sunday Nwoye on Medium]]></description>
        <link>https://medium.com/@sonynwoye?source=rss-cf9f429d8253------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*XcU2KkU2f9gl6kSb</url>
            <title>Stories by Sunday Nwoye on Medium</title>
            <link>https://medium.com/@sonynwoye?source=rss-cf9f429d8253------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 02:19:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sonynwoye/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[Deploying Resilient and Scalable Dynamic Web Applications with Terraform: A Comprehensive Guide to…]]></title>
            <link>https://medium.com/@sonynwoye/deploying-resilient-and-scalable-dynamic-web-applications-with-terraform-a-comprehensive-guide-to-2c2ce6f0d044?source=rss-cf9f429d8253------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c2ce6f0d044</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[iac]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Sunday Nwoye]]></dc:creator>
            <pubDate>Tue, 24 Oct 2023 00:15:31 GMT</pubDate>
            <atom:updated>2023-10-25T23:51:42.823Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deploying Resilient and Scalable Dynamic Web Applications with Terraform: A Comprehensive Guide to High Availability and Security</h3><p>This project will guide and teach you how to deploy a scalable, highly available, and secure dynamic web application using Terraform :).</p><p><strong><em>This is one project you could show to your hiring manager or recruiters during interviews.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*XQqUfMLbqb7NTIjF2jKvKg.gif" /><figcaption>GIF by me</figcaption></figure><p><strong>Architecture Diagram:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iNs9-6WYCCoLjlhlsl589g.png" /><figcaption>photo by me</figcaption></figure><p><strong>Introduction:</strong></p><p>Have you ever wondered how top-tier websites and apps maintain their seamless performance while keeping security intact? It’s all about High Availability (HA) and security. HA ensures consistent, uninterrupted operation, making it a critical asset for your infrastructure. This reliability is achieved by eliminating single points of failure and preparing every tech layer for redundancy. And all seamlessly automated with Terraform.</p><p><strong>Terraform: </strong>Terraform is Infrastructure as Code (IaC) software. It allows you to define and provision your infrastructure using code, which means you can treat your infrastructure as if it were software. This brings a host of benefits, including version control, reusability, repeatability, and collaboration.</p><h3>Objective</h3><p>1. <strong>Environment Setup</strong>: Configure your development environment on Visual Studio Code (VS Code).<br>2. <strong>File Preparation: </strong>Create and understand the purpose of essential files, including alb.tf, variables.tf, asg.tf, etc. You can access these files on my <a href="https://github.com/profebass99/dummy-app-project"><strong>GitHub repository</strong></a>.<br>3. <strong>File Explanation &amp; Population</strong>: Provide detailed explanations for each of the files mentioned above.<br>4. <strong>Resource Provisioning:</strong> Use Terraform to provision the necessary resources.<br>5. <strong>Resource Verification</strong>: Check and validate the provisioned resources through the AWS Management Console.<br>6. <strong>Website Access:</strong> Access your website and perform a high-availability (HA) test.<br>7. <strong>Resource Cleanup:</strong> Practice resource management by using Terraform to destroy resources when they are no longer needed.<br>8. Conclusion.</p><h3><strong>Prerequisites</strong></h3><p>Before we embark on the deployment journey, we must ensure we have the following essentials in place.</p><ul><li><strong>Application Code, SQL Script, and AppServiceProvider.php:</strong> Acquire the required application code and SQL script, available using any of these <a href="https://drive.google.com/drive/folders/1iRMFURMI8IOS0J6-1965OHsenJvtr74q"><strong>link1</strong></a><br>-<strong>Application code</strong>: contains source code and files that make up your web application.<br>- <strong>SQL script:</strong> contains script to set up our database schema and data required for our application.<br>- <strong>AppServiceProvider.php: </strong>enforces secure HTTPS connections for the application by using the forceScheme method to ensure all URLs use the &quot;https&quot; scheme.</li><li><strong>AWS Account:</strong> You’ll need an AWS account to host your application and database. If you don’t have one, you can sign up on the <a href="https://aws.amazon.com/console/"><strong>AWS website</strong></a> or follow the provided <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwiRzYGu2ImCAxXPQaQEHZb7BtcQwqsBegQIIhAG&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DFKCh9drnc5E&amp;usg=AOvVaw23MAoRF3Pz5W7S7m3AZjuF&amp;opi=89978449"><strong>instructions </strong></a>on how to create one.</li><li><strong>Integrated Development Environment (IDE</strong>): Install an Integrated Development Environment (IDE) such as Visual Studio Code (VS Code) to streamline your development and deployment processes. Download and install VS Code from <a href="https://developer.hashicorp.com/terraform/downloads"><strong>here </strong></a>based on your operating system.</li><li><strong>Terraform Setup:</strong> Ensure that Terraform is installed on your local machine. For an enhanced infrastructure-as-code workflow, consider installing the Terraform extension for Visual Studio Code. Refer to this <a href="https://developer.hashicorp.com/terraform/downloads"><strong>guide</strong></a> for installation <strong>instru</strong>c<strong>tions (Depending on your OS)</strong>.</li><li><strong>AWS CLI Configuration:</strong> Install the AWS Command Line Interface (CLI) and configure it with programmatic access credentials for the “terraform-user” profile.</li><li><strong>AWS S3 Bucket</strong>: Create an AWS S3 bucket where your application code and SQL script will be stored.</li><li><strong>AWS Secret Manager</strong>: Configure AWS Secret Manager to securely store sensitive database information, including passwords and usernames.</li><li><strong>Domain:</strong> If you already have a domain, great! If not, learn how to register a domain on AWS by following this <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;ved=2ahUKEwjP-fu014mCAxXMT6QEHdwRBDgQFnoECDUQAQ&amp;url=https%3A%2F%2Faws.plainenglish.io%2Fhow-to-register-a-domain-name-with-amazon-80a1bf809859&amp;usg=AOvVaw2QKuYQr6mG6v6w4J538Cq9&amp;opi=89978449"><strong>link</strong></a>. Please note that domain registration may involve additional fees.</li><li><strong>SSL Certificate</strong>: Establish an SSL certificate for secure HTTPS connections on AWS using AWS Certificate Manager (ACM). Refer to a separate tutorial on creating an SSL certificate <a href="https://medium.com/@sonynwoye/creating-ssl-certificates-using-aws-certificate-manager-acm-1c359e70ce4d"><strong>here</strong></a>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IS1CucWv4WsCFQWb.jpg" /></figure><p><strong>Let’s Go!!! </strong>Now let the fun begin! :) Follow the steps below…..</p><h3><strong>Create IAM user on AWS IAM:</strong></h3><p>We need to go into our AWS console and create an<strong> IAM user with admin privileges,</strong> then we <strong>generate access credentials</strong> for that user, by doing this we can configure our terraform to manage resources on AWS, <strong>To create an IAM user use this link </strong><a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/getting-set-up.html"><strong>here</strong></a><strong>.</strong></p><h3><strong>Install AWS CLI:</strong></h3><ul><li>Start by ensuring you have the AWS CLI installed on your computer or server. If you don’t already have it, you can follow the instructions to download and install it from<strong> this </strong><a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html"><strong>link</strong></a>.</li></ul><h3><strong>Configure IAM Profile for Terraform:</strong></h3><ul><li>This profile encompasses the Access Key, Secret Key we generated previously, and region details for an IAM User, facilitating secure connections to AWS resources. Here’s how we configure a profile Terraform, follow the steps below:</li><li>Open your terminal (<strong>assuming we have installed aws cli in the previous step</strong>), and run the following command below to set up our terraform-user profile.</li></ul><pre>$ aws configure --profile terraform-user<br>AWS Access Key ID [None]: AKIAIObnSFODN # Replace with your Access Key ID<br>AWS Secret Access Key [None]: # Replace with your Secret Access Key<br>Default region name [None]: us-east-1<br>Default output format [None]: json</pre><ul><li>Our profile for Terraform has been successfully created and this Terraform profile will be used in our Terraform script. Now we create our S3 bucket.</li></ul><h3><strong>Create an S3 bucket to store our application code and SQL Script:</strong></h3><p>Here we will create the bucket that will be used to store our application code and also store our terraform state file… This bucket will serve as source storage from where our application code will be stored and where our terraform will keep the state file.</p><ul><li>Go to the AWS Management Console (<a href="https://aws.amazon.com/">https://aws.amazon.com/</a>) and sign in to your AWS account.</li><li>Once you are logged in, search for “S3” in the AWS services search bar. Click on “S3” to access the S3 dashboard.</li><li>In the S3 dashboard, click the “Create bucket” button.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*4pRluKqj34vk9OmabcYqDw.png" /></figure><ul><li>Enter a unique name for your bucket. The bucket name must be globally unique across all AWS S3 bucket names. Bucket names can contain only lowercase letters, numbers, hyphens, and periods.</li><li>Choose the AWS region where you want to create your bucket. This region determines where your data will be stored. Select a region that is geographically closest to your users or your application.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*JXhoGt5wgpsbaWcnSE--_Q.png" /></figure><ul><li>Leave every other thing as default, review the configuration settings to ensure they are correct &amp; click the “Create bucket” button. AWS will create the bucket with the specified settings.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*MSNQ96npHDgAEagoClOC6A.png" /></figure><ul><li>Once the bucket is created, you will see a confirmation message. You can now use this S3 bucket to store, manage, and retrieve objects (files) as needed.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*jyMnJKgvxDskqAW66H4wBw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*T2nyKb591DftnICVbPqfOg.png" /></figure><blockquote><strong>Once our bucket has been created we need to upload and push our application code and SQL script we downloaded previously, to our s3 bucket, which will be used later by our EC2 instance.</strong></blockquote><h3><strong>Create a secret in the AWS secret manager for our database:</strong></h3><blockquote><strong>Once our bucket has been created, the next step is to create secrets using AWS Secrets Manager. This security measure is essential because we want to avoid storing our sensitive database credentials directly in our code. In our security-focused environment, safeguarding our credentials is a top priority. Therefore, we will store our database credentials securely in AWS Secrets Manager. Then, when we execute our Terraform code, we will retrieve these credentials dynamically during runtime. This approach ensures that sensitive information is never hard-coded in our Terraform scripts, enhancing the security of our infrastructure.</strong></blockquote><p>To create an AWS Secrets Manager secret for your database credentials, follow these steps:</p><ul><li>Once you are logged in to your account, search for “Secrets Manager” in the AWS services search bar, in the AWS services menu. Click on “Secrets Manager” to access the Secrets Manager dashboard.</li><li>In the Secrets Manager dashboard, click the “Store a new secret” button to create a new secret.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AwYXEniq3r6srFINcjiZXg.png" /></figure><ul><li>Select the “Other type of secret” option.</li><li>in the key/value pair option select “Plaintext”</li><li>Username: Enter the username for your database.</li><li>Password: Enter the password for your database. .</li><li>Database name: Enter the name of the database to which you want to connect. Note!! this database name will be used as well when creating our database with our terraform script.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*CoCvGNYWK0CO9HIWwdM6vQ.png" /></figure><ul><li>Give your secret a name and description, Leave every other option as default and click on “Next”.</li><li>Review all the settings once more to ensure they are accurate. If everything looks good, click the “Store” button to create the secret.</li><li>After successfully creating the secret, you will receive a confirmation message. You can now use this secret to securely access your database from your applications.</li></ul><h3>Create SSL certificate for secure connection:</h3><p>To enhance the security of our application, it’s crucial to create an SSL certificate using AWS ACM. This cert will help us access our dynamic website using a secure connection. I’ve put together a mini concise tutorial on how to generate your SSL certificate right <a href="https://medium.com/@sonynwoye/creating-ssl-certificates-using-aws-certificate-manager-acm-1c359e70ce4d?source=your_stories_page-------------------------------------"><strong>here</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/0*huEsOu2-uoBSS-G9.jpg" /><figcaption>Photo by google.com</figcaption></figure><p><strong>Keep pushing!!!!!!!!!!!! You can do it trust me :)</strong></p><h3><strong>Part 1: Set up your development environment on VS Code:</strong></h3><p>Now we will set up our IDE, and open Visual Studio Code, If you haven’t already installed VS Code, you can download it from the official website (<a href="https://code.visualstudio.com/">https://code.visualstudio.com/</a>) and follow the installation instructions for your operating system.</p><ul><li>Open VS Code.</li><li>Click on “File” in the top-left corner.</li><li>Select “Open Folder” to create a new project directory or open an existing one.</li><li>Change to the Project Directory</li><li>Once you’ve created or opened a folder, it will appear on the left-hand sidebar.</li><li>Click on the folder to select it as your current working directory.</li></ul><p>Now, you’re all set up in your project directory within VS Code. You can start creating and editing files, installing extensions, and writing code for your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PtYMH5poE5DndPBCrRybig.png" /></figure><h3>Part 2: Creating the Necessary Terraform Files</h3><p>In this part, inside our Project Directory, we will be creating various Terraform files for our project. Each of these files will house the essential resources required to successfully deploy a fully scalable dynamic web application.<em> I know creating these files and populating them can be hectic, so I have made them available for you in my</em> <strong>GitHub repo here.</strong></p><p><strong>List of files that will be created:</strong></p><ul><li>alb.tf</li><li>asg.tf</li><li>data-migrate-ec2.tf</li><li>iam-role.tf</li><li>install-and-configure-nest-app.sh.tpl <strong>(User data script)</strong></li><li>migrate-nest-sql.sh.tpl<strong>(User data script)</strong></li><li>main.tf</li><li>natgateway.tf</li><li>output.tf</li><li>rds-database.tf</li><li>route-53.tf</li><li>security-group.tf</li><li>sns.tf</li><li>variable.tf</li><li>vpc.tf</li><li>terraform.tfvars</li></ul><p>The files created should look like this below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*xCMprJ4nbAZGcebdV0aBZA.png" /></figure><h3><strong>Part 3: Populating files</strong></h3><p><strong>a). main.tf <em>file </em>:</strong></p><p>In the main.tf file, Terraforms AWS provider is configured for the &#39;us-east-1&#39; region with the &#39;<strong>terraform-user</strong>&#39; profile, which we previously set up using the programmatic credentials generated from the <strong>IAM </strong>user. Additionally, the file establishes the Terraform backend configuration, utilizing an S3 bucket we have previously created to store the state file. It specifies both the path and the region for the state file. This setup ensures that Terraform can effectively manage infrastructure changes while securely storing its state information remotely on s3.</p><pre>provider &quot;aws&quot; {<br>  region  = &quot;us-east-1&quot;<br>  profile = &quot;terraform-user&quot;<br>}<br><br>terraform {<br>  backend &quot;s3&quot; {<br>    bucket  = &quot;project-bucket&quot; #replace with your bucket name created previously<br>    key     = &quot;terraform.tfstate.dev&quot;<br>    region  = &quot;us-east-1&quot;<br>    profile = &quot;terraform-user&quot;<br>  }<br>}</pre><p><strong>b). vpc.tf <em>file </em>(VPC — Virtual Private Cloud):</strong></p><p>vpc.tf defines the Virtual Private Cloud (VPC) settings. VPC is the foundational networking component in AWS. In this file, we specify the network structure, including subnets, routing tables, Internet Gateways, etc. Our VPC setup ensures secure isolation and routing of traffic within our AWS environment, providing a stable and scalable network foundation.</p><pre># create vpc<br># terraform aws create vpc<br>resource &quot;aws_vpc&quot; &quot;terraform_vpc&quot; {<br>  cidr_block           = var.cidr_block[0]<br>  instance_tenancy     = var.instance_tenancy<br>  enable_dns_hostnames = true<br>  enable_dns_support   = true<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-vpc&quot;<br>  }<br>}<br><br># create internet gateway and attach it to vpc<br># terraform aws create internet gateway<br>resource &quot;aws_internet_gateway&quot; &quot;internet_gateway&quot; {<br>  vpc_id = aws_vpc.terraform_vpc.id<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-IGW&quot;<br>  }<br>}<br><br># create public subnet az1<br># terraform aws create subnet<br>resource &quot;aws_subnet&quot; &quot;public_subnet_az1&quot; {<br>  vpc_id                  = aws_vpc.terraform_vpc.id<br>  cidr_block              = var.cidr_block[1]<br>  availability_zone       = var.availability_zone[0]<br>  map_public_ip_on_launch = true<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-public-subnet-AZ1&quot;<br>  }<br>}<br><br># create public subnet az2<br># terraform aws create subnet<br>resource &quot;aws_subnet&quot; &quot;public_subnet_az2&quot; {<br>  vpc_id                  = aws_vpc.terraform_vpc.id<br>  cidr_block              = var.cidr_block[2]<br>  availability_zone       = var.availability_zone[1]<br>  map_public_ip_on_launch = true<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-public-subnet-AZ2&quot;<br>  }<br>}<br><br># create route table and add public route<br># terraform aws create route table<br>resource &quot;aws_route_table&quot; &quot;public_route_table&quot; {<br>  vpc_id = aws_vpc.terraform_vpc.id<br><br>  route {<br>    cidr_block = var.default_route<br>    gateway_id = aws_internet_gateway.internet_gateway.id<br>  }<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-public-routetable-AZ1&quot;<br>  }<br>}<br><br># associate public subnet az1 to &quot;public route table&quot;<br># terraform aws associate subnet with route table<br>resource &quot;aws_route_table_association&quot; &quot;public_subnet_az1_route_table_association&quot; {<br>  subnet_id      = aws_subnet.public_subnet_az1.id<br>  route_table_id = aws_route_table.public_route_table.id<br>}<br><br># associate public subnet az2 to &quot;public route table&quot;<br># terraform aws associate subnet with route table<br>resource &quot;aws_route_table_association&quot; &quot;public_subnet_2_route_table_association&quot; {<br>  subnet_id      = aws_subnet.public_subnet_az2.id<br>  route_table_id = aws_route_table.public_route_table.id<br>}<br><br># create private app subnet az1<br># terraform aws create subnet<br>resource &quot;aws_subnet&quot; &quot;private_app_subnet_az1&quot; {<br>  vpc_id                  = aws_vpc.terraform_vpc.id<br>  cidr_block              = var.cidr_block[3]<br>  availability_zone       = var.availability_zone[0]<br>  map_public_ip_on_launch = false<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-private-app-subnet-AZ1&quot;<br>  }<br>}<br><br># create private app subnet az2<br># terraform aws create subnet<br>resource &quot;aws_subnet&quot; &quot;private_app_subnet_az2&quot; {<br>  vpc_id                  = aws_vpc.terraform_vpc.id<br>  cidr_block              = var.cidr_block[4]<br>  availability_zone       = var.availability_zone[1]<br>  map_public_ip_on_launch = false<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-private-app-subnet-AZ2&quot;<br>  }<br>}<br><br># create private data subnet az1<br># terraform aws create subnet<br>resource &quot;aws_subnet&quot; &quot;private_data_subnet_az1&quot; {<br>  vpc_id                  = aws_vpc.terraform_vpc.id<br>  cidr_block              = var.cidr_block[5]<br>  availability_zone       = var.availability_zone[0]<br>  map_public_ip_on_launch = false<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-private-data-subnet-AZ1&quot;<br>  }<br>}<br><br># create private data subnet az2<br># terraform aws create subnet<br>resource &quot;aws_subnet&quot; &quot;private_data_subnet_az2&quot; {<br>  vpc_id                  = aws_vpc.terraform_vpc.id<br>  cidr_block              = var.cidr_block[6]<br>  availability_zone       = var.availability_zone[1]<br>  map_public_ip_on_launch = false<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-private-data-subnet-AZ2&quot;<br>  }<br>}</pre><p><strong>c). Natgateway.tf</strong> file</p><p>In the natgateway.tf file, we set up 2 NAT gateways as part of our multi-tier architecture and associated resources for efficient outbound internet access. Key components include Elastic IP allocation, the creation of NAT gateways in separate availability zones, and the setup of private route tables with associated private subnets. These elements collectively enhance network connectivity and security within our infrastructure.</p><pre># allocate elastic ip. this eip will be used for the nat-gateway in the public subnet az1 <br># terraform aws allocate elastic ip<br>resource &quot;aws_eip&quot; &quot;eip_for_nat_gateway_az1&quot; {<br>  domain = &quot;vpc&quot; # update, this is the correct code.<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-nat-eip1&quot;<br>  }<br>}<br><br># allocate elastic ip. this eip will be used for the nat-gateway in the public subnet az2<br># terraform aws allocate elastic ip<br>resource &quot;aws_eip&quot; &quot;eip_for_nat_gateway_az2&quot; {<br>  domain = &quot;vpc&quot; # update, this is the correct code.<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-nat-eip2&quot;<br>  }<br>}<br><br># create nat gateway in public subnet az1<br># terraform create aws nat gateway<br>resource &quot;aws_nat_gateway&quot; &quot;nat_gateway_az1&quot; {<br>  allocation_id = aws_eip.eip_for_nat_gateway_az1.id<br>  subnet_id     = aws_subnet.public_subnet_az1.id<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-natgw-AZ1&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_gateway]<br>}<br><br># create nat gateway in public subnet az2<br># terraform create aws nat gateway<br>resource &quot;aws_nat_gateway&quot; &quot;nat_gateway_az2&quot; {<br>  allocation_id = aws_eip.eip_for_nat_gateway_az2.id<br>  subnet_id     = aws_subnet.public_subnet_az2.id<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-natgw-AZ2&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_gateway]<br>}<br><br># create private route table az1 and add route through nat gateway az1<br># terraform aws create route table<br>resource &quot;aws_route_table&quot; &quot;private_route_table_az1&quot; {<br>  vpc_id = aws_vpc.terraform_vpc.id<br><br>  route {<br>    cidr_block     = var.default_route<br>    nat_gateway_id = aws_nat_gateway.nat_gateway_az1.id<br>  }<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-private-routetable-AZ1&quot;<br>  }<br>}<br><br># associate private app subnet az1 with private route table az1<br># terraform aws associate subnet with route table<br>resource &quot;aws_route_table_association&quot; &quot;private_app_subnet_az1_route_table_az1_association&quot; {<br>  subnet_id      = aws_subnet.private_app_subnet_az1.id<br>  route_table_id = aws_route_table.private_route_table_az1.id<br>}<br><br># associate private data subnet az1 with private route table az1<br># terraform aws associate subnet with route table<br>resource &quot;aws_route_table_association&quot; &quot;private_data_subnet_az1_route_table_az1_association&quot; {<br>  subnet_id      = aws_subnet.private_data_subnet_az1.id<br>  route_table_id = aws_route_table.private_route_table_az1.id<br>}<br><br># create private route table az2 and add route through nat gateway az2<br># terraform aws create route table<br>resource &quot;aws_route_table&quot; &quot;private_route_table_az2&quot; {<br>  vpc_id = aws_vpc.terraform_vpc.id<br><br>  route {<br>    cidr_block     = var.default_route<br>    nat_gateway_id = aws_nat_gateway.nat_gateway_az2.id<br>  }<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-private-routetable-AZ2&quot;<br>  }<br>}<br><br># associate private app subnet az2 with private route table az2<br># terraform aws associate subnet with route table<br>resource &quot;aws_route_table_association&quot; &quot;private_app_subnet_az2_route_table_az2_association&quot; {<br>  subnet_id      = aws_subnet.private_app_subnet_az2.id<br>  route_table_id = aws_route_table.private_route_table_az2.id<br>}<br><br># associate private data subnet az2 with private route table az2<br># terraform aws associate subnet with route table<br>resource &quot;aws_route_table_association&quot; &quot;private_data_subnet_az2_route_table_az2_association&quot; {<br>  subnet_id      = aws_subnet.private_data_subnet_az2.id<br>  route_table_id = aws_route_table.private_route_table_az2.id<br>}</pre><p><strong>d). alb.tf file</strong>:</p><p>alb.tf is the file where we define configurations for our Application Load Balancer (ALB), specifying its attributes, listener rules, security groups, subnet placement, and tags to make our infrastructure deployment flexible and organized, the load balancer will help us manage and balance traffics to/from our application, in here for our https connection we are using or importing the SSL certificate we created earlier into our load balancer.</p><pre># create application load balancer<br># terraform aws create application load balancer<br>resource &quot;aws_lb&quot; &quot;application_load_balancer&quot; {<br>  name               = var.alb_name<br>  internal           = false<br>  load_balancer_type = &quot;application&quot;<br>  security_groups    = [aws_security_group.alb_security_group.id]<br>  subnets            = [aws_subnet.public_subnet_az1.id, aws_subnet.public_subnet_az2.id]<br><br>  enable_deletion_protection = false<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-alb&quot;<br>  }<br>}<br><br># create target group<br># terraform aws create target group<br>resource &quot;aws_lb_target_group&quot; &quot;alb_target_group&quot; {<br>  name        = var.target_group_name<br>  target_type = &quot;instance&quot;<br>  port        = 80<br>  protocol    = &quot;HTTP&quot;<br>  vpc_id      = aws_vpc.terraform_vpc.id<br><br>  health_check {<br>    healthy_threshold   = 5<br>    interval            = 300<br>    matcher             = &quot;200,301,302&quot;<br>    path                = &quot;/&quot;<br>    port                = &quot;traffic-port&quot;<br>    protocol            = &quot;HTTP&quot;<br>    timeout             = 5<br>    unhealthy_threshold = 2<br>  }<br>}<br><br># create a listener on port 80 with redirect action<br># terraform aws create listener<br>resource &quot;aws_lb_listener&quot; &quot;alb_http_listener&quot; {<br>  load_balancer_arn = aws_lb.application_load_balancer.arn<br>  port              = 80<br>  protocol          = &quot;HTTP&quot;<br><br>  default_action {<br>    type = &quot;redirect&quot;<br><br>    redirect {<br>      host        = &quot;#{host}&quot;<br>      path        = &quot;/#{path}&quot;<br>      port        = 443<br>      protocol    = &quot;HTTPS&quot;<br>      status_code = &quot;HTTP_301&quot;<br>    }<br>  }<br>}<br><br># create a listener on port 443 with forward action<br># terraform aws create listener<br>resource &quot;aws_lb_listener&quot; &quot;alb_https_listener&quot; {<br>  load_balancer_arn = aws_lb.application_load_balancer.arn<br>  port              = 443<br>  protocol          = &quot;HTTPS&quot;<br>  ssl_policy        = &quot;ELBSecurityPolicy-2016-08&quot;<br>  certificate_arn   = var.ssl_certificate_arn<br><br>  default_action {<br>    type             = &quot;forward&quot;<br>    target_group_arn = aws_lb_target_group.alb_target_group.arn<br>  }<br>}</pre><p><strong>e). asg.tf file:</strong></p><p>asg.tf is the file in which we configure our Auto Scaling Group (ASG), defining parameters such as instance type, desired capacity, launch template(<strong><em>containing the user data to bootstrap our instance </em></strong>), scaling notification, auto-scaling-notification, and scaling policies to ensure your application can dynamically adjust its capacity based on demand.</p><blockquote>Note that the launch template is using the user data or config template ……<strong>install-and-configure-nest-app.sh.tpl </strong>as you can see in the <strong>user data</strong> section below</blockquote><pre># create a launch template<br># terraform aws launch template<br>resource &quot;aws_launch_template&quot; &quot;webserver_launch_template&quot; {<br>  name                   = &quot;${var.environment-prefix}-launch-template&quot;<br>  image_id               = var.image_id<br>  instance_type          = var.ec2_instance_type<br>  key_name               = var.ec2_keypair_name<br>  description            = &quot;launch template for ASG&quot;<br>  update_default_version = true<br>  vpc_security_group_ids = [aws_security_group.webserver_security_group.id]<br><br>  iam_instance_profile {<br>    name = aws_iam_instance_profile.s3_full_access_instance_profile.name<br>  }<br><br>  monitoring {<br>    enabled = true<br>  }<br><br>  user_data = base64encode(templatefile(&quot;${path.module}/install-and-configure-nest-app.sh.tpl&quot;, {<br>    PROJECT_NAME = var.project_name<br>    ENVIRONMENT  = var.environment-prefix<br>    RECORD_NAME  = var.route_53_record_name<br>    RDS_ENDPOINT = aws_db_instance.database_instance.endpoint<br>    RDS_DB_NAME  = local.database_credentials.databasename<br>    USERNAME     = local.database_credentials.username<br>    PASSWORD     = local.database_credentials.password<br>  }))<br><br><br>}<br><br># create auto scaling group<br># terraform aws autoscaling group<br>resource &quot;aws_autoscaling_group&quot; &quot;auto_scaling_group&quot; {<br>  vpc_zone_identifier = [aws_subnet.private_app_subnet_az1.id, aws_subnet.private_app_subnet_az2.id]<br>  desired_capacity    = 2<br>  max_size            = 4<br>  min_size            = 1<br>  name                = &quot;${var.environment-prefix}-asg&quot;<br>  health_check_type   = &quot;ELB&quot;<br>  depends_on          = [aws_db_instance.database_instance]<br><br>  launch_template {<br>    name    = aws_launch_template.webserver_launch_template.name<br>    version = &quot;$Latest&quot;<br>  }<br><br>  tag {<br>    key                 = &quot;Name&quot;<br>    value               = &quot;${var.environment-prefix}-webserver-asg&quot;<br>    propagate_at_launch = true<br>  }<br><br>  lifecycle {<br>    ignore_changes = [target_group_arns]<br>  }<br>}<br><br># attach auto scaling group to alb target group<br># terraform aws autoscaling attachment<br>resource &quot;aws_autoscaling_attachment&quot; &quot;asg_alb_target_group_attachment&quot; {<br>  autoscaling_group_name = aws_autoscaling_group.auto_scaling_group.id<br>  lb_target_group_arn    = aws_lb_target_group.alb_target_group.arn<br>}<br><br># create an auto scaling group notification<br># terraform aws autoscaling notification<br>resource &quot;aws_autoscaling_notification&quot; &quot;webserver_asg_notifications&quot; {<br>  group_names = [aws_autoscaling_group.auto_scaling_group.name]<br><br>  notifications = [<br>    &quot;autoscaling:EC2_INSTANCE_LAUNCH&quot;,<br>    &quot;autoscaling:EC2_INSTANCE_TERMINATE&quot;,<br>    &quot;autoscaling:EC2_INSTANCE_LAUNCH_ERROR&quot;,<br>    &quot;autoscaling:EC2_INSTANCE_TERMINATE_ERROR&quot;,<br>  ]<br><br>  topic_arn = aws_sns_topic.user_updates.arn<br>}</pre><p>g) i<strong>nstall-and-configure-nest-app.sh.tpl:</strong></p><p>This user data script has been meticulously crafted for integration into our launch template, an integral component of our auto-scaling group. It simplifies the intricate process of preparing our dynamic website for deployment. The script orchestrates essential operations, including PHP 8 and MySQL 8 installation, acquisition of our application code, Apache configuration, permission fine-tuning, and the establishment of vital database credentials and configurations. <strong>You have to substitute the S3 bucket name, with the name of your previously created bucket and the fil</strong>e <strong>we uploaded</strong> as long as they align with your previously uploaded data to the designated S3 bucket.</p><blockquote>Make sure to replace with your<strong> bucket name,</strong> wherever you see this “<strong>&lt;&lt;&lt;your-bucket-name&gt;&gt;&gt;</strong>” in the file below.</blockquote><pre>#!/bin/bash<br><br># This command updates all the packages on the server to their latest versions<br>sudo yum update -y<br><br># This series of commands installs the Apache web server, enables it to start on boot, and then starts the server immediately<br>sudo yum install -y httpd<br>sudo systemctl enable httpd <br>sudo systemctl start httpd<br><br>## This command installs PHP 8 along with several necessary extensions for the application to run<br>sudo dnf install -y php php-cli php-fpm php-mysqlnd php-bcmath php-ctype php-fileinfo php-json php-mbstring php-openssl php-pdo php-gd php-tokenizer php-xml<br><br>## These commands Installs MySQL version 8<br># Install the MySQL Community repository<br>sudo wget https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm <br>#<br># Install the MySQL server<br>sudo dnf install -y mysql80-community-release-el9-1.noarch.rpm <br>dnf repolist enabled | grep &quot;mysql.*-community.*&quot;<br>sudo dnf install -y mysql-community-server <br>#<br># Start and enable the MySQL server<br>sudo systemctl start mysqld<br>sudo systemctl enable mysqld<br><br># Install the cURL and PHP cURL packages<br>sudo yum install -y curl libcurl libcurl-devel php-curl --allowerasing<br><br># Restart the PHP-FPM service to apply the changes<br>sudo service php-fpm restart<br><br># Update the settings, memory_limit to 128M and max_execution_time to 300 in the php.ini file<br>sudo sed -i &#39;s/^\s*;\?\s*memory_limit =.*/memory_limit = 128M/&#39; /etc/php.ini<br>sudo sed -i &#39;s/^\s*;\?\s*max_execution_time =.*/max_execution_time = 300/&#39; /etc/php.ini<br><br># This command enables the &#39;mod_rewrite&#39; module in Apache on an EC2 Linux instance. It allows the use of .htaccess files for URL rewriting and other directives in the &#39;/var/www/html&#39; directory<br>sudo sed -i &#39;/&lt;Directory &quot;\/var\/www\/html&quot;&gt;/,/&lt;\/Directory&gt;/ s/AllowOverride None/AllowOverride All/&#39; /etc/httpd/conf/httpd.conf<br><br><br># This command downloads the contents of the specified S3 bucket to the &#39;/var/www/html&#39; directory on the EC2 instance<br>sudo aws s3 sync s3://&lt;&lt;&lt;your-bucket-name&gt;&gt;&gt;/nest-app/ /var/www/html<br><br># This command changes the current working directory to &#39;/var/www/html&#39;, which is the standard directory for hosting web pages on a Unix-based server<br>cd /var/www/html<br><br># This command is used to extract the contents of the application code zip file that was previously downloaded from the S3 bucket<br>sudo unzip nest-app.zip<br><br># This command recursively copies all files, including hidden ones, from the &#39;nest-app&#39; directory to the &#39;/var/www/html/&#39;.<br>sudo cp -R nest-app/. /var/www/html/<br><br># This command permanently deletes the &#39;nest-app&#39; directory and the &#39;nest-app.zip&#39; file.<br>sudo rm -rf nest-app nest-app.zip<br><br># This command set permissions 777 for the &#39;/var/www/html&#39; directory and the &#39;storage/&#39; directory<br>sudo chmod -R 777 /var/www/html<br>sudo chmod -R 777 storage/<br><br># This command uses `sed` to search the .env file for a line that starts with APP_NAME= and replaces everything after the &quot;=&quot; character with the app&#39;s name.<br>sudo sed -i &quot;/^APP_NAME=/ s/=.*$/=${PROJECT_NAME}-${ENVIRONMENT}/&quot; .env<br><br># This command uses `sed` to search the .env file for a line that starts with APP_URL= and replaces everything after the &quot;=&quot; character with the app&#39;s domain name.<br>sudo sed -i &quot;/^APP_URL=/ s|=.*$|=https://${RECORD_NAME}/|&quot; .env<br><br># This command uses `sed` to search the .env file for a line that starts with DB_HOST= and replaces everything after the &quot;=&quot; character with the RDS endpoint.<br>sudo sed -i &quot;/^DB_HOST=/ s/=.*$/=${RDS_ENDPOINT}/&quot; .env<br><br># This command uses `sed` to search the .env file for a line that starts with DB_DATABASE= and replaces everything after the &quot;=&quot; character with the RDS database name.<br>sudo sed -i &quot;/^DB_DATABASE=/ s/=.*$/=${RDS_DB_NAME}/&quot; .env<br><br># This command uses `sed` to search the .env file for a line that starts with DB_USERNAME= and replaces everything after the &quot;=&quot; character with the RDS database username.<br>sudo sed -i &quot;/^DB_USERNAME=/ s/=.*$/=${USERNAME}/&quot; .env<br><br># This command uses `sed` to search the .env file for a line that starts with DB_PASSWORD= and replaces everything after the &quot;=&quot; character with the RDS database password.<br>sudo sed -i &quot;/^DB_PASSWORD=/ s/=.*$/=${PASSWORD}/&quot; .env<br><br># This command will replace the AppServiceProvider.php file<br>sudo aws s3 cp s3://&lt;&lt;&lt;your-bucket-name&gt;&gt;&gt;/AppServiceProvider.php /var/www/html/app/Providers/AppServiceProvider.php<br><br># This command will restart the Apache server<br>sudo service httpd restart</pre><p><strong>h) data-migrate-ec2.tf</strong>:</p><p>This Terraform script performs critical tasks for deploying a secure and scalable infrastructure. Here we begin by securely retrieving sensitive database credentials from the AWS Secrets Manager we created in the previous step, enhancing the security of credential storage. Subsequently, the script creates an Amazon EC2 instance optimized for data migration, specifying its configuration, including instance type, security group, and more. This instance is further customized with a user data(<strong>migrate-nest-sql.sh.tpl</strong>), which runs a script to facilitate the migration or importation of our SQL file into our <strong>rds database </strong>using the retrieved credentials. Now to ensure the database’s availability, the EC2 instance’s creation depends on the RDS database instance, so our RDS needs to be provisioned first. Finally, the instance is tagged for easy identification. Overall, this tf script combines security and efficiency to set up a robust environment for database migration within the AWS infrastructure</p><pre>data &quot;aws_secretsmanager_secret_version&quot; &quot;secret_manager_credentials&quot; {<br>  secret_id = var.rds_db_secret_credentials<br>}<br><br>locals {<br>  database_credentials = jsondecode(<br>    data.aws_secretsmanager_secret_version.secret_manager_credentials.secret_string<br>  )<br>}<br><br><br>resource &quot;aws_instance&quot; &quot;data_migrate_ec2&quot; {<br>  ami                    = var.image_id<br>  instance_type          = var.ec2_instance_type<br>  subnet_id              = aws_subnet.private_app_subnet_az1.id<br>  vpc_security_group_ids = [aws_security_group.webserver_security_group.id]<br>  iam_instance_profile   = aws_iam_instance_profile.s3_full_access_instance_profile.name<br><br>  user_data = base64encode(templatefile(&quot;${path.module}/migrate-nest-sql.sh.tpl&quot;, {<br>    RDS_ENDPOINT = aws_db_instance.database_instance.endpoint<br>    RDS_DB_NAME  = local.database_credentials.databasename<br>    USERNAME     = local.database_credentials.username<br>    PASSWORD     = local.database_credentials.password<br>  }))<br><br>  depends_on = [aws_db_instance.database_instance]<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-data-migration-instance&quot;<br>  }<br>}<br><br></pre><blockquote>Below is the user data file(<strong>migrate-nest-sql.sh.tpl</strong>) we will use to migrate or import our sql file</blockquote><p><strong>i) migrate-nest-sql.sh.tpl :</strong></p><p>Here all you need to do is replace this “<strong>&lt;&lt;&lt;your-bucket-name&gt;&gt;&gt; </strong>with your<strong> bucket name created previously</strong>. To explain what this file does below</p><ul><li>In this specific file, we address a critical aspect of our dynamic, highly available web application. To ensure smooth deployment, we downloaded the flyway tool that we will use to migrate our SQL file from s3 to our RDS database using this instance. So this instance facilitates the migration and import of our SQL scripts downloaded from our S3 bucket to the RDS database, which is crucial for the proper functioning of our web application. Furthermore. After completing its tasks, the instance is programmed to either shut down or be terminated after a 7-minute wait period.</li></ul><pre>#!/bin/bash<br><br># Download and extract Flyway<br>sudo wget -qO- https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/9.20.0/flyway-commandline-9.20.0-linux-x64.tar.gz | tar -xvz<br><br># Create a symbolic link to make Flyway accessible globally<br>sudo ln -s $(pwd)/flyway-9.20.0/flyway /usr/local/bin<br><br># Create the SQL directory for migrations<br>sudo mkdir sql<br><br># Download the migration SQL script from AWS S3<br>aws s3 cp s3://&lt;&lt;&lt;your-bucket-name&gt;&gt;&gt;/V1__nest.sql sql/ # replace with your bucket-name you created previously<br><br># Run Flyway migration<br>sudo flyway -url=jdbc:mysql://&quot;${RDS_ENDPOINT}&quot;/&quot;${RDS_DB_NAME}&quot; \<br>  -user=&quot;${USERNAME}&quot; \<br>  -password=&quot;${PASSWORD}&quot; \<br>  -locations=filesystem:sql \<br>  migrate<br><br># Then shutdown after waiting 7 minutes<br>sudo shutdown -h +7</pre><p><strong>j). IAM-role (iam-role.tf) file:</strong></p><p>In the ‘iam-role.tf’ file, we create an essential IAM (Identity and Access Management) role known as “S3FullAccessRole.” Its core purpose is to empower EC2 instances with the capability to securely and efficiently download files(<strong>application code, etc.</strong>) from our Amazon S3 bucket. This role serves as the linchpin that enables these instances to assume the necessary permissions, facilitating seamless interactions with your S3 resources. In essence, it plays a pivotal role in achieving the primary goal of accessing files from S3 while ensuring the security and reliability of the process</p><pre># create iam role <br>resource &quot;aws_iam_role&quot; &quot;s3_full_access_role&quot; {<br>  name = &quot;S3FullAccessRole&quot;<br><br>  assume_role_policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [<br>      {<br>        Action = &quot;sts:AssumeRole&quot;<br>        Effect = &quot;Allow&quot;<br>        Principal = {<br>          Service = &quot;ec2.amazonaws.com&quot;<br>        }<br>      }<br>    ]<br>  })<br>}<br><br># attach the aws manage s3 full access policy to the iam role<br>resource &quot;aws_iam_role_policy_attachment&quot; &quot;s3_full_access_policy_attachment&quot; {<br>  role       = aws_iam_role.s3_full_access_role.name<br>  policy_arn = &quot;arn:aws:iam::aws:policy/AmazonS3FullAccess&quot;<br>}<br><br># create an iam instance profile<br>resource &quot;aws_iam_instance_profile&quot; &quot;s3_full_access_instance_profile&quot; {<br>  name = var.aws_iam_instance_profile_name<br>  role = aws_iam_role.s3_full_access_role.name<br>}</pre><p><strong>k). Route 53 (route-53.tf):</strong></p><p>In the ‘route-53.tf file, our Terraform script performs DNS management tasks using Amazon Route 53. It first retrieves details from my public hosted zone, and then, it creates a DNS record set within that zone. This record set maps a record (var.route_53_record_name) to an Application Load Balancer (ALB) using an alias, allowing traffic directed to the domain to be efficiently routed to the ALB. The evaluate_target_health setting ensures that the health of the ALB&#39;s targets is considered when routing traffic, making this a robust and reliable DNS configuration for the application.</p><pre># get hosted zone details<br># terraform aws data hosted zone<br>data &quot;aws_route53_zone&quot; &quot;hosted_zone&quot; {<br>  name = var.route_53_hosted_zone_name<br>}<br><br># create a record set in route 53<br># terraform aws route 53 record<br>resource &quot;aws_route53_record&quot; &quot;site_domain&quot; {<br>  zone_id = data.aws_route53_zone.hosted_zone.zone_id<br>  name    = var.route_53_record_name<br>  type    = &quot;A&quot;<br><br>  alias {<br>    name                   = aws_lb.application_load_balancer.dns_name<br>    zone_id                = aws_lb.application_load_balancer.zone_id<br>    evaluate_target_health = true<br>  }<br>}</pre><p><strong>l). rds-database. tf file:</strong></p><p>This Terraform code block creates a database subnet group, ‘<strong>aws_db_subnet_group,</strong>’ and provisions an Amazon RDS instance, ‘<strong>aws_db_instance</strong>.’ The subnet group defines the subnets for the database instance, while the RDS instance configuration includes the database engine, credentials(<strong><em>the one we stored in aws secret manager</em></strong>), instance class, storage, security groups, and availability zone settings. This setup establishes the core of our database infrastructure, ensuring secure and efficient database management.</p><pre># create a database subnet group<br># terraform aws db subnet group<br>resource &quot;aws_db_subnet_group&quot; &quot;database_subnet_group&quot; {<br>  name        = var.database_subnet_group_name<br>  subnet_ids  = [aws_subnet.private_data_subnet_az1.id, aws_subnet.private_data_subnet_az2.id]<br>  description = &quot;subnets for database instance&quot;<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-database&quot;<br>  }<br>}<br><br># create the rds instance<br>resource &quot;aws_db_instance&quot; &quot;database_instance&quot; {<br>  engine                 = var.rds_engine<br>  engine_version         = var.rds_engine_version<br>  multi_az               = false<br>  identifier             = var.database_instance_identifier<br>  username               = local.database_credentials.username<br>  password               = local.database_credentials.password<br>  db_name                = local.database_credentials.databasename<br>  instance_class         = var.database_instance_class<br>  allocated_storage      = 200<br>  db_subnet_group_name   = aws_db_subnet_group.database_subnet_group.id<br>  vpc_security_group_ids = [aws_security_group.database_security_group.id]<br>  availability_zone      = var.availability_zone[1]<br>  skip_final_snapshot    = true<br>  publicly_accessible    = false<br>}</pre><p><strong>m). security-group. tf file:</strong></p><p>In ‘security-group. tf,’ we have defined several AWS security groups to control and secure traffic within the infrastructure:</p><ul><li>The Application Load Balancer (ALB) security group permits inbound HTTP (port 80) and HTTPS (port 443) traffic and allows all outbound traffic, this will be used by our application load balancer.</li><li>The bastion host (SSH jump box) security group grants SSH access on port 22 but restricts it to our IP alone, allowing all outbound traffic.<br>- <em>To see your IP click</em> <a href="https://whoer.net/"><strong>here</strong></a></li><li>The web server security group facilitates HTTP and HTTPS access, allowing traffic from the ALB security group, as well as SSH access from the SSH security group. Outbound traffic is unrestricted, this will be used by our ec2 instances.</li><li>The database security group enables MySQL/Aurora access on port 3306, allowing incoming traffic only from the web server security group and permitting all outbound traffic, this will be assigned to our database.</li></ul><p>These security groups ensure controlled and secure communication among our different infrastructure components, aligning with the defined security policies.”</p><pre># create security group for the ec2 instance connect endpoint<br>resource &quot;aws_security_group&quot; &quot;eice_security_group&quot; {<br>  name        = var.eice_security_group_name<br>  description = &quot;enable outbound traffic on port 22 from the vpc cidr&quot;<br>  vpc_id      = aws_vpc.terraform_vpc.id<br><br>  egress {<br>    from_port   = 22<br>    to_port     = 22<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [var.cidr_block[0]]<br>  }<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-eice-security-group&quot;<br>  }<br>}<br><br># create security group for the application load balancer<br># terraform aws create security group<br>resource &quot;aws_security_group&quot; &quot;alb_security_group&quot; {<br>  name        = var.alb_security_group_name<br>  description = &quot;enable http/https access on port 80/443&quot;<br>  vpc_id      = aws_vpc.terraform_vpc.id<br><br>  ingress {<br>    description = &quot;HTTP access&quot;<br>    from_port   = 80<br>    to_port     = 80<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [var.default_routes[0]]<br>  }<br><br>  ingress {<br>    description = &quot;https access&quot;<br>    from_port   = 443<br>    to_port     = 443<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [var.default_routes[0]]<br>  }<br><br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = -1<br>    cidr_blocks = [var.default_routes[0]]<br>  }<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-ALB-security-group&quot;<br>  }<br>}<br><br># create a security group for the bastion host aka jump box<br># terraform aws create a security group<br>resource &quot;aws_security_group&quot; &quot;ssh_security_group&quot; {<br>  name        = var.ssh_security_group_name<br>  description = &quot;enable ssh access on port 22&quot;<br>  vpc_id      = aws_vpc.terraform_vpc.id<br><br>  ingress {<br>    description = &quot;ssh access&quot;<br>    from_port   = 22<br>    to_port     = 22<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [var.my_local_isp_public_ip[0]]<br>  }<br><br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = -1<br>    cidr_blocks = [var.default_routes[0]]<br>  }<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-ssh-security-group&quot;<br>  }<br>}<br><br># create security group for the web server<br># terraform aws create security group<br>resource &quot;aws_security_group&quot; &quot;webserver_security_group&quot; {<br>  name        = var.webserver_security_group_name<br>  description = &quot;enable http/https access on port 80/443 via alb sg and access on port 22 via ssh sg&quot;<br>  vpc_id      = aws_vpc.terraform_vpc.id<br><br>  ingress {<br>    description     = &quot;http access&quot;<br>    from_port       = 80<br>    to_port         = 80<br>    protocol        = &quot;tcp&quot;<br>    security_groups = [aws_security_group.alb_security_group.id]<br>  }<br><br>  ingress {<br>    description     = &quot;https access&quot;<br>    from_port       = 443<br>    to_port         = 443<br>    protocol        = &quot;tcp&quot;<br>    security_groups = [aws_security_group.alb_security_group.id]<br>  }<br><br>  ingress {<br>    description     = &quot;ssh access&quot;<br>    from_port       = 22<br>    to_port         = 22<br>    protocol        = &quot;tcp&quot;<br>    security_groups = [aws_security_group.ssh_security_group.id]<br>  }<br><br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = -1<br>    cidr_blocks = [var.default_routes[0]]<br>  }<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-webserver-security-group&quot;<br>  }<br>}<br><br># create security group for the database<br># terraform aws create security group<br>resource &quot;aws_security_group&quot; &quot;database_security_group&quot; {<br>  name        = var.database_security_group_name<br>  description = &quot;enable mysql/aurora access on port 3306&quot;<br>  vpc_id      = aws_vpc.terraform_vpc.id<br><br>  ingress {<br>    description     = &quot;mysql/3306 aurora access&quot;<br>    from_port       = 3306<br>    to_port         = 3306<br>    protocol        = &quot;tcp&quot;<br>    security_groups = [aws_security_group.webserver_security_group.id]<br>  }<br><br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = -1<br>    cidr_blocks = [var.default_routes[0]]<br>  }<br><br>  tags = {<br>    Name = &quot;${var.environment-prefix}-database-security-group&quot;<br>  }<br>}</pre><p><strong>n). sns.tf (SNS — Simple Notification Service):</strong></p><p>In the ‘sns.tf’ file, we configure AWS Simple Notification Service (SNS). SNS enables event-driven communication, this especially helps get notified when there has been a scale in and scale out of our ec2 instances by the auto-scaling group. We define topics and subscriptions to notify and coordinate actions when specific events occur.</p><pre># create an sns topic<br># terraform aws create sns topic<br>resource &quot;aws_sns_topic&quot; &quot;user_updates&quot; {<br>  name = var.sns_topic_name<br>}<br><br># create an sns topic subscription<br># terraform aws sns topic subscription<br>resource &quot;aws_sns_topic_subscription&quot; &quot;notification_topic&quot; {<br>  topic_arn = aws_sns_topic.user_updates.arn<br>  protocol  = var.sns_protocol<br>  endpoint  = var.operator_email<br>}</pre><p><strong>o). Create Output.tf </strong>:</p><p>This file is basically to output information on some of our resources.</p><pre>output &quot;vpc_id&quot; {<br>  value = aws_vpc.terraform_vpc.id<br>}<br><br>output &quot;public_subnet_az1_id&quot; {<br>  value = aws_subnet.public_subnet_az1.id<br>}<br><br>output &quot;public_subnet_az2_id&quot; {<br>  value = aws_subnet.public_subnet_az2.id<br>}<br><br>output &quot;private_app_subnet_az1&quot; {<br>  value = aws_subnet.private_app_subnet_az1.id<br>}<br><br>output &quot;private_app_subnet_az2&quot; {<br>  value = aws_subnet.private_app_subnet_az2.id<br>}<br><br><br>output &quot;website_url&quot; {<br>  value = join(&quot;&quot;, [&quot;https://&quot;, aws_route53_record.site_domain.name, &quot;.&quot;, data.aws_route53_zone.hosted_zone.name)<br>}<br><br>output &quot;hosted_zone&quot; {<br>  value = data.aws_route53_zone.hosted_zone.name<br>}</pre><p><strong>p) Variable.tf:</strong></p><p>The variable.tf file in Terraform plays a vital role by defining variables that serve as dynamic placeholders for values that can vary depending on the environment, project, or specific use case. Meaning that every variable we have defined in our terraform configuration is been declared here. These variables enhance the flexibility and reusability of our Terraform code, allowing us to easily supply different values for these variables when executing Terraform commands. To furnish these variables with specific values, we utilize the <strong>terraform.tfvars</strong> file. Within this file, we establish key-value pairs that correspond to the variable names we&#39;ve specified in <strong>variable.tf</strong>. This approach ensures our code&#39;s reusability and adaptability, making it easier to manage infrastructure across diverse scenarios.</p><pre>variable &quot;cidr_block&quot; {<br>  type = list(any)<br>}<br>variable &quot;availability_zone&quot; {<br>  type = list(any)<br>}<br>variable &quot;default_routes&quot; {<br>  type = list(any)<br>}<br>variable &quot;my_local_isp_public_ip&quot; {<br>  type = list(any)<br>}<br>variable &quot;eice_security_group_name&quot; {}<br>variable &quot;rds_engine_version&quot; {}<br>variable &quot;rds_engine&quot; {}<br>variable &quot;ec2_keypair_name&quot; {}<br>variable &quot;ec2_instance_type&quot; {}<br>variable &quot;image_id&quot; {}<br>variable &quot;ssl_certificate_arn&quot; {}<br>variable &quot;database_subnet_group_name&quot; {}<br>variable &quot;instance_tenancy&quot; {}<br>variable &quot;environment-prefix&quot; {}<br>variable &quot;default_route&quot; {}<br>variable &quot;ssh_security_group_name&quot; {}<br>variable &quot;alb_security_group_name&quot; {}<br>variable &quot;webserver_security_group_name&quot; {}<br>variable &quot;database_security_group_name&quot; {}<br>variable &quot;database_instance_class&quot; {}<br>variable &quot;database_instance_identifier&quot; {}<br>variable &quot;target_group_name&quot; {}<br>variable &quot;alb_name&quot; {}<br>variable &quot;sns_topic_name&quot; {}<br>variable &quot;sns_protocol&quot; {}<br>variable &quot;operator_email&quot; {}<br>variable &quot;route_53_hosted_zone_name&quot; {}<br>variable &quot;route_53_record_name&quot; {}<br>variable &quot;webserver_asg_notifications_group&quot; {}<br>variable &quot;project_name&quot; {}<br>variable &quot;aws_iam_instance_profile_name&quot; {}<br>variable &quot;rds_db_secret_credentials&quot; {}</pre><p><strong>q) <em>terraform.tfvars</em>:</strong></p><p>Here is how we use our <em>terraform.tfvars</em> and fill in the values.</p><pre>cidr_block = [<br>  &quot;10.0.0.0/16&quot;,<br>  &quot;10.0.0.0/24&quot;, <br>  &quot;10.0.1.0/24&quot;, <br>  &quot;10.0.2.0/24&quot;, <br>  &quot;10.0.3.0/24&quot;, <br>  &quot;10.0.4.0/24&quot;, <br>  &quot;10.0.5.0/24&quot;<br>]<br><br>availability_zone = [<br>  &quot;us-east-1a&quot;,<br>  &quot;us-east-1b&quot;<br>]<br><br>default_routes = [<br>  &quot;0.0.0.0/0&quot;<br>]<br><br>my_local_isp_public_ip = [<br>  &quot;123.456.789.0/32&quot; #change this to your-own-IP/32<br>]<br><br>eice_security_group_name = &quot;eice-security-group&quot;<br>rds_engine_version = &quot;5.7&quot;<br>rds_engine = &quot;mysql&quot;<br>ec2_keypair_name = &quot;my-keypair&quot;<br>ec2_instance_type = &quot;t2.micro&quot;<br>image_id = &quot;ami-0123456789&quot; <br>ssl_certificate_arn = #add the arn of the certificate you created earlier <br>database_subnet_group_name = &quot;my-database-subnet-group&quot;<br>instance_tenancy = &quot;default&quot;<br>environment-prefix = &quot;my-environment&quot;<br>default_route = &quot;0.0.0.0/0&quot;<br>ssh_security_group_name = &quot;ssh-security-group&quot;<br>alb_security_group_name = &quot;alb-security-group&quot;<br>webserver_security_group_name = &quot;webserver-security-group&quot;<br>database_security_group_name = &quot;database-security-group&quot;<br>database_instance_class = &quot;db.t2.micro&quot;<br>database_instance_identifier = &quot;my-database-instance&quot;<br>target_group_name = &quot;my-target-group&quot;<br>alb_name = &quot;my-application-load-balancer&quot;<br>sns_topic_name = &quot;my-sns-topic&quot;<br>sns_protocol = &quot;email&quot;<br>operator_email = # ADD YOUR PREFERRED EMAIL ADDRESS <br>route_53_hosted_zone_name = # ADD YOUR hosted zone<br>route_53_record_name = &quot;dynaweb&quot; #replace with what your preferred record name<br>webserver_asg_notifications_group = &quot;webserver-asg-notifications&quot;<br>project_name = &quot;my-project&quot;<br>aws_iam_instance_profile_name = &quot;my-iam-instance-profile&quot;<br>rds_db_secret_credentials = # replace with the name of the secret we created previously</pre><p>Now you should have all these files populated. Awesome great job!!!</p><p>Next step, we will deploy the dynamic website by running our terraform commands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*Yb9O5apr9CRumkjR" /></figure><h3>Part 4. Provision your resources</h3><p>Let’s proceed with the deployment process. Before running these Terraform commands, ensure that you’ve already configured your AWS credentials in the previous step at the beginning.</p><ul><li>Initialize the Configuration: To start, open your terminal and change to the directory of the project where your terraform files are, and run the terraform init command. This command initializes your Terraform configuration, downloading the necessary provider plugins and setting up the backend for storing the state.</li></ul><pre>terraform init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*SB0s_DYiP0So7ihozVrfPg.png" /><figcaption>photo by me</figcaption></figure><ul><li>Generate Execution Plan: Next, execute terraform plan. This command generates an execution plan for your Terraform configuration, detailing the resources that Terraform will create, modify, or delete when applied. Creating more than 40 resources, including giving us some outputs like our website URL….</li></ul><pre>terraform plan</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*29BT0NBs2bc8QHMubOD5xA.png" /></figure><ul><li>Apply the Configuration: Finally, use Terraform apply to apply the Terraform configuration. This command triggers the creation or modification of resources in the target environment as specified in the plan.</li></ul><pre>terraform apply --auto-approve</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8rFlFhIC4CFNMS2meYe81A.png" /></figure><h3>Part 5: Verify resources on the AWS Management Console</h3><p>Now that we have done terraform apply to provision our resources on the AWS, what we will do is verify on the AWS console to check if the resources have been provisioned.</p><ul><li>Vpc, subnets, route table, IGW, Nat gateway</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yG8t-OkjuqfpWR5Ip49dEw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KHmw1lHMGvs_8YO8fdisRA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PF2yjMqq2i3pq_P2eJrFDQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-mvsPXNYq18YLR74L1gw2w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rrkse7buWeNeL8N9ITunJw.png" /></figure><ul><li>here you can see our ec2 instances running and our RDS database</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jcCJOBoZKcHTMUgH_hhqkg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AfCbmjr3d4COUHH7X0HX9A.png" /></figure><ul><li>auto-scaling group, ALB, and target group</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l0EXb51xvTF1mHuqkW8u8Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FnI1aDvBnIgRlSuuz_kRJQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ADMIgq698r3Cd5VKg9xQ2Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fWoAWRHFSzFMogLiSqHXhA.png" /></figure><ul><li>route 53 record</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lcc8znF3B_7XILULEGokAQ.png" /></figure><h3>Part 6: Access our website</h3><p>Here we will now do what we have been waiting for all this while which is access our website and see if it is accessible.</p><p>Copy and paste the website URL shown in our terminal when we ran Terraform apply inside your web browser and hit enter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*v64OCcq0KxD0DxnC.gif" /></figure><p>There you go our dynamic website deployed.. Just with Terraform. Isn’t it amazing :) !!!!!!!!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2mkurD-X-z5UAO-FSrOfXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mYREgJDFH9Um469fWbaPCg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rYQuKuaWRKVEkpFUgT6FaQ.png" /></figure><h3><strong>Awesome Job !!!!!!!!!!!!!!!!!!</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*orN8Kz6eN1mblvwz" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*1v5AxFOD_aunMAY2.gif" /></figure><h3>Part 7: Clean up (terraform destroy)</h3><p>Congratulations!!!! on successfully deploying a fully scalable, highly available, and secure dynamic website! However, to avoid incurring unnecessary charges, it’s essential to clean up our resources. Terraform makes this process quick and efficient.</p><p>Simply execute the following Terraform command below to dismantle our infrastructure. This showcases the agility and flexibility of Infrastructure as Code (IAC), where you can create and tear down resources with ease.</p><pre>terraform destroy --auto-approve</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*3mmxZxjceRxSS2EYhla9BQ.png" /></figure><p>Additionally, remember to remove or delete the secret you created in AWS Secret Manager and delete the associated S3 bucket. Proper cleanup ensures a tidy conclusion to your project while maintaining cost-effectiveness</p><h3><strong>Conclusion</strong></h3><p>Through Terraform, we’ve automated a highly available web application deployment on AWS. By distributing resources across multiple Availability Zones, we’ve improved fault tolerance and minimized single points of failure. Key to this setup are the Elastic Load Balancer and Auto-scaling Group, etc. which ensure efficient traffic distribution and fault tolerance.</p><p>I appreciate your dedication and commitment in following along with this tutorial. I hope you’ve found it valuable and insightful. Keep an eye out for my upcoming projects and tutorials. There’s more to come!</p><p><strong><em>Please don’t forget to clap </em>👏🏽</strong></p><p><strong>Connect with me</strong> on <a href="https://www.linkedin.com/in/sunday-nwoye-740961236/?lipi=urn%3Ali%3Apage%3Ad_flagship3_feed%3BWwAHY2LRRci6eErYU%2FbjXA%3D%3D"><strong>LinkedIn</strong></a><strong> &amp; GitHub</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c2ce6f0d044" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating SSL Certificates using AWS Certificate Manager (ACM)]]></title>
            <link>https://medium.com/@sonynwoye/creating-ssl-certificates-using-aws-certificate-manager-acm-1c359e70ce4d?source=rss-cf9f429d8253------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c359e70ce4d</guid>
            <dc:creator><![CDATA[Sunday Nwoye]]></dc:creator>
            <pubDate>Thu, 05 Oct 2023 00:16:18 GMT</pubDate>
            <atom:updated>2023-10-05T00:16:18.593Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*uzbgnab9TbJH3dRpfdeu-g.jpeg" /><figcaption>photo by google.com</figcaption></figure><p>Dealing with the intricacies of SSL/TLS certificates can be quite a hassle. Thankfully, AWS offers a hassle-free solution in the form of AWS Certificate Manager (ACM). ACM is a robust service designed to simplify the process of provisioning, managing, and deploying both public and private SSL/TLS certificates. These certificates are not only used with various AWS services but also for securing your internal resources.</p><p>When it comes to certificate provisioning, ACM provides you with two convenient options. You can opt for the ‘Provision certificates’ feature, a free service that allows you to either provision your own certificate or request one directly from AWS for use with ACM-Integrated Services.</p><p>In this post, we’ll guide you through the generation of a certificate for ‘sundaydevops.com’ using the ‘request a certificate’ option within ACM.”</p><p>Generating Your SSL Certificate: Creating an SSL certificate through AWS ACM is a straightforward process. Here’s a step-by-step guide:</p><ul><li>Log into AWS Management Console: To begin, access the AWS Management Console securely.</li><li>Access Certificate Manager: Navigate to ‘Certificate Manager’ under the ‘Security, Identity, &amp; Compliance’ section. You can also use the search feature by typing ‘certificate manager’ to quickly locate the service.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*sNthKQMaBg3HHbDXEadN7g.png" /></figure><h3>Request a certificate</h3><p>After being sure that Request a public certificate option is selected, you can click Request a certificate and select “<strong><em>request a public certificate</em></strong>”, and click on <strong><em>Next</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0a3TK9dvkm4v5EHoDafXig.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JH7CsaklxFZ01fPQrL4XGA.png" /></figure><h3><strong>Adding Domain Names:</strong></h3><p>Now, it’s time to specify the fully qualified domain name (FQDN) of the website you intend to secure with the SSL/TLS certificate. AWS ACM also supports the request of wildcard certificates, which you can include in the domain name. Here’s how to do it:</p><ul><li><strong>Enter Domain Name</strong>: In the provided field, input the complete domain name of your website. This could be something like ‘<a href="http://www.yourwebsite.com/">www.yourwebsite.com</a>&#39; for a specific subdomain or ‘yourwebsite.com’ for the root domain. in our case i will be my domain “<strong>sundaydevops.com</strong>”</li><li><strong>Consider Wildcard Certificates:</strong> If needed, you can request a wildcard certificate by including an asterisk (*<em>) as a placeholder. For instance, ‘*</em>.yourwebsite.com’ would secure all subdomains under ‘yourwebsite.com.’ And in our case i will be using “<strong>*.sundaydevops.com</strong>”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-puP3a6Dwbv2FAiB_mZXEg.png" /></figure><p>By following these steps, you can ensure that your SSL/TLS certificate covers the necessary domains and subdomains, providing comprehensive security for your web presence.</p><h3><strong>Choosing Your Validation Method</strong>:</h3><p>The next crucial step in this process is selecting the validation method that proves ownership of your domain. AWS ACM offers two options for this purpose: DNS validation and Email validation.</p><p>In my case, I have the necessary permissions to make DNS configuration changes, which is why I’ve opted for DNS validation. This method allows for a seamless and automated verification process, ensuring a smooth journey towards securing your SSL/TLS certificate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LOfWKOFBRRY5DihWCX6O6A.png" /></figure><p>For the key algorithm i will choose RSA 2048, RSA is the most widely used key type. You can add tags if you want but i will not be adding tags.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JaqAFA5TEmeOnwu6KDJAbA.png" /></figure><h3>Review and Request:</h3><p>Now, it’s time to review your selections, including the domain name, chosen validation method, and any tags you’ve applied. This quick review ensures everything is on track before advancing to the next certificate provisioning steps. If after everything it looks great and okay, then click on <strong>“request”.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WwjKNCOxUtMl79qUidBCQA.png" /></figure><h3>Validation Process:</h3><p>AWS ACM will initiate the certificate request process, placing it in a ‘Pending Validation’ state. To proceed with validation, follow these steps:</p><ul><li>Route 53 Hosted Zones: If your domain is hosted within AWS Route 53, ACM will automatically create the required DNS records for validation. Since your domains are hosted on Route 53, simply click ‘Create record in Route 53’ to proceed.</li><li>Manual Validation: For domains hosted outside Route 53, manual action is required. You must create a CNAME record within your domain’s DNS configuration for each entered domain. Failure to complete this step will prevent ACM from issuing your certificate. Once you’ve created the necessary DNS records, click ‘Continue’ to move forward in the certificate issuance process.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8a9jrjKTVZGehAeV6qOUjw.png" /></figure><h3>Creating a Record in Route 53:</h3><p>After clicking ‘Create,’ you’ll receive a confirmation message indicating that the DNS record has been successfully written to your AWS Route 53 hosted zone. This message signifies the completion of the DNS record creation process, ensuring that your certificate validation is on the right track.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6j-gnH5-ksUXJCHYvCjWjg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E352nSiXzbnikc2SfOXkYA.png" /></figure><h3>Creation of Certificate in ACM</h3><p>After creating records you should be seeing that your validation status becomes Issued and validation status is Success.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ekDxVeG-kfh_47h4MwCeqg.png" /></figure><p>After successfully obtaining your issued certificate, you can seamlessly link it with a wide range of AWS Services. These include Elastic Load Balancing, Amazon Cloud Front, AWS Elastic Beanstalk, Amazon API Gateway, AWS Cloud Formation, and AWS Cognito.</p><p>This versatility allows you to fortify the security of your web applications and services across multiple AWS offerings using your SSL/TLS certificate.</p><h3>Conclusion:</h3><p>In this tutorial, we’ve covered the simple process of creating SSL/TLS certificates with AWS Certificate Manager (ACM). Now, you’re ready to secure your web services.</p><p>Best Regards,<br>Sunday.</p><p>Thank You and Stay Tuned: Thanks for joining me. Look forward to more tutorials coming soon!</p><p>Also you can connect with me on <a href="https://www.linkedin.com/in/sunday-nwoye-740961236/?lipi=urn%3Ali%3Apage%3Ad_flagship3_job_details%3B4IpTDJHYQ8ewNeAu72ptyA%3D%3D">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c359e70ce4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to connect to your servers in your private network via ssh using MobaXterm #AWS]]></title>
            <link>https://medium.com/@sonynwoye/how-to-connect-to-your-servers-in-your-private-network-via-ssh-using-mobaxterm-aws-33c29f7e60c7?source=rss-cf9f429d8253------2</link>
            <guid isPermaLink="false">https://medium.com/p/33c29f7e60c7</guid>
            <dc:creator><![CDATA[Sunday Nwoye]]></dc:creator>
            <pubDate>Sat, 30 Sep 2023 15:01:18 GMT</pubDate>
            <atom:updated>2023-10-04T08:39:07.096Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*IANHtyc6S0Nk84aPdTdvXw.jpeg" /><figcaption>MobaXterm</figcaption></figure><p>SSH agent forwarding is a feature in the SSH (Secure Shell) protocol that allows you to use your local SSH key pair to authenticate and access remote servers or systems, even when you are connecting through an intermediate server. It’s particularly useful in scenarios where you need to access multiple servers or systems in a chain especially when they don&#39;t have access to public ip, such as when using SSH to access a jump host or a bastion server to reach another machine deeper within a network.</p><h3><strong>Here is how to setup agent forwarding in MobaXterm:</strong></h3><ol><li>Open MobaXterm and at the top menu, select “Settings” &gt; “Configuration” &gt; “SSH” tab</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*ai20-im38QAAaIKxEU0W2A.png" /><figcaption>MobaXterm</figcaption></figure><p>2. You have option for SSH agent handling: MobaXterm’s built-in SSH agent For this scenario, let’s utilize MobaXterm’s internal SSH agent. Be sure to check the boxes for “<strong>Use internal SSH agent MobAgent</strong>” and “Forward SSH Agents,” while unchecking “Use external Pageant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*aG3M5cZfpoBLeaMe6ZmQzg.png" /></figure><p>3. Add your SSH keys (.pem) to the agent by clicking the “+” icon and click OK when you’re done. This may restart the MobaXterm application. If so click “yes”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*ZN3phKrGs4-3Bp3ZbT5REQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*KMPeWVmJ2W8dXJ6GjLAFAg.png" /></figure><p>4. Now lets SSH to our servers using MobaXterm’s local terminal the same way you would use a bash terminal or by creating the “SSH sessions”. Once again, you don’t have to specify the keys when connecting if you have already added them to the SSH agent.</p><p>I’ve just spun up two EC2 instances on AWS: one in a public subnet with a public IP address, which I’ll refer to as my “bastion” instance, and another in a private subnet, which doesn’t have a public IP address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-uWlpK-gl5bD72a8ajCPuA.png" /></figure><p>5. Now in your mobaxterm click on the “<strong>Session</strong>” tab and choose “<strong>SSH</strong>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mzi9YLO-hc29HKPKCFdrYA.png" /></figure><p>6. Copy the public IP address of your bastion instance. Paste it into the “Remote host” field, check the “<strong>Specify username</strong>” box. Enter the appropriate username based on your instance’s operating system. In my case, i am using <strong>Amazon Linux</strong>, so the username is “<strong>ec2-user.</strong>” Check the “<strong>Use private key</strong>” box, Insert your “<strong>key.pem</strong>” file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*JI2PPwjON9NT-bciW5wxZw.png" /></figure><p>7. Additionally, we must enable SSH agent forwarding. To do this, click the “<strong><em>Expert SSH settings</em></strong>” button and check the box labeled “<strong><em>Allow agent forwarding</em></strong>.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*2WGVgSP7u6n0-M8231F4Dw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*vswv9ODKWmJkbhVbxiJ2pw.png" /></figure><p>8. Now click “<strong>Okay</strong>.” You will then see a prompt asking you to confirm the connection and verify the identity. If you trust the identity, click “<strong>Accept.</strong>”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*tE8Pf6K1c2AFF9es0OUdbA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*MYFjUsNP6za1OburJP4kbA.png" /></figure><p>Now we have successfully ssh into our bastion host. :) !!</p><p>7. Now, it’s time to establish an SSH connection with our EC2 instance located in the private subnet, which lacks a public IP address. To do this, we’ll use the private IP of the EC2 instance and execute the following command. Thanks to our Mobaxterm setup we did earlier, which includes SSH agent forwarding, we should seamlessly SSH into our EC2 instance in the private subnet.</p><p><strong>Command</strong>: ssh ec2-user@&lt;your-instance-private-ip-address&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i7AExjDpkfpAsHRcwDUA-Q.png" /></figure><p><strong><em>Baaam</em></strong>!!!! there you go &amp; you are in!!!</p><p><strong>Conclusion</strong>:</p><p>In this tutorial we have successfully SSH into our ec2 instance in our private subnet using MobaXterm.</p><p>Thanks for reading and Watch out for the next tutorial session. Have a lovely day :).</p><p>You connect with me too on <a href="https://www.linkedin.com/in/sunday-nwoye-740961236/?lipi=urn%3Ali%3Apage%3Ad_flagship3_job_details%3BoHzon4HURUWVxg1zWGxJsA%3D%3D">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33c29f7e60c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simplifying CI/CD: Deploying Applications to AWS Kubernetes with Jenkins & Terraform]]></title>
            <link>https://medium.com/@sonynwoye/simplifying-ci-cd-deploying-applications-to-aws-kubernetes-with-jenkins-terraform-d70864699b0b?source=rss-cf9f429d8253------2</link>
            <guid isPermaLink="false">https://medium.com/p/d70864699b0b</guid>
            <dc:creator><![CDATA[Sunday Nwoye]]></dc:creator>
            <pubDate>Fri, 29 Sep 2023 17:02:40 GMT</pubDate>
            <atom:updated>2023-10-06T07:01:02.406Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*br84X18cwoZ4hVlHcEcpsQ.png" /><figcaption>Architectural Diagram</figcaption></figure><h3><strong>Overview:</strong></h3><p>This project harnesses the power of Jenkins and Terraform to streamline development. Developers commit code to Git, prompting Jenkins to orchestrate a build process. Jenkins compiles Java into a WAR file, elegantly packaging it with Tomcat into a Docker image, destined for Amazon Elastic Container Registry (ECR). Jenkins then calls upon Terraform to craft an Amazon Elastic Kubernetes Service (EKS) cluster, seamlessly deploying the Docker image within. Users enjoy easy application testing via web browsers, embracing the harmony of automation. 🚀 #CI/CD #Jenkins #Terraform #AWS #Kubernetes</p><h3><strong>Requirements:</strong></h3><p>AWS Infrastructure<br>VPC following AWS best practice with public and private subnets<br>Jenkins (Terraform)<br>GitOps or equivalent<br>EKS (Jenkins uses terraform)</p><h3><strong>Steps:</strong></h3><p>Setting Up Jenkins on AWS Using Terraform</p><p>In this guide, we’ll set up a Jenkins server on AWS using Terraform, a tool for infrastructure as code.</p><p>We will configure AWS credentials or profiles that Terraform will use to create resources in AWS is a crucial step in the process. Here’s how to do it:</p><h3><strong>Step 1: Set Up AWS Credentials</strong></h3><ul><li>AWS CLI Installation: If you haven’t already, install the AWS Command Line Interface (CLI) on your local machine.</li><li>AWS Account: Ensure you have an AWS account with IAM user(you may give it admin privilege) having the necessary permissions to create EC2 instances, security groups, and other resources.</li><li>AWS Access Key and Secret Key: Obtain your AWS access key ID and secret access key. These are the credentials Terraform will use to authenticate with AWS.</li></ul><h3><strong>Step 2: Configure AWS CLI</strong></h3><p>Open a terminal and run the following command to configure AWS CLI:<br>`aws configure`</p><p>You will be prompted to enter:</p><ul><li>AWS Access Key ID: Enter your access key ID.</li><li>AWS Secret Access Key: Enter your secret access key.</li><li>Default region name: Specify your preferred AWS region (e.g. us-east-1).</li><li>Default output format: You can leave this as the default (e.g., json).</li></ul><h3><strong>Step 3: Terraform Script</strong></h3><p>We have a Terraform script in a repository that automates Jenkins server setup. You can access it <a href="https://github.com/profebass99/jenkins-terraform-eks/tree/main/jenkins-server"><strong><em>here</em></strong></a><strong><em>.</em></strong></p><h3><strong>Step 4: Customize</strong></h3><p>Modify the script as needed for your project, including instance type(as we know is better to use a suitable instance type for jenkins, i recommend using at least for this project a t2.medium), region, and specific Jenkins configurations.</p><h3><strong>Step 5: Execution</strong></h3><p>Execute the Terraform script:</p><ul><li>terraform init</li><li>terraform apply</li></ul><h3><strong>Step 6: Post-Deployment &amp; Installing the right plugins for our project</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*d_tKlbUwDDQOzTyeaOi0QQ.png" /></figure><p>Access the Jenkins web interface using the public ipv4 address and you will be prompted with the image above.</p><p>Now navigate to the highlighted link in directory in the Jenkins server to retrieve the password using the command `sudo cat abovementionedlocation`and you should be good to go.<br>Next is to launch your Jenkins instance with the suggested plugins.<br>First we will install suggested plugins and later we will install the needed plugins for our project :).<br><strong>Lets go!!!!!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*WWcYOTkJBGVKvWAPCLM9bw.png" /></figure><p>Then give the details required, save and continue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*WGZd4s1QgWV4N4vCPTEmiA.png" /></figure><ul><li>Go to Dashboard — Manage Jenkins — Plugins The simplest and most common way of installing plugins is through the Manage Jenkins &gt; Plugins view, available to administrators of a Jenkins environment.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*TfQJl4CBTcDueNJUTfBOBA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*-IbxjF2xdxs7sTQ4G_bMvw.png" /></figure><p>Here under Available plugins search for these plugins below and install it without restarting.</p><ul><li>Cloud Bees AWS Credentials</li><li>Amazon ECR</li><li>Docker Pipeline</li><li>Maven integration</li><li>AWS Credentials</li><li>pipeline aws steps</li></ul><h3><strong>Step : configure maven and java(jdk) path in Jenkins.</strong></h3><p>How to integrate Maven with Jenkins? <br>Understand that we have to build our java application into an executable Jar file and then build this jar file into a docker image that will be deployed in our EKS cluster<br>The reason behind integrating Maven with Jenkins is so that we can execute Maven commands through Jenkins as we will majorly use Maven for Java projects. Hence, JDK also comes as a pre-requisite for this setup. So, let’s first quickly see how to can specify the java path in Jenkins:</p><ul><li>In the Jenkins dashboard, go to “Manage Jenkins” &gt; “Global Tool Configuration.”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*BzExBzoCoifejMBge2cu7Q.png" /></figure><ul><li>Under the “JDK” section, click “Add JDK.”</li><li>Provide a name (e.g., “JDK 8”) and specify the JAVA_HOME path (e.g., /usr/lib/jvm/java-8-openjdk-amd64 for OpenJDK 8).</li><li>You can use this command below in your server where the Jenkins is installed to check the path where your java was installed.</li><li>`readlink -f $(which java)`</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*Ovr8-P-d4BUem3Nh9mz7ag.png" /></figure><p>* Now Important!! Scroll down and look for the Maven section and click on add maven, but in our case, this time after providing it a name, check the box<strong> **`install automatically`**</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*oHURYCF5F14OzjjogV0C6Q.png" /></figure><p><strong>Save the configuration.</strong></p><p><strong>Great!! Job!! Keep it going we almost there!! :) .</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*h8ZnW6ky3gU-DotW.jpg" /><figcaption>photo by makeameme.org</figcaption></figure><h3><strong>Step 7: Configuring Jenkins Credentials</strong></h3><p>Now, let’s create AWS credentials in Jenkins:</p><ul><li>In the Jenkins dashboard, go to `”Manage Jenkins” &gt; “Manage Credentials.”`</li><li>Under the “Stores scoped to Jenkins” section, click “Jenkins.”</li><li>Click “Global credentials (unrestricted)” and then “Add Credentials.”</li><li>Choose “AWS Credentials” as the kind of credential.</li><li>In the “ID” field, provide a unique identifier for these credentials (e.g., “AWS_Credentials”).</li><li>Enter your AWS Access Key ID and Secret Access Key in the respective fields.</li><li>Optionally, you can provide a description for these credentials.</li><li>Click “OK” to save the credentials.</li></ul><p><strong><em>In our next steps, we’ll establish a secure and automated connection between GitHub and Jenkins by generating a new SSH key pair. Adding your public SSH key to GitHub ensures secure authentication, authorizes Jenkins to access your repositories, and establishes trusted communication for secure interaction with your GitHub projects.</em></strong></p><p><strong><em>Additionally, incorporating this SSH key pair into Jenkins enables secure authentication with GitHub during interactions with repositories, facilitating a seamless and secure automation and integration process between Jenkins and GitHub. In summary, both GitHub and Jenkins rely on this SSH key pair for authentication and mutual trust, enabling a secure and automated collaboration between the two platfor</em>ms.</strong></p><p><strong>Generate an SSH Key Pair</strong></p><p>If you haven’t already, generate an SSH key pair on your Jenkins server. You can use the ssh-keygen command for this purpose. Run the following command:</p><ul><li>`ssh-keygen -t rsa -b 4096 -C “<a href="/service/mailto:your-email@example.com">your-email@example.com</a>”`</li><li>Replace “<a href="/service/mailto:your-email@example.com">your-email@example.com</a>” with your GitHub email address, and follow the prompts to generate the key pair.</li><li>Add the SSH Public Key to GitHub</li><li>Copy the contents of the public key file (~/.ssh/id_rsa.pub) you just generated.</li><li>Log in to your GitHub account.</li><li>Go to your GitHub account settings by clicking on your profile picture in the upper-right corner, then selecting “Settings.”</li><li>In the left sidebar, click on “SSH and GPG keys.”</li><li>Click “New SSH key” or “Add SSH key.”</li><li>Provide a title (e.g., “Jenkins Server”) and paste the SSH public key into the “Key” field.</li><li>Click “Add SSH key” to save.</li><li>Configure Jenkins to Use the SSH Key</li><li>Log in to your Jenkins dashboard.</li><li>In the Jenkins dashboard, click on “Manage Jenkins” &gt; “Manage Credentials.”</li><li>Under the “Stores scoped to Jenkins” section, click “Jenkins.”</li><li>Click “Global credentials (unrestricted)” and then “Add Credentials.”</li><li>Choose “SSH Username with private key” as the kind of credential.</li><li>In the “Username” field, enter your GitHub username.</li><li>In the “Private Key” field, select “Enter directly” and paste the contents of the private key (~/.ssh/id_rsa) you generated earlier.</li><li>Provide a description (e.g., “GitHub SSH Key for Jenkins”).</li><li>Click “OK” to save the credentials.</li></ul><h3><strong>Step 8: Configure GitHub Webhook</strong></h3><p>Additionally, we’ll set up a webhook trigger between our Jenkins job and GitHub. This webhook will automatically initiate our Jenkins jobs in response to specific push events or code changes in our repository.<br>To set up a webhook in GitHub to trigger Jenkins builds automatically, follow these steps:</p><ul><li>In your GitHub repository, go to “Settings” &gt; “Webhooks.”</li><li>Click “Add webhook.”</li><li>In the “Payload URL” field, enter the URL to your Jenkins server, followed by /github-webhook/ (e.g., <a href="http://your-jenkins-server/github-webhook/">http://your-jenkins-server/github-webhook/</a>).</li><li>Set the “Content type” to “application/json.”</li><li>In the “Secret” field, you can optionally enter a secret token that Jenkins will use to verify the authenticity of the webhook payload. This enhances security.</li><li>Select the events that should trigger the webhook. At a minimum, you’ll want to select “Just the push event” to trigger the build when code is pushed to the repository.</li><li>Click “Add webhook” to save your webhook configuration.</li></ul><h3><strong>Step 9: Create an ECR on AWS</strong></h3><p>We will create an ECR repo where our built docker images will be pushed to. To create an Amazon Elastic Container Registry (ECR) repository in AWS, you can use the AWS Management Console:</p><ul><li>Log in to your AWS account.</li><li>From the AWS Management Console, go to the “Services” dropdown in the top left corner, and under the “Container” section, select “ECR” (Elastic Container Registry).</li><li>In the ECR dashboard, click the “Create repository” button.</li><li>Enter a unique name for your repository in the “Repository name” field. Optionally, add a tag immutability policy if desired. Click “Create repository” to create the ECR repository.</li></ul><h3><strong>Step 10: Configure Jenkins to run our jobs.</strong></h3><p>Configure Jenkins Job</p><p>In the Jenkins dashboard, create a new pipeline job:</p><ul><li>Click “New Item”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*PFLjtMd0JJj2OlyOvyzvEw.png" /></figure><ul><li>Enter a job name &gt; Select “Pipeline” as the job type &gt; Click “OK.”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*NY3aoXb5OCzDNd6j6T-jMw.png" /></figure><ul><li>In the “Build Triggers” option check the box `GitHub hook trigger for GitScm polling`</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*kwdxqo2UrkzYrNy0r8ZfjA.png" /></figure><ul><li>In the job configuration, go to the “Pipeline” section. Choose for the ‘Pipeline script from SCM’ option since our Jenkinsfile resides within the repository. Provide the repository URL and select the previously created GitHub access credentials in the credentials option. Choose the appropriate branch (e.g., ‘main’ or ‘master’) depending on your repo and scm configuration. Specify the Jenkinsfile path; in my case, it’s in the root directory, so I’ll simply use the filename ‘Jenkinsfile’.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*WaD57GLJYD8x80T9rOOC_A.png" /></figure><p>After completing these steps, click ‘Save and Apply’ and then initiate a build to test our job. Moreover, keep in mind that the job can also be triggered automatically when a push event occurs in our repository; it will start promptly in response to the event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*i9n9CBUgTVLiGeyNXfZu7A.png" /></figure><p><strong>WOW!!! Yes You did it !!!!!!!!!! There you go, a successful pipeline.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*KYmmuTEq8GdcSVgT.jpg" /><figcaption>photo by makeameme.org</figcaption></figure><p><strong>Overview or Description of the Jenkins file: </strong><br>So first of all, As you could see from my codes, i am integrating the Jenkinsfile with my scipt.groovy. Using a Jenkinsfile in conjunction with a Groovy script enables a cleaner and more modular CI/CD configuration. The Jenkinsfile defines the pipeline structure, while the Groovy script handles the detailed implementation of each stage’s tasks. This separation enhances code organization, promotes reusability, and simplifies maintenance, making it a more efficient and readable way to manage complex CI/CD processes.</p><p><strong>## My Jenkinsfile defines a declarative pipeline with multiple stages for a</strong> continuous integration and deployment (CI/CD) process. Here’s a breakdown of what each stage is doing:</p><p><strong>## Init Stage:</strong><br>Loads a Groovy script named “script.groovy” and assigns it to the variable gv.</p><p><strong>## Fetch Code Stage:</strong><br>Calls the fetchCode method from the loaded Groovy script (gv) to fetch the source code.</p><p><strong>## Build Stage:</strong><br>Builds the code, using Maven (specified in the “tools” section).<br>Archives the generated artifacts (War files) upon a successful build.</p><p><strong>## Build Image Stage:</strong><br>Calls the buildImage method, which builds a Docker image from the application code.</p><p><strong>## Push Image to ECR Stage:</strong><br>Pushes the Docker image to Amazon Elastic Container Registry (ECR) using the pushImage method.</p><p><strong>## Provision EKS Cluster Stage:</strong><br>Invokes the provisionEksCluster method, which goes beyond just creating an Amazon Elastic Kubernetes Service (EKS) cluster. It also sets up a Virtual Private Cloud (VPC) with essential components like subnets, an internet gateway, NAT gateway, route table, and more. This entire infrastructure is provisioned using a Terraform module. For a deeper understanding of the context, you can refer to the script.groovy and the terraform folder. 😊</p><p><strong>## Connect to EKS Cluster Stage:</strong><br>Calls the connectEks method, indicating the establishment of a connection to the provisioned EKS cluster. And deploying this pushed image in our EKS cluster</p><p><strong>Conclusion:</strong></p><p>In this article, we’ve delved into the world of CI/CD pipelines using Jenkins, Terraform, and AWS Kubernetes. By following these steps, you can streamline your development process, automate deployments, and enhance the overall efficiency of your projects. Embracing automation and modern DevOps practices can lead to smoother, more reliable software delivery.</p><p><strong><em>This is one project you could show to your hiring manager or recruiters during interviews.</em></strong></p><p><strong>About the Author:</strong></p><p>I’m Sunday(A.K.A Sony), and I’ve been deeply involved in the world of CI/CD, DevOps, and cloud technologies for close to a year. I’m passionate about simplifying complex processes and helping developers and teams succeed in their projects. Feel free to connect with me on <a href="https://www.linkedin.com/in/sunday-nwoye-740961236/?lipi=urn%3Ali%3Apage%3Ad_flagship3_feed%3BWwAHY2LRRci6eErYU%2FbjXA%3D%3D"><strong>LinkedIn</strong></a> to stay updated on the latest in CI/CD and cloud automation.</p><p><strong>Thank You and Stay Tuned</strong>:</p><p>Thank you for reading this article! I appreciate your interest and trust that you’ve found this information valuable. Stay tuned for my upcoming tutorials, where I’ll continue to explore exciting topics in the world of DevOps, cloud computing, and software development. Your feedback and suggestions are always welcome :).</p><p><em>Please don&#39;t forget to clap </em>👏🏽 &amp; Connect with me on <a href="https://www.linkedin.com/in/sunday-nwoye-740961236/?lipi=urn%3Ali%3Apage%3Ad_flagship3_feed%3BWwAHY2LRRci6eErYU%2FbjXA%3D%3D"><strong>LinkedIn</strong></a><strong>………….</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d70864699b0b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>