Launching Wordpress and Mysql Database Server using Terraform Code by creating Private and Public Subnets
Objective :
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.
Pre-requisites:
1] IAM user creation in aws account.
2] AWSCLI configuration
3] Terraform application installed.
Write a Infrastructure as code using terraform, which automatically create a VPC.
For better understanding of the task follow the steps:
Step I :
Before creating VPC, first we have to mention provider of AWS for understanding API interactions.The Amazon Web Services (AWS) provider is used to interact with the many resources supported by AWS. The provider needs to be configured with the proper credentials before it can be used.
Step II :
Create a Virtual Private Cloud. A virtual private cloud is a virtual network dedicated to your AWS account. It is logically isolated from other virtual networks in the AWS Cloud. It will isolate us from outside real world.
Step III:
In that VPC we have to create 2 subnets:
Public subnet for wordpress which can be accessible from outside world. For that we are here using map_public_ip_on_launch. So that whenever we launch subnet, it will one public ip to the wordpress. Another subnet is for mysql database server which is private. Because we don't to showcase our data to the outside world.
Step IV:
Create a public facing internet gateway for connect our Network to the internet world and attach this gateway to our VPC. An internet gateway is a horizontally scaled, redundant, and highly available VPC component that allows communication between your VPC and the internet.
Step V:
Create a routing table for Internet gateway so that instance can connect to outside world, update and associate it with public subnet. A route table contains a set of rules, called routes, that are used to determine where network traffic from your subnet or gateway is directed.
Step VI:
Associating Public subnet to this route table:
Step VII:
Create Security Groups for Wordpress and Mysql server:
A security group acts as a virtual firewall for your EC2 instances to control incoming and outgoing traffic. Inbound rules control the incoming traffic to your instance, and outbound rules control the outgoing traffic from your instance.
This security group allows only http and ssh connectivity for the clients to worpress site.
This security group will allow connectivity to clients coming on mysql port.
Step VIII:
Let's launch an ec2 instance which has WordPress setup in the public which is already having the security group allowing port 80 so that our client can connect to our WordPress site.Also attach the key to instance for further login into it. AMI for wordpress is available in the AMImarketplace.
Also launch Mysql ec2 instance in the private subnet to restricts users to access delicate data.
So our two instances of wordpress and mysql becomes ready!!
By using Public instance ip or Public DNS name of Wordpress, we can access wordpress site. If we trying it for the time, then we will some error and there we need to subscribe the ami image used for the wordpress.
By entering instance ID of wordpress, we are able to access wordpress site.
By clicking on the login, we can see wordpress login setup.
So our full setup is ready!!
We have successfully launched Wordpress and Mysql Database Server using Terraform Code by creating Private and Public Subnets.
Thank you Reading!!!
For any queries or suggestions DM me.
Nicee..
Nice one 👍
Nice...
Good ✨