The infrastructure deployment code for a school project.
If you don't have time.
# replace with real values
export AWS_ACCESS_KEY_ID=<id>
export AWS_SECRET_ACCESS_KEY=<secret>
export TF_VAR_db_username=<username>
export TF_VAR_db_password=<password>
export SSH_KEY_PATH=<path>
export TF_VAR_vpc_id=<vpc id>
# don't bother reading
export BOTO_USE_ENDPOINT_HEURISTICS=true
pip install boto ansible
cd terraform
terraform init
terraform apply --auto-approve
cd ../ansible
ansible-galaxy role install -r requirements.yml
ansible-playbook ./main.yml --user ubuntu --key $SSH_KEY_PATH -i ./inventory/ec2.py
This repository is meant to create and configure the infrastructure. Application deployment is done on application repositories (api and client). First, deploy the infrastructure from this repository. Then you can deploy the applications on the newly created infrastructure, by pushing your changes on branch master or preprod of the application.
First, export the AWS credentials of the user (create one) who will deploy the infrastructure
export AWS_ACCESS_KEY_ID=<id>
export AWS_SECRET_ACCESS_KEY=<secret>
Install Python dependencies
pip install boto ansible
Boto enables accessing AWS resources. You may use a region that is not supported by Boto, such as eu-west-3. To prevent such a problem, enable automatic region finding:
export BOTO_USE_ENDPOINT_HEURISTICS=true
If you are deploying this project for the first time, install Terraform and run
cd terraform
terraform init
Prepare credentials for the database:
export TF_VAR_db_username=<username>
export TF_VAR_db_password=<password>
Export the id of your vpc
export TF_VAR_vpc_id=<vpc id>
To deploy the infrastructure, run
terraform apply [--auto-approve]
cd ../ansible
Install roles
ansible-galaxy role install -r requirements.yml
Run Ansible Playbooks
ansible-playbook ./main.yml --user ubuntu --key <ssh/public/key/path> -i ./inventory/ec2.py
ec2.py is a programmatic way to find all EC2 instances IPs.
// todo : put all instructions in 1 script for easier deployment
// todo : aws kms for encryption