Solutions for a DevOps technical assessment covering three key areas:
- Load balancer implementation in Go
- System metrics exporter
- Infrastructure as Code with Terraform
.
├── 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
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.goAccess at http://localhost:8080
Status at http://localhost:8080/status
Testing:
go test ./...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-exporterMetrics at http://localhost:8080/metrics
Configuration:
./node-exporter -port=9100 -collection-period=10sTesting:
go test ./...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 destroyAutomated workflows for testing and deployment.
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
Configure in GitHub Settings > Secrets:
Development:
DEV_GCP_PROJECT_ID- GCP project ID for devDEV_GCP_SA_KEY- Service account JSON key for dev
Production:
PROD_GCP_PROJECT_ID- GCP project ID for prodPROD_GCP_SA_KEY- Service account JSON key for prod
main- Production releasesdevelop- Development branch- Feature branches - PRs to develop
Environment-specific settings in environments/:
dev.tfvars- Development configurationprod.tfvars- Production configuration
Install dependencies:
# Algorithm
cd algorithm && go mod download
# Node exporter
cd golang-node-exporter && go mod downloadRun 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- 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
- Clean, readable code
- Comprehensive testing
- Best practices for Go and Terraform
- Documentation for all components
- CI/CD automation
- Environment separation