This project uses Terraform to create cloud instances and Ansible to deploy applications across multiple cloud providers and frameworks.
- Provides a modular structure for different cloud providers and frameworks
- Creates necessary cloud resources (e.g., EC2 instances for AWS)
- Sets up security groups and networking
- Generates SSH key pairs for secure access
- Uses Ansible to deploy and configure applications
- Terraform installed on your local machine
- Ansible installed on your local machine
- Accounts and necessary permissions for supported cloud providers (AWS, Azure, GCP)
- Respective CLI tools configured with your credentials (optional)
.
└── terraform
├── aws
│ ├── laravel
│ └── node
│ ├── ansible.cfg
│ ├── inventory.tpl
│ ├── main.tf
│ ├── playbook.yml
│ └── variables.tf
├── azure
└── gcp
-
Clone this repository.
-
Navigate to the desired provider and framework directory:
cd terraform/aws/node
-
Initialize Terraform:
terraform init
-
Plan the Terraform execution:
terraform plan
-
Apply the Terraform configuration:
terraform apply
You will be prompted to enter values for the variables if not provided.
-
The Ansible playbook will run automatically after the cloud resources are created.
-
To destroy the created resources when you're done:
terraform destroy
You can also run the entire process in one step by providing all variable values in the command line. For AWS Node.js deployment:
terraform apply -auto-approve \
-var="access_key=<YOUR_AWS_ACCESS_KEY>" \
-var="secret_key=<YOUR_AWS_SECRET_KEY>" \
-var="region=<AWS_REGION>" \
-var="key_name=<PEM_FILE.pem>" \
-var="instance_type=<AWS_INSTANCE_TYPE>" \
-var="ami_id=<AWS_AMI_ID_FOR_SELECTED_ZONE>" \
-var="instance_name=<INSTANCE_NAME>"
Replace the placeholders (enclosed in <>) with your actual values.
The Ansible playbook (playbook.yml
) performs framework-specific tasks. For the AWS Node.js setup, it:
- Installs Node.js and npm
- Clones a specified Git repository containing a Node.js application
- Installs application dependencies
- Sets up and starts the application using PM2
You can modify the Ansible playbook to suit your specific deployment needs.
- The private key for SSH access will be saved in the current directory with the name specified in
key_name
. Ensure to keep this file secure and do not commit it to version control. - For AWS Node.js deployments, the application will be accessible at
http://<INSTANCE_PUBLIC_IP>:3000
after deployment. - Ensure your cloud provider credentials have the necessary permissions to create the required resources.
- The structure allows for easy addition of new cloud providers and frameworks. Simply add new directories under the respective provider folder and include the necessary Terraform and Ansible files.