Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sampathshivakumar/e2a5a3bf762e1009cb2654ef181276ba to your computer and use it in GitHub Desktop.
Save sampathshivakumar/e2a5a3bf762e1009cb2654ef181276ba to your computer and use it in GitHub Desktop.

Three-Tier Architecture in AWS Using Terraform

The three-tier architecture is the most popular implementation of a multi-tier architecture and consists of a single presentation tier, logic tier, and data tier.

The following illustration shows an example of a simple, generic three-tier application. Three-tier architecture

GitHub Repo:- https://github.com/sampathshivakumar/3-Tier-Architecture-Terraform

Resources need to be created are

  • Custom VPC
  • 2-Subnets (Public)
  • 1 Subnet (Private)
  • 2-EC2-Instances
  • Security Group
  • Elastic-IP
  • NAT Gateway
  • Internet Gateway
  • Route Table
  • Application Load Balancer
  • Webserver
  • MySQL-DB

Flow of creating Three-Tier Architecture using AWS Management Console

Create a Custome VPC

1

2

3

Now create Subnets

4

5

6

Now Create Route tables

7

8

9

10

Now lets Create Internet gateway

11

12

Attach the Internet gateway to a VPC

13

14

15

Let's Create NAT Gateway

16

17

Now lets Edit subnet associations and Add Route to Internet gateway to my-Public-subnet

18

19

20

21

22

Now lets Edit subnet associations and Add Route to NAT-Gateway to my-Private-subnet

23

24

25

Now we can see the Resource map in Your VPCs

26

27

Now let's Clean the resoures

28

Now let's try to build the same using Terraform

**In two ways we can build the Three-Tier Architecture in AWS Using Terraform

Untitled Diagram

As i have previously build EC2 instance with Security group using Terraform resources, i would like to go with module this time.

I have created a folder and named it Three-Tier Architecture on my pc.

29

I have created 3 files, versions.tf, variables.tf and vpc.tf Inside of vpc.tf only we are going to use/create vpc terraform module

30

Lets start writing terraform configuration files.

31

we have to input vpc module details in vpc.tf

32

34

For subnet divisions i am using Visual Subnet Calculator

link:- https://www.davidc.net/sites/default/subnets/subnets.html

33

Now lets apply terraform init

35

**After terraform init, .terraform directory and .terraform.lock.hcl file is created.

36

.terraform.lock.hcl file contains a lock file format specific to HCL (HashiCorp Configuration Language) and is used to lock the versions of the provider plugins and modules used in your Terraform configuration.

37

.terraform directory structure

terraform dir structure

Apply terrafor validate

38

Apply terraform plan and apply

Plan: 30 to add, 0 to change, 0 to destroy.

Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve.

Enter a value: yes

you can see my-own-vpc created

39

Three-Tier Architecture is created using terraform

3-tire

Thank you for reading this post! I hope you found it helpful. If you have any feedback or questions,Please connect with me on LinkedIn at https://www.linkedin.com/in/sampathsivakumar-boddeti-1666b810b/. Your feedback is valuable to me. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment