Skip to content

onlypwns/devtest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS EC2 Deployment with GitHub Actions, Terraform, and Ansible

This repository demonstrates how to deploy an AWS EC2 instance (free tier) using GitHub Actions, Terraform for infrastructure provisioning, and Ansible for configuration management..

Prerequisites

To use this repository, you'll need:

  1. An AWS account with free tier access
  2. AWS access credentials with permissions to create EC2 instances
  3. A GitHub account
  4. SSH key pair for accessing the EC2 instance

Setup Instructions

1. Fork/Clone this Repository

Start by forking or cloning this repository to your GitHub account.

2. Set up GitHub Secrets

In your repository on GitHub, navigate to Settings > Secrets and variables > Actions and add the following secrets:

  • AWS_ACCESS_KEY_ID: Your AWS access key
  • AWS_SECRET_ACCESS_KEY: Your AWS secret key
  • SSH_PRIVATE_KEY: Your private SSH key (the entire key content including BEGIN and END lines)

3. Update Terraform Variables (Optional)

You may want to update the following in the Terraform files:

  • In variables.tf: Change default AWS region, instance type, or AMI ID
  • In main.tf: Update the security group to restrict SSH access to your IP address

4. Push Changes to Main Branch

When you push changes to the main branch, GitHub Actions will automatically run the workflow to deploy your infrastructure.

5. Manual Deployment

You can also manually trigger the workflow by:

  1. Going to the "Actions" tab in your repository
  2. Selecting the "Terraform and Ansible Deploy" workflow
  3. Clicking on "Run workflow"

What This Deploys

This setup deploys:

  1. A t2.micro EC2 instance (free tier eligible)
  2. A security group allowing SSH access
  3. Apache web server with a simple "Hello" page

Cleaning Up

To avoid ongoing charges, remember to destroy the resources when you're done:

  1. You can add a destroy workflow or run terraform destroy locally
  2. Alternatively, delete the resources manually from the AWS Console

Security Best Practices

This example includes some basic security practices:

  • Using GitHub Secrets for credential management
  • Creating a restrictive security group
  • Setting up firewall rules with Ansible

For a production environment, consider additional measures:

  • Use AWS IAM roles with least privilege
  • Implement AWS Config rules for compliance
  • Set up CloudTrail for auditing
  • Use VPC with private subnets where possible

About

testing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages