From Zero to Team Development: Building Your Own Cloud Container Playground

Want a cloud playground that's perfect for both solo hacking and team collaboration? Let's build one together - no local Docker needed, just pure cloud-powered creativity. What We're Building Your own cloud container environment (AWS/GCP/Azure) SSH access from anywhere Persistent storage for your work Team collaboration features Part 1: Basic Infrastructure Setup Project Structure cloud-container/ ├── main.tf ├── variables.tf ├── outputs.tf ├── providers.tf ├── versions.tf ├── terraform.tfvars ├── scripts/ │ └── setup-container.sh └── modules/ ├── aws/ │ ├── main.tf │ ├── variables.tf │ └── outputs.tf ├── gcp/ │ ├── main.tf │ ├── variables.tf │ └── outputs.tf └── azure/ ├── main.tf ├── variables.tf └── outputs.tf Core Files versions.tf - Define provider versions terraform { required_version = ">= 1.0.0" required_providers { aws = { source = "hashicorp/aws" version = "~> 5.0" } google = { source = "hashicorp/google" version = "~> 5.0" } azurerm = { source = "hashicorp/azurerm" version = "~> 3.0" } } } variables.tf - Configuration variables variable "cloud_provider" { description = "Pick your cloud (aws/gcp/azure)" type = string default = "aws" } variable "project_name" { description = "Name your playground" type = string default = "dev-playground" } variable "region" { description = "Where in the world?" type = map(string) default = { aws = "us-west-2" gcp = "us-central1" azure = "eastus" } } providers.tf - Cloud provider configurations provider "aws" { region = var.region["aws"] } provider "google" { project = "your-project-id" # Change this region = var.region["gcp"] } provider "azurerm" { features {} } main.tf - Main configuration module "aws_container" { source = "./modules/aws" count = var.cloud_provider == "aws" ? 1 : 0 project_name = var.project_name region = var.region["aws"] } module "gcp_container" { source = "./modules/gcp" count = var.cloud_provider == "gcp" ? 1 : 0 project_name = var.project_name region = var.region["gcp"] } module "azure_container" { source = "./modules/azure" count = var.cloud_provider == "azure" ? 1 : 0 project_name = var.project_name region = var.region["azure"] } Part 2: Cloud Provider Modules AWS Module (modules/aws/main.tf) resource "aws_security_group" "dev_container" { name = "${var.project_name}-security-group" description = "Security group for our playground" ingress { from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } ingress { from_port = 3000 to_port = 3000 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] } } # EBS volume for persistent storage resource "aws_ebs_volume" "dev_storage" { availability_zone = aws_instance.dev_container.availability_zone size = 20 type = "gp2" tags = { Name = "${var.project_name}-storage" } } resource "aws_instance" "dev_container" { ami = "ami-0735c191cf914754d" # Ubuntu 22.04 instance_type = "t2.micro" key_name = "your-key-pair-name" # Change this security_groups = [aws_security_group.dev_container.name] user_data = file("${path.root}/scripts/setup-container.sh") tags = { Name = var.project_name } } resource "aws_volume_attachment" "dev_storage_att" { device_name = "/dev/sdh" volume_id = aws_ebs_volume.dev_storage.id instance_id = aws_instance.dev_container.id } resource "aws_eip" "dev_container" { instance = aws_instance.dev_container.id } GCP Module (modules/gcp/main.tf) resource "google_compute_firewall" "dev_container" { name = "${var.project_name}-firewall" network = "default" allow { protocol = "tcp" ports = ["22", "3000"] } source_ranges = ["0.0.0.0/0"] } # Persistent disk resource "google_compute_disk" "dev_storage" { name = "${var.project_name}-disk" type = "pd-standard" zone = "${var.region}-a" size = 20 } resource "google_compute_instance" "dev_container" { name = var.project_name machine_type = "e2-micro" zone = "${var.region}-a" boot_disk { initialize_params { image = "ubuntu-os-cloud/ubuntu-2204-lts" } } network_interface { network = "default" access_config {} } metadata_startup_script = file("${path.root}/scripts/setup-container.sh") } resource "google_compute_attached_disk" "dev_storage" { disk = google_compute_disk.dev_storage.id instance = google_compute_instance.dev_container.id } Azure

Jan 28, 2025 - 17:47
 0
From Zero to Team Development: Building Your Own Cloud Container Playground

Want a cloud playground that's perfect for both solo hacking and team collaboration? Let's build one together - no local Docker needed, just pure cloud-powered creativity.

What We're Building

  • Your own cloud container environment (AWS/GCP/Azure)
  • SSH access from anywhere
  • Persistent storage for your work
  • Team collaboration features

Part 1: Basic Infrastructure Setup

Project Structure

cloud-container/
├── main.tf
├── variables.tf
├── outputs.tf
├── providers.tf
├── versions.tf
├── terraform.tfvars
├── scripts/
│   └── setup-container.sh
└── modules/
    ├── aws/
    │   ├── main.tf
    │   ├── variables.tf
    │   └── outputs.tf
    ├── gcp/
    │   ├── main.tf
    │   ├── variables.tf
    │   └── outputs.tf
    └── azure/
        ├── main.tf
        ├── variables.tf
        └── outputs.tf

Core Files

  1. versions.tf - Define provider versions
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
    google = {
      source  = "hashicorp/google"
      version = "~> 5.0"
    }
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 3.0"
    }
  }
}
  1. variables.tf - Configuration variables
variable "cloud_provider" {
  description = "Pick your cloud (aws/gcp/azure)"
  type        = string
  default     = "aws"
}

variable "project_name" {
  description = "Name your playground"
  type        = string
  default     = "dev-playground"
}

variable "region" {
  description = "Where in the world?"
  type        = map(string)
  default = {
    aws   = "us-west-2"
    gcp   = "us-central1"
    azure = "eastus"
  }
}
  1. providers.tf - Cloud provider configurations
provider "aws" {
  region = var.region["aws"]
}

provider "google" {
  project = "your-project-id"  # Change this
  region  = var.region["gcp"]
}

provider "azurerm" {
  features {}
}
  1. main.tf - Main configuration
module "aws_container" {
  source  = "./modules/aws"
  count   = var.cloud_provider == "aws" ? 1 : 0

  project_name = var.project_name
  region       = var.region["aws"]
}

module "gcp_container" {
  source  = "./modules/gcp"
  count   = var.cloud_provider == "gcp" ? 1 : 0

  project_name = var.project_name
  region       = var.region["gcp"]
}

module "azure_container" {
  source  = "./modules/azure"
  count   = var.cloud_provider == "azure" ? 1 : 0

  project_name = var.project_name
  region       = var.region["azure"]
}

Part 2: Cloud Provider Modules

AWS Module (modules/aws/main.tf)

resource "aws_security_group" "dev_container" {
  name        = "${var.project_name}-security-group"
  description = "Security group for our playground"

  ingress {
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  ingress {
    from_port   = 3000
    to_port     = 3000
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

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

# EBS volume for persistent storage
resource "aws_ebs_volume" "dev_storage" {
  availability_zone = aws_instance.dev_container.availability_zone
  size             = 20
  type             = "gp2"

  tags = {
    Name = "${var.project_name}-storage"
  }
}

resource "aws_instance" "dev_container" {
  ami           = "ami-0735c191cf914754d"  # Ubuntu 22.04
  instance_type = "t2.micro"
  key_name      = "your-key-pair-name"     # Change this

  security_groups = [aws_security_group.dev_container.name]
  user_data      = file("${path.root}/scripts/setup-container.sh")

  tags = {
    Name = var.project_name
  }
}

resource "aws_volume_attachment" "dev_storage_att" {
  device_name = "/dev/sdh"
  volume_id   = aws_ebs_volume.dev_storage.id
  instance_id = aws_instance.dev_container.id
}

resource "aws_eip" "dev_container" {
  instance = aws_instance.dev_container.id
}

GCP Module (modules/gcp/main.tf)

resource "google_compute_firewall" "dev_container" {
  name    = "${var.project_name}-firewall"
  network = "default"

  allow {
    protocol = "tcp"
    ports    = ["22", "3000"]
  }

  source_ranges = ["0.0.0.0/0"]
}

# Persistent disk
resource "google_compute_disk" "dev_storage" {
  name = "${var.project_name}-disk"
  type = "pd-standard"
  zone = "${var.region}-a"
  size = 20
}

resource "google_compute_instance" "dev_container" {
  name         = var.project_name
  machine_type = "e2-micro"
  zone         = "${var.region}-a"

  boot_disk {
    initialize_params {
      image = "ubuntu-os-cloud/ubuntu-2204-lts"
    }
  }

  network_interface {
    network = "default"
    access_config {}
  }

  metadata_startup_script = file("${path.root}/scripts/setup-container.sh")
}

resource "google_compute_attached_disk" "dev_storage" {
  disk     = google_compute_disk.dev_storage.id
  instance = google_compute_instance.dev_container.id
}

Azure Module (modules/azure/main.tf)

[Previous Azure module code with managed disk configuration]

Part 3: Enhanced Container Setup

The Ultimate Setup Script (scripts/setup-container.sh)

#!/bin/bash

# System updates and utilities
apt-get update
apt-get install -y docker.io git nfs-common

# Start Docker
systemctl start docker
systemctl enable docker

# Create shared workspace with proper permissions
mkdir -p /home/ubuntu/shared_workspace
chmod 775 /home/ubuntu/shared_workspace

# Create developer group
groupadd developers
usermod -aG developers ubuntu

# Set up shared workspace ownership
chown -R ubuntu:developers /home/ubuntu/shared_workspace

# Create SSH key management directory
mkdir -p /home/ubuntu/.ssh/authorized_keys.d
chmod 755 /home/ubuntu/.ssh/authorized_keys.d

# Set up SSH key aggregation
cat > /home/ubuntu/.ssh/authorized_keys_script.sh <<'EOF'
#!/bin/bash
cat /home/ubuntu/.ssh/authorized_keys.d/* > /home/ubuntu/.ssh/authorized_keys
chmod 600 /home/ubuntu/.ssh/authorized_keys
EOF

chmod +x /home/ubuntu/.ssh/authorized_keys_script.sh
(crontab -l 2>/dev/null; echo "*/5 * * * * /home/ubuntu/.ssh/authorized_keys_script.sh") | crontab -

# Run development container with persistent storage
docker run -d \
  --name dev-environment \
  --restart unless-stopped \
  -p 3000:3000 \
  -p 8080:8080 \
  -p 5432:5432 \
  -v /home/ubuntu/shared_workspace:/workspace \
  -v dev_dependencies:/usr/local/lib \
  -v dev_config:/etc/dev \
  node:16

# Install common development tools
docker exec dev-environment bash -c '
  apt-get update && \
  apt-get install -y git curl postgresql sqlite3 python3 python3-pip'

# Create welcome message
cat > /home/ubuntu/shared_workspace/README.md <<EOF
# Welcome to the Shared Development Environment!

## Quick Start
1. Your work directory is /workspace inside the container
2. Development server runs on port 3000
3. Add your SSH key to /home/ubuntu/.ssh/authorized_keys.d/
4. Docker container name is 'dev-environment'

## Useful Commands
- Enter container: docker exec -it dev-environment bash
- View logs: docker logs dev-environment
- Check disk usage: df -h /workspace

## Team Guidelines
1. Keep your work in your own directory
2. Use git for version control
3. Clean up temporary files
4. Update the team when installing new tools

Happy coding!