This guide provides the steps to deploy a FastAPI and MySQL application using Terraform and Ansible.
- Terraform: Install Terraform by following the instructions here.
- Ansible: Install Ansible by following the instructions here.
- AWS CLI: Install AWS CLI by following the instructions here.
- AWS Credentials: Configure your AWS credentials using
aws configure
.
First, create an SSH key pair in AWS. This key pair will be used to access your EC2 instances.
aws ec2 create-key-pair --key-name MyKeyPair --query 'KeyMaterial' --output text > ~/.ssh/MyKeyPair.pem
chmod 400 ~/.ssh/MyKeyPair.pem
- Clone the Repository Clone the repository to your local machine:
git clone https://github.com/Franky-Lim24/heap-workshop.git
cd heap-workshop
- Deploy Infrastructure with Terraform Navigate to the Terraform directory and initialize Terraform:
cd terraform
terraform init
Apply the Terraform configuration to deploy the infrastructure:
terraform apply
- Note the Outputs After Terraform has completed, it will output the following information:
- Public IP address
- DNS
- Instance ID
- Configure Ansible Inventory Navigate to the Ansible directory:
cd ../ansible
Edit the inventory.ini file and replace the placeholder with the actual IP address output by Terraform:
[web]
<public_ip> ansible_user=ubuntu ansible_ssh_private_key_file=~/.ssh/MyKeyPair.pem
- Deploy the Backend Application with Ansible Run the Ansible playbook to configure the server and deploy the application:
ansible-playbook -i inventory.ini deploy.yml