Giter Site home page Giter Site logo

jeffersonmf / aws-lab Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rogeriomm/aws-lab

0.0 0.0 0.0 17 KB

Terraform AWS free tier, EC2, RDS postgres. Docker running on EC2, Traefik reverse proxy, Lets Encrypt, dynamic DNS, OpenVPN

HCL 100.00%

aws-lab's Introduction

Terraform AWS Free Tier

Getting started with the Terraform for managing a base free-tier AWS resources.

Project description

This is a Terraform project for managing AWS resources.

It can build the next infrastructure:

  • VPC
  • Public Subnet in the VPC
  • IGW to enable access to or from the Internet for VPC
  • Route Table to associate IGW, VPC and Subnet
  • EC2 Instance in the public Subnet with the HTTP(s) & SSH access

Pre steps

  1. Install software
    • MACOS
brew install terraform awscli yq
  1. Create AWS account
  2. If the file ~/.aws/credentials doesn't exist, create it and add you Terraform profile to the file. For example:
   [terraform]
   aws_access_key_id = Your access key
   aws_secret_access_key = Your secret access key 
  1. Check AWS account
aws sts get-caller-identity
  1. Create S3 bucket to store Terraform state
aws s3api create-bucket --bucket world-terraform --region us-east-1
  1. Create config file config.tf that will contain information how to store state in a given bucket. See example.

  2. Create SSH key pair to connect to EC2 instance:

   cd ./src/free-tier/provision/access

   # it creates "free-tier-ec2-key" private key and "free-tier-ec2-key.pub" public key
   ssh-keygen -f free-tier-ec2-key

Build infrastructure

cd ./src/free-tier
terraform init -backend-config="./backend/config.tf"
cd ./src/free-tier
terraform plan
cd ./src/free-tier
terraform apply

Post install

ip=$(aws ec2 describe-instances | 
      yq 'select(.Reservations[].Instances[].State.Code == 16) | .Reservations[].Instances[].NetworkInterfaces[].PrivateIpAddresses[].Association.PublicIp')
echo $ip
ssh-add src/free-tier/provision/access/free-tier-ec2-key
  • Edit /etc/hosts add "aws" host name
sudo bash -c "echo $ip aws >> /etc/hosts"
ssh-keygen -R aws  
ssh-keyscan -H aws >> ~/.ssh/known_hosts
ssh-keygen -R $ip
ssh-keyscan -H $ip >> ~/.ssh/known_hosts
ssh ec2-user@$ip "sudo amazon-linux-extras install epel -y"
  • FIXME
ssh ec2-user@$ip "sudo yum update && sudo yum install -y openvpn"
sudo yum update && sudo yum upgrade && sudo yum install -y telnet
ssh ec2-user@$ip "sudo yum update && sudo yum upgrade && sudo yum install -y telnet openvpn"
ssh ec2-user@$ip "sudo yum update && sudo yum install -y docker python3-pip htop && sudo usermod -a -G docker ec2-user && sudo pip3 install docker-compose"
ssh ec2-user@$ip "sudo systemctl enable docker.service && sudo systemctl start docker.service && systemctl status docker.service"
  • Edit src/docker/env-duckdns.sh
SUBDOMAINS=your-subdomain
DUCKDNS_TOKEN=your-token
TOKEN=$DUCKDNS_TOKEN
  • Edit src/docker/docker-compose.yaml, set email and Duckdns subdomain FIXME
  • Edit src/docker/conf/users.txt FIXME
ssh ec2-user@$ip "mkdir -p docker/conf"
#scp src/docker/docker-compose.yaml src/docker/env-duckdns.sh ec2-user@$ip:./docker/
scp src/docker/conf/dynamic_conf.yml ec2-user@$ip:./docker/conf/dynamic_conf.yml
scp src/docker/conf/users.txt ec2-user@$ip:./docker/conf/users.txt
ssh ec2-user@$ip "cd docker && docker-compose up -d"

Duckns

TZ=America/Sao_Paulo
SUBDOMAINS=sub-domain-1,sub-domain-2,sub-domain-3,sub-domain-4,sub-domain-5
DUCKDNS_TOKEN=your-token
TOKEN=your-token
  • Duckdns logs
ssh ec2-user@$ip "cd docker && docker-compose logs duckdns"

Traefik

  • Traefik logs
ssh ec2-user@$ip "cd docker && docker-compose logs traefik"

AWS RDS

aws rds describe-db-instances | yq

Destroy infrastructure

cd ./src/free-tier
terraform destroy

aws-lab's People

Contributors

rogeriomm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.