From 555c26386e3a756e793b0f9a8a485c2610a192bc Mon Sep 17 00:00:00 2001 From: Andy Miles Date: Sun, 8 Dec 2024 07:04:44 -0800 Subject: [PATCH] hopefully resolved cleanu and timing issues with deployment --- README.md | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 180 insertions(+) diff --git a/README.md b/README.md index fec63a5..39ebbbf 100644 --- a/README.md +++ b/README.md @@ -59,3 +59,183 @@ TODO: install the project as a module with poetry build and pip or poetry install from the dist dir whl file. Put the .whl in a registry, Also note that the delay in deployment during the time the EC2 instance is up is caused by the time it takes to clone the github repo. + + +# More info +## ssh keys + +Here's a complete guide for setting up SSH keys for EC2 instances with Terraform and GitHub Actions: + 1. Generate SSH Keys Locally + +```# Generate key pair +ssh-keygen -t rsa -b 4096 -f id_rsa -N "" + +# This creates: +# - id_rsa (private key) +# - id_rsa.pub (public key) + 2. Add to GitHub Secrets +Add these secrets in your GitHub repository (Settings > Secrets and variables > Actions): + +SSH_PRIVATE_KEY: (contents of id_rsa) +SSH_PUBLIC_KEY: (contents of id_rsa.pub) + 3. Update Terraform Configuration + +# main.tf +resource "aws_key_pair" "deployer" { + key_name = "deployer-key" + public_key = var.ssh_public_key # Use variable instead of file() +} + +variable "ssh_public_key" { + description = "Public key for SSH access" + type = string +} + 4. GitHub Actions Workflow + +name: Terraform AWS Deployment + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + terraform: + runs-on: ubuntu-latest + + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: us-west-2 + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v2 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS_REGION }} + + - name: Create terraform.tfvars + run: | + cat > terraform.tfvars <