1- clone this repo
git clone https://github.com/Alii2121/IaC-Terraform-AWS-Project.git
2- Create your own key-pair and use in EC2/main.tf
3- Make sure to pass your credentials correctly in main.tf file provider block
4- Comment the backend in RemoteStateFile.tf and change S3 name to a unique one
5- Make sure you Have installed latest version of Terraform and run the following commands inside the project directory
terraform init
terraform apply
6- uncomment the backend and apply step 5 again
- Added Ansible files to configure EC2 machines using configuration management tool tou use it instead of provisioner in Terraform
- Ansible uses 1 of the EC2 public machines as a bastion host to connect to the private ones
- Installs Nginx on all machines then copy a script and run it on the machines
- Pass any script to the ansible files to cinfigure the machines as you like
- The provided IPS are dynamic not static so make sure to clear the all-ips file and use the IPS generated on applying terraform
sudo apt update -y
sudo apt install nginx -y
echo 'server { \n listen 80 default_server; \n listen [::]:80 default_server; \n server_name _; \n location / { \n proxy_pass http://${var.internal-LB-DNS}; \n } \n}' > default
sudo mv default /etc/nginx/sites-enabled/default
sudo systemctl restart nginx
sudo apt install curl -y