Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: github workflows #1

Merged
merged 15 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/terraform-apply.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Terraform Apply

on:
push:
branches:
- main

jobs:
terraform:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.1.7

- name: Terraform Init
run: terraform init
working-directory: ./infra

- name: Terraform Apply
run: terraform apply -auto-approve
working-directory: ./infra
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TF_VAR_db_username: ${{ secrets.TF_VAR_DB_USERNAME }}
TF_VAR_db_password: ${{ secrets.TF_VAR_DB_PASSWORD }}
29 changes: 29 additions & 0 deletions .github/workflows/terraform-validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Terraform Validate

on:
push:

jobs:
terraform:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.1.7

- name: Terraform Format Check
run: terraform fmt -check -recursive
working-directory: ./infra

- name: Terraform Init
run: terraform init
working-directory: ./infra

- name: Terraform Validate
run: terraform validate
working-directory: ./infra
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Files
.DS_Store
*.tfvars

# Folders
.idea/*
58 changes: 58 additions & 0 deletions infra/db.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
provider "aws" {
region = "eu-west-2"
}

resource "aws_db_instance" "db" {
allocated_storage = 20 # Minimum required storage in GB
storage_type = "gp2" # General Purpose SSD
engine = "postgres" # Specifies the database engine as PostgreSQL
engine_version = "16.4" # PostgreSQL version 16.4
instance_class = "db.t3.micro" # Smallest instance type available
db_name = "getstronger" # Name of your database
username = var.db_username # Master username
password = var.db_password # Master password
parameter_group_name = "default.postgres16" # Parameter group for PostgreSQL 16
skip_final_snapshot = true # Skips the final snapshot on deletion

# VPC & Subnet group settings
db_subnet_group_name = aws_db_subnet_group.default.name
publicly_accessible = false # Set to true if you need public access

# Security group settings
vpc_security_group_ids = [aws_security_group.default.id]
}

# Optional: Create a DB subnet group if you don't have one already
resource "aws_db_subnet_group" "default" {
name = "my-db-subnet-group"
subnet_ids = ["subnet-0977de5206e697577", "subnet-040d4c7a3aaa9a63d", "subnet-0cf0e0b715c1ec540"] # Replace with your subnet IDs

tags = {
Name = "My DB subnet group"
}
}

# Optional: Create a security group if you don't have one already
resource "aws_security_group" "default" {
name = "my-db-security-group"
description = "Allow DB access"
vpc_id = "vpc-016eba058ed193190" # Replace with your VPC ID

ingress {
from_port = 5432 # PostgreSQL default port
to_port = 5432
protocol = "tcp"
cidr_blocks = ["10.0.0.0/16"] # Adjust this range as needed
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

tags = {
Name = "My DB security group"
}
}
10 changes: 10 additions & 0 deletions infra/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
variable "db_username" {
description = "The username for the RDS instance"
type = string
}

variable "db_password" {
description = "The password for the RDS instance"
type = string
sensitive = true
}