Terraform is used to provision the AWS infrastructure.
cd terraformterraform init🔹 This sets up Terraform by downloading required providers.
terraform apply -auto-approve🔹 This will create an EC2 instance, security groups, and networking configurations in us-east-1.
Once the infrastructure is provisioned, Terraform outputs the EC2 public IP. Use it to access the instance:
echo "EC2 Public IP: $(terraform output public_ip)"Once the EC2 instance is created, configure it using Ansible.
Modify ansible_hosts with the correct EC2 public IP:
[development]
<EC2_PUBLIC_IP> ansible_ssh_user=ec2-user ansible_ssh_private_key_file=~/aws/aws_keys/default-ec2.pemcd ansible
ansible-playbook -i ansible_hosts playbooks/docker-install.yml🔹 This installs Docker and required dependencies.
ansible-playbook -i ansible_hosts playbooks/docker-run.yml🔹 This runs docker-compose on EC2, launching both microservices.
Once the deployment is complete, verify the API is accessible.
ssh -i ~/aws/aws_keys/default-ec2.pem ec2-user@<EC2_PUBLIC_IP>docker psYou should see two running containers: tour-de-france-mvc and tour-de-france-db.
Run the following command from your local machine or EC2:
curl http://<EC2_PUBLIC_IP>:3000/tour-de-france/cyclists✅ If successful, this will return JSON data containing cyclists.
To destroy the provisioned AWS infrastructure, run:
cd terraform
terraform destroy -auto-approveThis removes the EC2 instance and all associated resources.
| Issue | Solution |
|---|---|
| Ansible playbook fails | Ensure ansible_hosts contains the correct EC2 IP |
API returns Unable to retrieve cyclists |
Check if the database has data (SELECT * FROM cyclists;) |
| SSH access denied | Check if you are using the correct AWS key (chmod 400 default-ec2.pem) |