HYBRID MULTI-CLOUD COMPUTING TASK-3





The journey with Hybrid Multi-cloud has been fabulous. I have sucessfully completed my 3 task assigned by our mentor, Vimal Daga sir.

Thank you Vimal sir for mentoring me. If I am able to complete my task sucessfully its all because of you sir.

Task 3:

We have to create a web portal for our company with all the security as much as possible.
So, we use Wordpress software with dedicated database server.
Database should not be accessible from the outside world for security purposes.
We only need to public the WordPress to clients.


Prerequisted:
  •  AWS account  
  • create a user from IAM service of AWS
  •  Download the credential
  • Download AWS CLI and set the path in the environmental variables
I will create my infrastructure on AWS through Terraform

Now lets begin:

Step 1:
Configure AWS and create a profile and add the credentails


Step 2: 
Provide the provider that is AWS and create the VPC
CODE:

provider "aws" {
  region     = "ap-south-1"
  profile = "saba1121"
}
// vpc 
resource "aws_vpc" "myvpc_resourcename" {
  cidr_block       = "192.168.0.0/16"
  instance_tenancy = "default"
  enable_dns_hostnames = true

  tags = {
    Name = "myvpc1"
         }
}
output "printvpc_id" {
      value = aws_vpc.myvpc_resourcename.id
                 }




Step 3: 
Create the Internet Gateway for the connectivity to the world
Code:
resource "aws_internet_gateway" "resource_igw" {
  vpc_id = aws_vpc.myvpc_resourcename.id

  tags = {
    Name = "myvpc1_internet_gateway"
  }
}


Step 4: 
Create a public subnet inside the VPC which we have create above
Code:

resource "aws_subnet" "resourcename_publicsubnet" {
  vpc_id     = aws_vpc.myvpc_resourcename.id
  cidr_block = "192.168.0.0/24"
  map_public_ip_on_launch = true
  availability_zone = "ap-south-1a"
  
  tags = {
    Name = "mysubnet1"
  }
}



Step 5:
Creating  a Routing Table and create a route.
Attach the Routing Table
Code:

// routing table
resource "aws_route_table" "routingtable" {
  vpc_id = aws_vpc.myvpc_resourcename.id
 tags = {
    Name = "routing_table"
  }
}

// attaching routing table with subnet1

resource "aws_route_table_association" "rt_attach_subnet" {
  subnet_id      = aws_subnet.resourcename_publicsubnet.id
  route_table_id = aws_route_table.routingtable.id
}

resource "aws_route" "r" {
  route_table_id            = aws_route_table.routingtable.id
  destination_cidr_block    = "0.0.0.0/0"
  
    gateway_id = aws_internet_gateway.resource_igw.id
}


Step 6:
Create the key pairs for the intance
Code:
resource "tls_private_key" "skey" {
  algorithm   = "RSA"
                                  }

resource "aws_key_pair" "resource_key" {
  key_name   = "tabu123"
  public_key = tls_private_key.skey.public_key_openssh 
       }

resource "local_file" "key_file" {
  content = tls_private_key.skey.private_key_pem
  filename = "tabu123.pem"
    }

Step 7:
Create the Security Group for wordpress instance which I launch inside Public subnet
Code:
 resource "aws_security_group" "securitygroup" {                      
  name        = "launch-wizard-1"
  description = "this security group will allow traffic at port 80"
    vpc_id = aws_vpc.myvpc_resourcename.id
      
  ingress {
    description = "http is allowed"
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
    }
ingress {
    description = "ssh is allowed"
    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 = "security_group"                   
  }
}

variable "enter_your_security_group" {
 type = string
  default = "launch-wizard-1"
     }                                               

Step 8:
Now launch the Wordpress Instance
Code:
resource "aws_instance" "myinstance" {
  ami           = "ami-7e257211"
  instance_type = "t2.micro"
  key_name = aws_key_pair.resource_key.key_name
  vpc_security_group_ids = [ aws_security_group.securitygroup.id ]                
  subnet_id      = aws_subnet.resourcename_publicsubnet.id
tags = {
      Name = "wordpress_os"
                }
}

Step 9:
Create the Private Subnet where I launch mysql database instance
Code:
resource "aws_subnet" "resourcename_privatesubnet2" {
  vpc_id     = aws_vpc.myvpc_resourcename.id
  cidr_block = "192.168.1.0/24"
  availability_zone = "ap-south-1b"

  tags = {
    Name = "mysubnet2"
  }
}
Step 10: 
Attach the Routing table to Private Subnet
Code:
resource "aws_route_table_association" "rt_attach_subnet2" {
  subnet_id      = aws_subnet.resourcename_privatesubnet2.id
  route_table_id = aws_route_table.routingtable.id
}


Step 11:
Create the Security group for mysql Instance
Code:
resource "aws_security_group" "securitygroup2" {                      
  name        = "launch-wizard-2"
  description = "this security group will allow traffic at port 80"
    vpc_id = aws_vpc.myvpc_resourcename.id

  ingress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
    }
   ingress {
    description = "mysql"
    from_port   = 0
    to_port     = 3306
    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 = "security_group_mysql"                   
  }
}

Step 12:
Now create the mysql database instance
Code:
resource "aws_instance" "mysqlinstance_rn" {
  ami           = "ami-08706cb5f68222d09"
  instance_type = "t2.micro"
  key_name = aws_key_pair.resource_key.key_name
      
  vpc_security_group_ids = [ aws_security_group.securitygroup2.id ]               
  subnet_id = aws_subnet.resourcename_privatesubnet2.id 
tags = {
      Name = "mysql_os"
                }

                                         }


Now this terraform code is to be run on CLI . First step is  to initailise the terraform code
Command is: terraform init

Validate the code by writing the command
terraform validate

After this run the code by writing the command 
terraform apply







Now copy the DNS name of the wordpress instance and run in browser and enter the instance ID


Set the wordpress password and set your password 
 
In meta select login

Enter the user name :Aurora and give the password earlier set


This was all about this task.Hope you will enjoy and get to know something from this blog
At last by just one command whole setup can be destroyed 
command: terraform destroy








Comments

Popular posts from this blog

Flutter Task-1

HYBRID MULTI-CLOUD TASK-4

Launching Web-app through Terraform