This repository is meant to host all the code related to Lifebit Technical Assignment
- Terraform as our Infrastructure as Code tool.
- AWS as our Cloud Vendor.
- EC2 as our core service to get provisioned and the NodeJS app right after.
- Docker as our container tool to get the NodeJS running onto the server.
- Ansible as our Configuration Management tool to deploy the NodeJS app into the server.
Explanation:
- The EC2 instance is the main server where the application will be deployed. It hosts the Docker container.
- Docker container is used to run the Node.js application. The Docker image is built from the GitHub repository containing the Node.js app.
- The AWS Security Group (sg_ec2) controls incoming and outgoing traffic to the EC2 instance. SSH access is allowed only from the home's public IP address, ensuring secure access. Port 3000 is widely open to allow access to the Node.js application.
- The SSH key pair is used for secure SSH access to the EC2 instance during the deployment process.
- Ansible connects to the EC2 instance using SSH (also with the SSH key generated) and executes the tasks defined in the playbook to deploy the application.
- Terraform
- Ansible
- AWS account with IAM user with enough permissions
- Clone the repository with
git clone https://github.com/Roleyner/lifebit-assignment.git - In the
terraform.tfvarsfile, changeregionandamivalues according to the AWS region and AMI Ubuntu free tier you want to use - Initialize terraform with
terraform init - Do the plan for the provisioning:
terraform plan - Do the apply to make the provisioning happen:
terraform apply
Once the steps mentioned above have been performed, the whole stack will be provisioned and automatically, through terraform, an ansible-playbook command will run to install our NodeJS app and its dependencies.
Either ansible-playbook output or terraform output will provide us with the instance public IP to be able to use it along with the port 3000
As a private key named nodejs-key gets created through terraform into the same repo root directory, we can also leverage it for sshing to the EC2 instance as follows:
ssh -i nodejs-key vm_user@vm_ipv4_dns
Both vm_user and vm_ipv4_dns get outputted by terraform after applying changes to the infrastructure.
It's importante to tear down all the AWS resources used for this implementation, hence terraform destroy needs to be performed :)
