AWS ASG-ALB-EC2 Deployment with Terraform — DevOps Diaries

Emrah T.
2 min readFeb 1, 2023

--

The popularity of public cloud thrives making it easier to deploy and manage IT infrastructure and avoiding pricey Total Cost of Ownership (TCO) charges. Although there is strict competition, Amazon Web Services (AWS) leads the sector for nearly a decade in a row.

AWS and other providers have their shiny web management consoles allowing many functions (if not all) to be executed on UI with mouse clicks. On the contrary, there are Infrastructure as Code (IaC) solutions which offer the same functionality based on configuration files. Advantages of IaC over manual provisioning is out of the scope of this article, however, reusability, version control, ability to faster deployment are some of the main reasons why IaC tools are preferred on enterprise-level.

Terraform is one of the most popular IaC tools both open source/free to use and maintained by Hashicorp. Its main function is to provision the infrastructure with automation.

In these tutorial, Terraform will be used to deploy a simple web application on AWS. It assumes basic knowledge about AWS concepts, when in doubt, AWS docs is always available and helpful in here. Application Load Balancer (ALB), Auto Scaling Group (ASG) and Elastic Compute Cloud (EC2) are the main components of this deployment. However, IAM, security groups, ALB listeners, target groups, launch configurations and autoscaling policies are other ingredients within the code.

For programmatic access to AWS with either aws-cli or IaC tools such as Terraform, access keys are needed. AWS docs here explains how to generate them. After generation, there are multiple ways to use. My preferred one is to store them in ~/.aws/credentials file (restricting the access to it with chmod 600). The most important point here is that DO NOT push them to version control systems such as GitHub.

Below, the topology of the application resides. Both Terraform resources and modules are used within the code for demonstrative purposes. A useful discussion about their differences and use-cases can be found here.

Simplified Topology of the Deployment

Source code and the instructions to deploy are available on my GitHub repo. Hope it helps to build and serves as a baseline for similar needs.

PS: If you liked the article, please support it with claps. Cheers!

--

--

Emrah T.
Emrah T.

Written by Emrah T.

Linux, System Adm., IaC, DevSecOps, K8S and Cloud enthusiast. Love what you do or do what you love!!! www.linkedin.com/in/emrah-t-61337713b, github.com/EmrhT

No responses yet