- Introduction
- Infrastructure Setup
- Application Deployment
- Deployment Scripts
- External Modules and Tools
- Code Structure Overview
- Configuration Options
- Troubleshooting and Common Issues
Each module includes separate README generated using terraform-docs:
This project demonstrates the deployment of a typical web application infrastructure on AWS using Terraform for Infrastructure as Code (IaC) and bash scripts for application deployment. The setup includes:
- A Virtual Private Cloud (VPC)
- A MySQL RDS instance
- An ElastiCache Redis instance
- An EC2 instance hosting a WordPress application
All infrastructure components are defined using Terraform configurations located in the repository.
The VPC is configured to host the necessary subnets, route tables, and security groups required for the application.
- Configuration: The RDS instance is set up with the following parameters:
- Engine: MySQL
- Accessibility: Private (not reachable from the public internet)
- Configuration: The Redis instance is configured as follows:
- Engine: Redis
- Accessibility: Private (not reachable from the public internet)
- Configuration:
- Instance Type:
t2.micro
(eligible for AWS Free Tier) - Accessibility: Public (reachable from the internet)
- Instance Type:
WordPress is deployed on the EC2 instance using a custom bash deployment script.
- Database Connection:
- The WordPress application connects to the MySQL RDS instance using environment variables for database credentials and endpoints.
- Session Management:
- WordPress sessions are managed using the ElastiCache Redis instance, with connection details provided via environment variables.
The deployment process is automated using a bash script that performs the following tasks:
- Installs necessary dependencies (e.g., Apache, PHP)
- Downloads and configures WordPress
- Sets up environment variables for database
- Starts the web server
The deployment script is located in the modules/1-ec2/
directory of the repository.
The repository is organized as follows:
-
modules/
: Includes custom Terraform modules used in the infrastructure setup. -
bootstrap/
: Calls thebootstrap
module to create AWS Resources for Remote Backend. -
0-vpc
: Calls thevpc
module to create required Network Infrastructure. -
1-ec2
: Calls theec2
module for creating Wordpress Host and necessary configuration. -
2-rds
: Calls therds
module for creating Database Instance and necessary configuration. -
3-elasticache
: Calls theelasticache
module for creating Single Node Redis Cluster and necessary configuration. -
.gitignore
: Specifies files and directories to be ignored by git. -
README.md
: Provides an overview and instructions for the project.
- Terraform Variables:
- Variables for customizing the infrastructure (e.g., instance types, database settings) are defined in the Terraform configuration files.
-
Issue: EC2 instance not reachable.
- Solution: Verify that the security group associated with the EC2 instance allows inbound traffic on the required ports (e.g., 80 for HTTP).
-
Issue: WordPress cannot connect to the database.
- Solution: Ensure that the RDS instance is accessible from the EC2 instance and that the correct environment variables are set for database credentials. Also, keep in mind the web server-centric nature of PHP when configuring WordPress to read from
wp-config.php
.
- Solution: Ensure that the RDS instance is accessible from the EC2 instance and that the correct environment variables are set for database credentials. Also, keep in mind the web server-centric nature of PHP when configuring WordPress to read from
-
Issue: Sessions not persisting.
- Solution: Check the connection to the Redis instance and verify that the appropriate PHP extensions for Redis are installed.
-
Note: Lots of issues were faced when working with remote state, so the decision for this particular project was made towards using Provider's Data Sources for retrieving dynamic values and dependency management.
For more detailed information, refer to the comments within the Terraform configuration files and the deployment script.