Your containerized application with IAC on AWS — Pt.1

Paloma Lataliza - May 3 - - Dev Community

These days, automation and efficiency are critical in the realm of cloud computing. The administration of your containerized apps may be optimized with AWS Fargate and Infrastructure as Code (IaC). This blog article will walk you through the process of utilizing these potent technologies to increase your applications scalability and efficiency.

FARGATE
Amazon’s container computing service, Fargate, allows you to use AWS containers without the need to manage servers.
I have written a blog article regarding Fargate that you may read here.

INTRODUCTION TO INFRASTRUCTURE AS CODE (IAC)
Infra as code is super important when we think about a stable, scalable and prepared infrastructure for any accident. You may use software development methods like code review and continuous testing, as well as version, reuse and share your configuration by describing your infrastructure in configuration files.

I’ve written a blog article about Terraform and Terragrunt, which we’ll be using in this instance.

CONNECTING AWS TO YOUR COMPUTER
With the help of the AWS CLI, you can easily control AWS services from the terminal on your PC. It allows you to use scripts to automate operations and manage a variety of AWS services.

INSTALLATION OF AWS CLI
windows

Go to the official AWS website and download the MSI installation.

Linux
To download the installation package, use curl. Apply the subsequent command:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-2.0.30.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
Enter fullscreen mode Exit fullscreen mode

To confirm if it was installed, run the command:

aws --version
Enter fullscreen mode Exit fullscreen mode

MacOs
Run the installer after downloading it from this link: https://awscli.amazonaws.com/AWSCLIV2-2.0.30.pkg

which aws
aws --version
Enter fullscreen mode Exit fullscreen mode

…………………………………

INSTALLATION OF TERRAFORM AND TERRAGRUNT
TERRAFORM

Linux
First, open your terminal. We’ll use wget or curl to download the latest version of Terraform:

wget https://releases.hashicorp.com/terraform/1.1.0/terraform_1.1.0
Enter fullscreen mode Exit fullscreen mode

Now, if unzip isn’t already installed, let’s install it before unzipping the file:

sudo apt-get install unzip -y
unzip terraform_1.1.0_linux_amd64.zip
Enter fullscreen mode Exit fullscreen mode

In this step, we will move the terraform executable to a directory included in your system PATH, such as /usr/local/bin:

sudo mv terraform /usr/local/bin/
Enter fullscreen mode Exit fullscreen mode

Finally, we’ll check if the installation is legitimate:

terraform -version
Enter fullscreen mode Exit fullscreen mode

Windows

1.Visit the official Terraform website and get the Windows binary that is needed.

  1. Use WinZip, WinRAR or another unzip application, to extract the file.

  2. Put Terraform in the Path System

Click “This Computer” with a right-click, then choose “Properties.”
Select ‘Environment Variables’ after selecting ‘Advanced System Settings’.
Locate the Path variable under ‘System Variables’ and modify it by adding the path of the directory where you unpacked Terraform.

  1. Use the Command Prompt to Confirm Installation:
terraform -version
Enter fullscreen mode Exit fullscreen mode

MacOs
We are going to start installing Homebrew. If you do not yet have Homebrew, you may install it using this command on the terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

Here, we will install the terraform using Brew. Without a terminal, run:

brew tap hashicorp/tap
brew install hashicorp/tap/terraform
Enter fullscreen mode Exit fullscreen mode

Finally, we will check whether everything is well with our installation:

terraform -version
Enter fullscreen mode Exit fullscreen mode

TERRGRUNT
Windows :
You can install Terragrunt on Windows by using Chocolatey :.choco install terragrunt

MacOS : You can install Terragrunt on Mac by using Homebrew :.brew install terragrunt

Linux : Most Linux users are able to use Homebrew : brew install terragrunt. Users of Arch Linux can utilize pacman -S terragruntto install it community-terragrunt.

FreeBSD : You can install Terragrunt on FreeBSD by using Pkg :.pkg install terragrunt

……………………………………

Configure AWS CLI
In this blog article, we will create a new user and configure our credentials. This user here belongs to the adm group, but be careful when it is necessary to give permissions to other people who use your account or who are users of your organization. Adopt the concept of least privilege always. You may read more about IAM on my blog post here.

We navigate to IAM -> Users -> Create User. Once the user is created, we will create the credentials. To do this, log in with your credentials and select Security Credentials -> Access Keys -> Create Access Key.

Remember to copy the credentials exactly as they were created.

After creating the credentials, lets open a terminal and set up the AWS CLI. To do this, type the command below and provide your credentials:

aws configure
Enter fullscreen mode Exit fullscreen mode

To test, simply run a command for any service. Here we will try to list the EC2 instances of the account.

aws ec2 describe-instances
Enter fullscreen mode Exit fullscreen mode

If it returns anything like the code below, it means that it worked. If there is no instance, the code below will be returned; if there is an instance, the information from the GIF conformation will be returned.

{
    "Reservations": []
}

Enter fullscreen mode Exit fullscreen mode

……………………………………

Now that the requirements are all up and operational, we can use Terraform and Terragrunt to build our infrastructure.
In part two of this series, let’s see how. See Ya!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .