Skip to content

anhkhoa93/devops-assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DevOps Technical Assessment

Solutions for a DevOps technical assessment covering three key areas:

  • Load balancer implementation in Go
  • System metrics exporter
  • Infrastructure as Code with Terraform

Structure

.
├── algorithm/              # Round-robin load balancer
├── golang-node-exporter/   # Prometheus-compatible metrics exporter
├── terraform-gcp-vm/       # GCP VM provisioning module
├── environments/           # Environment-specific configurations
└── .github/workflows/      # CI/CD pipelines

Components

1. Load Balancer (algorithm/)

Round-robin load balancer with health checking. Automatically manages backend servers and routes traffic only to healthy instances.

Features:

  • Round-robin distribution
  • Health check monitoring
  • Dynamic backend management
  • Status endpoint for monitoring

Quick start:

cd algorithm
go mod download
go run cmd/loadbalancer/main.go

Access at http://localhost:8080
Status at http://localhost:8080/status

Testing:

go test ./...

2. Node Exporter (golang-node-exporter/)

Lightweight metrics exporter for Prometheus. Collects CPU, memory, and network stats.

Metrics exposed:

  • CPU usage per core
  • Memory usage
  • Network bytes sent/received

Quick start:

cd golang-node-exporter
go mod download
go build
./node-exporter

Metrics at http://localhost:8080/metrics

Configuration:

./node-exporter -port=9100 -collection-period=10s

Testing:

go test ./...

3. Terraform GCP Module (terraform-gcp-vm/)

Terraform module for provisioning GCP VM instances with nginx.

Architecture:

  • Backend component: Creates GCS bucket for state storage
  • VM module: Provisions compute instances

Prerequisites:

  • Terraform >= 1.0
  • GCP project with billing enabled
  • Service account with required permissions

Setup:

# Create service account
gcloud iam service-accounts create terraform --display-name="Terraform SA"

# Generate key
gcloud iam service-accounts keys create terraform-key.json \
  --iam-account=terraform@YOUR-PROJECT-ID.iam.gserviceaccount.com

# Grant permissions
gcloud projects add-iam-policy-binding YOUR-PROJECT-ID \
  --member="serviceAccount:terraform@YOUR-PROJECT-ID.iam.gserviceaccount.com" \
  --role="roles/storage.admin"

gcloud projects add-iam-policy-binding YOUR-PROJECT-ID \
  --member="serviceAccount:terraform@YOUR-PROJECT-ID.iam.gserviceaccount.com" \
  --role="roles/compute.admin"

Usage:

# Backend setup
cd terraform-gcp-vm/backend
terraform init
terraform apply -var-file="../../environments/dev.tfvars"

# VM deployment
cd ../modules/gcp_vm
terraform init
terraform apply -var-file="../../../environments/dev.tfvars"

Cleanup:

# Destroy in reverse order
cd terraform-gcp-vm/modules/gcp_vm
terraform destroy

cd ../../backend
terraform destroy

CI/CD Pipelines

Automated workflows for testing and deployment.

Workflows

golang-ci.yml

  • Runs on push/PR to main and develop
  • Tests both Go projects
  • Runs linting
  • Generates coverage reports

terraform-validate.yml

  • Runs on PRs touching Terraform files
  • Validates syntax and formatting
  • Runs tflint for best practices

deploy-dev.yml

  • Triggers on push to develop branch
  • Plans infrastructure changes
  • Manual approval required for apply

deploy-prod.yml

  • Triggers on push to main or version tags
  • Requires production environment approval
  • Uses larger instance sizes

Required Secrets

Configure in GitHub Settings > Secrets:

Development:

  • DEV_GCP_PROJECT_ID - GCP project ID for dev
  • DEV_GCP_SA_KEY - Service account JSON key for dev

Production:

  • PROD_GCP_PROJECT_ID - GCP project ID for prod
  • PROD_GCP_SA_KEY - Service account JSON key for prod

Branching Strategy

  • main - Production releases
  • develop - Development branch
  • Feature branches - PRs to develop

Environment Configuration

Environment-specific settings in environments/:

  • dev.tfvars - Development configuration
  • prod.tfvars - Production configuration

Local Development

Install dependencies:

# Algorithm
cd algorithm && go mod download

# Node exporter
cd golang-node-exporter && go mod download

Run tests:

# Run all tests
go test ./...

# With coverage
go test -cover ./...

# With race detection
go test -race ./...

Format code:

go fmt ./...

Validate Terraform:

cd terraform-gcp-vm
terraform fmt -recursive
terraform validate

Notes

  • All sensitive data is gitignored
  • Service account keys should never be committed
  • Terraform state is stored remotely in GCS
  • Backend uses local state to avoid circular dependency

Requirements Met

  • Clean, readable code
  • Comprehensive testing
  • Best practices for Go and Terraform
  • Documentation for all components
  • CI/CD automation
  • Environment separation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors