Before setting up the project, ensure you have the following dependencies:
- Sudo: require passwordless sudo permission for the ansible playbook How to Guide
- Docker: Install Docker to run containers. Docker Installation Guide
- Terraform: Install Terraform to configure infrastructure. Terraform Installation Guide
- Ansible: Install Ansible for configuration management and automation. Ansible Installation Guide
- Git: Install Git to clone the repository. Git Installation Guide
-
Clone the Repository
Clone the repository and navigate to the project directory:
git clone https://github.com/orinahum/terraform_single_docker.git cd terraform_single_docker
-
Run the Setup Script
To install and deploy the infrastructure, run the
setup.sh
script provided in the project. The script is interactive and offers both installation and uninstallation options:-
To run the installation:
./setup.sh
This script will perform the following steps:
- Check Dependencies: Verifies if required tools (Terraform, Docker, and Ansible) are installed.
- Apply Terraform Configuration: Uses Terraform to create the infrastructure and outputs the plan to a log file (
terraform_apply_output.log
). - Run Ansible Playbook: Executes the Ansible playbook to configure NGINX with the necessary settings.
-
To uninstall (destroy the infrastructure):
./setup.sh --uninstall
This command will destroy all infrastructure created by Terraform.
-
- Dependency Check: The script starts by checking if Terraform, Docker, and Ansible are available on your system. If any of these tools are missing, the script will exit with an appropriate error message. This ensures that all necessary tools are in place before proceeding.
-
Terraform Apply: The script then runs
terraform apply
to create the infrastructure in theterraform/
directory. The output of the plan is logged to a file calledterraform_apply_output.log
for reference. This command provisions the required Docker containers as specified in the Terraform configuration. -
Run Ansible Playbook: After Terraform has provisioned the infrastructure, the script uses Ansible to perform additional configuration on the infrastructure, such as setting up NGINX with the proper configuration files. This ensures that the application environment is correctly configured and ready for use.
- Terraform Destroy: If the script is run with the
--uninstall
flag, it will attempt to destroy all resources created during the installation usingterraform destroy
. If the destroy process fails, an error message along with the specific error details will be displayed.
Once the deployment is complete, you can access the application via the NGINX load balancer using the configured DNS name (e.g., https://example.local
). Make sure your system's hosts file includes an entry mapping this DNS name to the NGINX container's IP address.
To destroy the infrastructure and remove all created resources, run:
./setup.sh --uninstall
This command will safely remove all resources that were previously deployed.