Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 2, 2022 08:14 pm GMT

Deploying a Two-Tier Architecture in AWS Using Terraform Modules in Terraform Cloud

Image description

This is the same continuation of my previous article on Deploying a two-tier architecture in AWS using Terraform Modules, but in Terraform Cloud.

Objectives are the same which are given below:

Objectives:

1. Create a highly available two-tier AWS architecture containing the following:

  • 3 Public Subnets

  • 3 Private Subnets

  • Auto Scaling Group for Bastion Host and Web Server

  • Internet-facing Application Load Balancer for Web Server

2. Use module blocks for ease of use and re-usability.

In this article, I am going to show only on how to deploy the same infra-structure in Terraform Cloud.

Used Terraform Cloud Documentation.

What you will need in addition is a Terraform Cloud Account.

What is Terraform Cloud?

Terraform is an infrastructure as code tool that lets you define and manage infrastructure resources through configuration files. It uses modules for readability and re-usability. It securely stores state and secret data, and can connect to version control systems so that you can develop your infrastructure. It helps you to collaborate with your teams in your organization so that all can review at the same time you plan a new change, and approve the plan before you apply it.

Click on my repository link below to clone it into Cloud9 IDE.

Create a Terraform Cloud account

  • Sign into Terraform Cloud

  • In your Terraform Cloud dashboard, navigate to Settings

Image description

  • On the left hand, scroll down to Providers

Image description

  • Click Add a VCS provider at the top right of screen

Image description

  • Click GitHub and select GitHub.com (Custom)

Image description

  • After making sure you are signed into your GitHub account, in the Terraform Cloud web page, click on the link register a new OAuth Application.

  • Use the information given to fill out the fields in your GitHub account.

Image description

  • Register application

Image description

  • Finish without creating a SSH key pair.

Image description

  • In Terraform Cloud dashboard, click to create a New Workspace

Image description

  • Click Version control workflow

Image description

  • click the GitHub custom you just created

Image description

  • Select repository for this project, awsmine/2_tier_architecture_modules_terraform_cloud

Image description

  • Create a name for this workspace and select Create workspace

Image description

  • Click Go to workspace overview to add variables

Image description

  • Click Configure variables.

Image description

  • Click Add variable in the Environment Variable section.

Image description

  • First add your 1st environment variable AWS_ACCESS_KEY_ID for your IAM user with admin permissions.

  • Ensure that you click Sensitive for these variable. This will prevent your variable value from being displayed.

Image description

  • Then add your 2nd environment variable AWS_SECRET_ACCESS_KEY for your IAM user with admin permissions.

  • Ensure that you click Sensitive for these variable. This will prevent your variable value from being displayed.

Image description

  • Then add your 3rd environment variable for AWS_DEFAULT_REGION set to us-east-1

Image description

  • Then add your 4th environment variable create a CONFIRM_DESTROY variable set to 1. This is needed to destroy our infrastructure later.

Image description

  • Instead of using a .tfvars file in the GitHub repo, we are adding our access_ip variable to the Terraform Variables. In our root main.tf, the access_ip is set up which determines the CIDR block that can SSH into our Bastion Host. Use 0.0.0.0/0, but you can also use your personal IP address.

Image description

  • See the list of Environment and Terraform variables added

Image description

  • Now click the Actions link at the top right and select Start new run

Image description

  • Write test for Reason for starting run, Choose run type Plan and apply (standard) and click Start run

Image description

  • Plan running

Image description

  • Once Plan finished

Image description

  • go all the way down , click Confirm & apply

Image description

  • write test apply and click Confirm Plan

Image description

  • you will see Apply running

Image description

  • Apply errored
  • Error: with the retirement of EC2-Classic no new non-VPC EIPs can be created

Image description

  • But our infrastructure is completed.

Image description

VERIFY

DNS name

Image description

Security group for Bastion host

Image description

  • Copy the Public IP of the Bastion host

Image description

  • Using Putty and Putty Agent forwarding (use Pageant Putty authentication agent), log into the putty session using the key name from the root main.tf (NVirKey) as your EC2 Key Pair name via SSH connection.

  • Test Internet connection by ping google.com

Image description

  • Validate 1st webserver (named as database server)
  • Security group for webserver host

Image description

  • copy the Private IP address of 1st webserver (database server)

Image description

  • SSH from the bastion host

Image description

  • verify internet connection ping google.com

Image description

  • Validate 2nd webserver (named as database server)Security group for webserver host

Image description

  • copy the Private IP address of 2nd webserver (database server)

Image description

  • SSH from the bastion host

  • verify internet connection ping google.com

Image description

Clean up

Navigate to your Workspace and click *Settings/Destruction and Deletion.
*

Image description

Image description

  • First click Queue destroy plan and follow the below prompts

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

  • Now Delete workspace from Terraform Cloud

Image description

  • Delete workspace

Image description

  • check to see that everything is cleaned up

Image description

What we have done so far

In Terraform Cloud, we created two Web servers placed in Private Subnets which has access to the internet through a Bastion host placed in Public Subnets with High availability and Load Balancing features.


Original Link: https://dev.to/aws-builders/deploying-a-two-tier-architecture-in-aws-using-terraform-modules-in-terraform-cloud-5c8n

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To