Automating Infrastructure using AWS and Terraform

What is AWS?

Amazon Web Services (AWS) is the world’s most comprehensive and broadly adopted cloud platform, offering over 200 fully featured services from data centers globally. Millions of customers — including the fastest-growing startups, largest enterprises, and leading government agencies — are using AWS to lower costs, become more agile, and innovate faster.

What is Terraform?

Terraform is an infrastructure as code (IaC) tool that allows you to build, change, and version infrastructure safely and efficiently. This includes low-level components such as compute instances, storage, and networking, as well as high-level components such as DNS entries, SaaS features, etc. Terraform can manage both existing service providers and custom in-house solutions.

What is CI/CD pipeline?

CI and CD are two acronyms frequently used in modern development practices and DevOps. CI stands for continuous integration, a fundamental DevOps best practice where developers frequently merge code changes into a central repository where automated builds and tests run. But CD can either mean continuous delivery or continuous deployment.

CI/CD Pipeline

Continuous Integration :

Continuous Integration is a process where developers work on code changes and commit the code very frequently to repository. CI triggers the build every time whenever new code changes detected in repository. Unit testing is performed against these code changes every time. CI enables to detect the errors at early stage or when code is being integrated. CI is a set of principles that helps developers to manage code integrations and detect early stage bugs and rectify them.

Continuous Delivery :

Continuous delivery is an extension of continuous integration since it automatically deploys all code changes to a testing and/or production environment after the build stage.

Continuous deployment :

Continuous deployment goes one step further than continuous delivery. It is most critical stage in pipeline. In this process code changes are automatically deployed to production environment where end customers or users are using the application. It is achieved by taking the benefit of continuous delivery by automating new stage (Production) in the pipeline. There is very less human interaction at this stage and it helps to reduce delay in making code changes live.

Continuous Delivery vs Continuous Deployment

What is .NET?

.NET is a developer platform made up of tools, programming languages, and libraries for building many different types of applications.

  1. .NET Core is a cross-platform implementation for running websites, services, and console apps on Windows, Linux, and macOS. .NET Core is open source on GitHub.
  2. Xamarin/Mono is a .NET implementation for running apps on all the major mobile operating systems, including iOS and Android.

Terraform Script :

Connection with cloud providers :

provider “aws” {
region = “us-east-1”
access_key = “***”
secret_key = “***”
}
resource “aws_vpc” “sgp” {
cidr_block = “10.0.0.0/16”
tags = {
Name = “SGP”
}
}
resource “aws_internet_gateway” “gw” {
vpc_id = aws_vpc.sgp.id
}
resource “aws_subnet” “publicsubnet” {
vpc_id = aws_vpc.sgp.id
cidr_block = “10.0.1.0/24”
availability_zone = “us-east-1a”
tags = {
Name = “Public-subnet”
}
}
resource “aws_subnet” “privatesubnet” {
vpc_id = aws_vpc.sgp.id
cidr_block = “10.0.2.0/24”
availability_zone = “us-east-1a”
tags = {
Name = “Private-subnet”
}
}
resource “aws_route_table” “public-route-table” {
vpc_id = aws_vpc.sgp.id
route {
cidr_block = “0.0.0.0/0”
gateway_id = aws_internet_gateway.gw.id
}
route {
ipv6_cidr_block = “::/0”
gateway_id = aws_internet_gateway.gw.id
}
tags = {
Name = “Public”
}
}
resource “aws_network_interface” “sgp-nic” {
subnet_id = aws_subnet.privatesubnet.id
private_ips = [“10.0.2.50”]
security_groups = [aws_security_group.allow_web.id]
}
resource “aws_route_table” “private-route-table” {
vpc_id = aws_vpc.sgp.id
route {
cidr_block = “10.0.2.0/24”
network_interface_id = aws_network_interface.sgp-nic.id

}
tags = {
Name = “Private”
}
}
tags = {
Name = “Private”
}
}
resource “aws_route_table_association” “private” {
subnet_id = aws_subnet.privatesubnet.id
route_table_id = aws_route_table.private-route-table.id
}
resource “aws_security_group” “allow_web” {
name = “allow_web_traffic”
description = “Allow Web inbound traffic”
vpc_id = aws_vpc.sgp.id
ingress {
description = “HTTPS”
from_port = 443
to_port = 443
protocol = “tcp”
cidr_blocks = [“0.0.0.0/0”]
}
ingress {
description = “HTTP”
from_port = 80
to_port = 80
protocol = “tcp”
cidr_blocks = [“0.0.0.0/0”]
}
ingress {
description = “SSH”
from_port = 22
to_port = 22
protocol = “tcp”
cidr_blocks = [“0.0.0.0/0”]
}
egress {
from_port = 0
to_port = 0
protocol = “-1”
cidr_blocks = [“0.0.0.0/0”]
}
tags = {
Name = “allow_web”
}
}
resource “aws_instance” “web-server-instance” {
ami = “ami-087c17d1fe0178315”
instance_type = “t2.micro”
availability_zone = “us-east-1a”
key_name = “sgp”
tags = {
Name = “web-server”
}
}

Overview of Project :

Website using .NET framework

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store