Part three of Terraform project. In this lab I will add an React App backed with API and MongoDB
Previousll I created an advanced AWS VPC spanning 2 AZs with both public and private subnets. An internet gateway and NAT gateway was deployed into it. Public and private route tables were established. An application load balancer (ALB) will be installed which will load balance traffic across an auto scaling group (ASG) of Nginx web servers. Security groups will be created and deployed to secure all network traffic between the various components.
Private subnets will host the frontend application and ALB will distribute traffic to them. Application includes bootstrapped React app with API backed with a MongoDB instance. The public subnet will host bastion host for connectivity.
├── main.tf ├── modules │ ├── application │ │ ├── main.tf │ │ ├── outputs.tf │ │ └── vars.tf │ ├── bastion │ │ ├── main.tf │ │ ├── outputs.tf │ │ └── vars.tf │ ├── network │ │ ├── main.tf │ │ ├── outputs.tf │ │ └── vars.tf │ ├── security │ │ ├── main.tf │ │ ├── outputs.tf │ │ └── vars.tf │ └── storage │ ├── install.sh │ ├── main.tf │ ├── outputs.tf │ └── vars.tf ├── outputs.tf ├── terraform.tfvars └── variables.tf├── ec2.userdata ├── main.tf ├── outputs.tf ├── terraform.tfvars └── variables.tf
- Create Terraform template to launch resources
- Create AWS environment including VPC, subnets, EC2 instance, route table, internet gateway
- Provide EC2 userdata from a separate file
- Use terraform modules for application, network, bastion, storage and security layers
- AWS account
- Terraform installed
- KeyPair in EC2 (I called my cloudacademydemo)
- Start off with initializing terraform project in your directory
- Plan the terraform environment execution by running
- Deploy the resources by running
When terraform completes there should be 4 instances running
Navigate to the DNS name found in the Load Balancers tab. You should be able to vote on your favorite language. Votes are send by executing a Ajax request to API and logged in the MongoDB database.
- Try connecting to the bastion host and jump over to the MongoDB instance. I use PuTTY to connect to the bastion’s public IP and use Allow agent forwarding option to connect to database instance.
- Delete all the resources by running: