AWS Ntier Architecture
- Ntier is very popular architecture for deploying web applications
- web-tier: Webservers will be hosted which serve webpages and they will be accessed directly/indirectly from internet
- app/business tier: This tier has applications which run the business logic
- data tier: we store the data in the database
Phase 1: Create basic network and subnets
-
Goal
-
We have two categories of subnets of here
- public subnets (web-1, web-2)
- private subnets (others)
- Refer Here for changes done to create vpc and subnets
- Now lets add an internet gateway Refer Here for changes
- Now lets create a public route table and private route table and associate them to subnets Refer Here for the changes
-
Now lets add route for public route table to forward to internet gateway Refer Here
-
Now we need to create security groups
- web
- allow 80 and 22 port from any where
- app
- allow 8000 port within vpc
- db
- allow 3306 port within vpc
- web
- Refer Here for the changes
- Now lets try to create a ec2 instance in web
- ami id
- key pair
- security group
- subnet
- public ip
- instance type
- Refer Here for creating an ec2 instance and outputs
Conditional resource creation
- We have already used the count meta argument, in the count if we pass zero then resource will not be created. Refer Here
resource "aws_internet_gateway" "ntier" {
# conditional creation
count = length(var.public_subnets) > 0 ? 1 : 0
vpc_id = aws_vpc.ntier.id
tags = {
Name = "ntier-igw"
}
}
Locals
- Refer Here for official docs
Outputs
- Refer Here for terraform outputs
Terraform block
- Refer Here for official docs of terraform block
- From terraform block we can restrict
- provider versions
- which terraform version is required to run the template
- Versioning constraints Refer Here
- Refer Here for changes in providers to restrict terraform and providers version
