DevOps help for Cloud Platform Engineers
  • Welcome!
  • Quick Start Guide
  • About Me
  • CV
  • Contribute
  • 🧠DevOps & SRE Foundations
    • DevOps Overview
      • Engineering Fundamentals
      • Implementing DevOps Strategy
      • DevOps Readiness Assessment
      • Lifecycle Management
      • The 12 Factor App
      • Design for Self Healing
      • Incident Management Best Practices (2025)
    • SRE Fundamentals
      • Toil Reduction
      • System Simplicity
      • Real-world Scenarios
        • AWS VM Log Monitoring API
    • Agile Development
      • Team Agreements
        • Definition of Done
        • Definition of Ready
        • Team Manifesto
        • Working Agreement
    • Industry Scenarios
      • Finance and Banking
      • Public Sector (UK/EU)
      • Energy Sector Edge Computing
  • 🛠️DevOps Practices
    • Platform Engineering
    • FinOps
    • Observability
      • Modern Practices
  • 🚀Modern DevOps Practices
    • Infrastructure Testing
    • Modern Development
    • Database DevOps
  • 🛠️Infrastructure as Code (IaC)
    • Terraform
      • Cloud Integrations - Provider-specific implementations
        • Azure Scenarios
          • Azure Authetication
            • Service Principal
            • Service Principal in block
            • Service Principal in env
        • AWS Scenarios
          • AWS Authentication
        • GCP Scenarios
          • GCP Authentication
      • Testing and Validation
        • Unit Testing
        • Integration Testing
        • End-to-End Testing
        • Terratest Guide
      • Best Practices
        • State Management
        • Security
        • Code Organization
        • Performance
      • Tools & Utilities - Enhancing the Terraform workflow
        • Terraform Docs
        • TFLint
        • Checkov
        • Terrascan
      • CI/CD Integration - Automating infrastructure deployment
        • GitHub Actions
        • Azure Pipelines
        • GitLab CI
    • Bicep
      • Getting Started - First steps with Bicep [BEGINNER]
      • Template Specs
      • Best Practices - Guidelines for effective Bicep implementations
      • Modules - Building reusable components [INTERMEDIATE]
      • Examples - Sample implementations for common scenarios
      • Advanced Features
      • CI/CD Integration - Automating Bicep deployments
        • GitHub Actions
        • Azure Pipelines
  • 💰Cost Management & FinOps
    • Cloud Cost Optimization
  • 🐳Containers & Orchestration
    • Containerization Overview
      • Docker
        • Dockerfile Best Practices
        • Docker Compose
      • Kubernetes
        • CLI Tools - Essential command-line utilities
          • Kubectl
          • Kubens
          • Kubectx
        • Core Concepts
        • Components
        • Best Practices
          • Pod Security
          • Security Monitoring
          • Resource Limits
        • Advanced Features - Beyond the basics [ADVANCED]
          • Service Mesh
            • Istio
            • Linkerd
          • Ingress Controllers
            • NGINX
            • Traefik
            • Kong
            • Gloo Edge
            • Contour
        • Tips
          • Status in Pods
          • Resource handling
          • Pod Troubleshooting Commands
        • Enterprise Architecture
        • Health Management
        • Security & Compliance
        • Virtual Clusters
      • OpenShift
  • Service Mesh & Networking
    • Service Mesh Implementation
  • Architecture Patterns
    • Data Mesh
    • Multi-Cloud Networking
    • Disaster Recovery
    • Chaos Engineering
  • Edge Computing
    • Implementation Guide
      • Serverless Edge
      • IoT Edge Patterns
      • Real-Time Processing
      • Edge AI/ML
      • Security Hardening
      • Observability Patterns
      • Network Optimization
      • Storage Patterns
  • 🚀CI/CD & Release Management
    • Continuous Integration
    • Continuous Delivery
      • Deployment Strategies
      • Secrets Management
      • Blue-Green Deployments
      • Deployment Metrics
      • Progressive Delivery
      • Release Management for DevOps/SRE (2025)
  • CI/CD Platforms
    • Tekton
      • Build and Push Container Images
      • Tekton on NixOS Setup
    • Flagger
    • Azure DevOps
      • Pipelines
        • Stages
        • Jobs
        • Steps
        • Templates - Reusable pipeline components
        • Extends
        • Service Connections - External service authentication
        • Best Practices for 2025
        • Agents and Runners
        • Third-Party Integrations
        • Azure DevOps CLI
      • Boards & Work Items
    • GitHub Actions
      • GitHub SecOps: DevSecOps Pipeline
    • GitLab
      • GitLab Runner
  • GitOps
    • GitOps Overview
      • Modern GitOps Practices
      • GitOps Patterns for Multi-Cloud (2025)
      • Flux
        • Progressive Delivery
        • Use GitOps with Flux, GitHub and AKS
  • Source Control
    • Source Control Overview
      • Git Branching Strategies
      • Component Versioning
      • Kubernetes Manifest Versioning
      • GitLab
      • Creating a Fork
      • Naming Branches
      • Pull Requests
      • Integrating LLMs into Source Control Workflows
  • ☁️Cloud Platforms
    • Cloud Strategy
      • AWS to Azure
      • Azure to AWS
      • GCP to Azure
      • AWS to GCP
      • GCP to AWS
    • Landing Zones in Public Clouds
      • AWS Landing Zone
      • GCP Landing Zone
      • Azure Landing Zones
    • Azure
      • Best Practices
        • Azure Best Practices Overview
        • Azure Architecture Best Practices
        • Azure Naming Standards
        • Azure Tags
        • Azure Security Best Practices
      • Services
        • Azure Active Directory (AAD)
        • Azure Monitor
        • Azure Key Vault
        • Azure Service Bus
        • Azure DNS
        • Azure App Service
        • Azure Batch
        • Azure Machine Learning
        • Azure OpenAI Service
        • Azure Cognitive Services
        • Azure Kubernetes Service (AKS)
        • Azure Databricks
        • Azure SQL Database
      • Monitoring
      • Administration Tools - Platform management interfaces
        • Azure PowerShell
        • Azure CLI
      • Tips & Tricks
    • AWS
      • Authentication
      • Best Practices
      • Tips & Tricks
      • Services
        • AWS IAM (Identity and Access Management)
        • Amazon CloudWatch
        • Amazon SNS (Simple Notification Service)
        • Amazon SQS (Simple Queue Service)
        • Amazon Route 53
        • AWS Elastic Beanstalk
        • AWS Batch
        • Amazon SageMaker
        • Amazon Bedrock
        • Amazon Comprehend
    • Google Cloud
      • Services
        • Cloud CDN
        • Cloud DNS
        • Cloud Load Balancing
        • Google Kubernetes Engine (GKE)
        • Cloud Run
        • Artifact Registry
        • Compute Engine
        • Cloud Functions
        • App Engine
        • Cloud Storage
        • Persistent Disk
        • Filestore
        • Cloud SQL
        • Cloud Spanner
        • Firestore
        • Bigtable
        • BigQuery
        • VPC (Virtual Private Cloud)
  • 🔐Security & Compliance
    • DevSecOps Overview
      • DevSecOps Pipeline Security
      • DevSecOps
        • Real-life Examples
        • Scanning & Protection - Automated security tooling
          • Dependency Scanning
          • Credential Scanning
          • Container Security Scanning
          • Static Code Analysis
            • Best Practices
            • Tool Integration Guide
            • Pipeline Configuration
        • CI/CD Security
        • Secrets Rotation
      • Supply Chain Security
        • SLSA Framework
        • Binary Authorization
        • Artifact Signing
      • Security Best Practices
        • Threat Modeling
        • Kubernetes Security
      • SecOps
      • Zero Trust Model
      • Cloud Compliance
        • ISO/IEC 27001:2022
        • ISO 22301:2019
        • PCI DSS
        • CSA STAR
      • Security Frameworks
      • SIEM and SOAR
  • Security Architecture
    • Zero Trust Implementation
      • Identity Management
      • Network Security
      • Access Control
  • 🔍Observability & Monitoring
    • Observability Fundamentals
  • 🧪Testing Strategies
    • Testing Overview
      • Modern Testing Approaches
      • End-to-End Testing
      • Unit Testing
      • Performance Testing
        • Load Testing
      • Fault Injection Testing
      • Integration Testing
      • Smoke Testing
  • 🤖AI Integration
    • AIops Overview
      • Workflow Automation
      • Predictive Analytics
      • Code Quality
  • 🧠AI & LLM Integration
    • Overview
      • Claude
        • Installation Guide
        • Project Guides
        • MCP Server Setup
        • LLM Comparison
      • Ollama
        • Installation Guide
        • Configuration
        • Models and Fine-tuning
        • DevOps Usage
        • Docker Setup
        • GPU Setup
        • Open WebUI
      • Copilot
        • Installation Guide
        • VS Code Integration
        • CLI Usage
      • Gemini
        • Installation Guides - Platform-specific setup
          • Linux Installation
          • WSL Installation
          • NixOS Installation
        • Gemini 2.5 Features
        • Roles and Agents
        • NotebookML Guide
        • Cloud Infrastructure Deployment
        • Summary
  • 💻Development Environment
    • DevOps Tools
      • Pulumi
      • Operating Systems - Development platforms
        • NixOS
          • Install NixOS: PC, Mac, WSL
          • Nix Language Deep Dive
          • Nix Language Fundamentals
            • Nix Functions and Techniques
            • Building Packages with Nix
            • NixOS Configuration Patterns
            • Flakes: The Future of Nix
          • NixOS Generators: Azure & QEMU
        • WSL2
          • Distributions
          • Terminal Setup
      • Editor Environments
      • CLI Tools
        • Azure CLI
        • PowerShell
        • Linux Commands
          • SSH - Secure Shell)
            • SSH Config
            • SSH Port Forwarding
        • Linux Fundametals
        • Cloud init
          • Cloud init examples
        • YAML Tools
          • How to create a k8s yaml file - How to create YAML config
          • YQ the tool
  • 📚Programming Languages
    • Python
    • Go
    • JavaScript/TypeScript
    • Java
    • Rust
  • Platform Engineering
    • Implementation Guide
  • FinOps
    • Implementation Guide
  • AIOps
    • LLMOps Guide
  • Should Learn
    • Should Learn
    • Linux
      • Commands
      • OS
      • Services
    • Terraform
    • Getting Started - Installation and initial setup [BEGINNER]
    • Cloud Integrations
    • Testing and Validation - Ensuring infrastructure quality
      • Unit Testing
      • Integration Testing
      • End-to-End Testing
      • Terratest Guide
    • Best Practices - Production-ready implementation strategies
      • State Management
      • Security
      • Code Organization
      • Performance
    • Tools & Utilities
    • CI/CD Integration
    • Bicep
    • Kubernetes
      • kubectl
    • Ansible
    • Puppet
    • Java
    • Rust
    • Azure CLI
  • 📖Documentation Best Practices
    • Documentation Strategy
      • Project Documentation
      • Release Notes
      • Static Sites
      • Documentation Templates
      • Real-World Examples
  • 📋Reference Materials
    • Glossary
    • Tool Comparison
    • Tool Decision Guides
    • Recommended Reading
    • Troubleshooting Guide
    • Development Setup
Powered by GitBook
On this page
  • ECS Fargate with Application Load Balancer
  • Multi-Account AWS Organization
  • Secure VPC with Transit Gateway
  • EKS Cluster with Node Groups
  • Aurora Serverless v2 Database
  • CloudFront with S3 Origin
  • Best Practices
  • 1. Resource Tagging Strategy
  • 2. IAM Role Strategy
  • 3. Security Groups
  • Testing
  • Integration Tests with Terratest
Edit on GitHub
  1. Infrastructure as Code (IaC)
  2. Terraform
  3. Cloud Integrations - Provider-specific implementations

AWS Scenarios

This guide provides practical deployment scenarios for AWS using Terraform, incorporating modern best practices and patterns for 2025.

ECS Fargate with Application Load Balancer

A production-ready ECS Fargate deployment with ALB:

module "ecs_cluster" {
  source = "./modules/ecs-cluster"

  name = "production"
  capacity_providers = ["FARGATE", "FARGATE_SPOT"]
  
  default_capacity_provider_strategy = [
    {
      capacity_provider = "FARGATE"
      weight = 60
      base = 1
    },
    {
      capacity_provider = "FARGATE_SPOT"
      weight = 40
    }
  ]

  container_insights = true
}

module "ecs_service" {
  source = "./modules/ecs-service"

  name = "api-service"
  cluster_id = module.ecs_cluster.id
  
  task_definition = {
    cpu = 1024
    memory = 2048
    container_definitions = [
      {
        name = "api"
        image = "${var.ecr_repository_url}:latest"
        cpu = 512
        memory = 1024
        essential = true
        portMappings = [
          {
            containerPort = 8080
            protocol = "tcp"
          }
        ]
        environment = [
          {
            name = "ENV"
            value = "production"
          }
        ]
        logConfiguration = {
          logDriver = "awslogs"
          options = {
            awslogs-group = "/ecs/api-service"
            awslogs-region = var.aws_region
            awslogs-stream-prefix = "api"
          }
        }
      }
    ]
  }

  networking = {
    subnets = var.private_subnet_ids
    security_groups = [aws_security_group.ecs_tasks.id]
    assign_public_ip = false
  }

  load_balancer = {
    target_group_arn = module.alb.target_group_arns[0]
    container_name = "api"
    container_port = 8080
  }

  auto_scaling = {
    min_capacity = 2
    max_capacity = 10
    cpu_threshold = 75
    memory_threshold = 75
  }

  enable_execute_command = true
}

Multi-Account AWS Organization

Setting up a secure multi-account AWS organization:

module "organization" {
  source = "./modules/aws-organization"

  feature_set = "ALL"
  aws_service_access_principals = [
    "cloudtrail.amazonaws.com",
    "config.amazonaws.com",
    "sso.amazonaws.com"
  ]

  enabled_policy_types = [
    "SERVICE_CONTROL_POLICY",
    "TAG_POLICY"
  ]

  organizational_units = {
    infrastructure = {
      name = "Infrastructure"
      accounts = ["networking", "security"]
    }
    workloads = {
      name = "Workloads"
      accounts = ["dev", "staging", "prod"]
    }
    platform = {
      name = "Platform"
      accounts = ["logging", "monitoring", "backup"]
    }
  }

  accounts = {
    networking = {
      email = "aws-networking@example.com"
      name  = "Networking Account"
    }
    security = {
      email = "aws-security@example.com"
      name  = "Security Account"
    }
    // ... other accounts
  }

  service_control_policies = {
    deny_root_user = {
      name = "DenyRootUser"
      description = "Deny root user access"
      policy = jsonencode({
        Version = "2012-10-17"
        Statement = [
          {
            Sid = "DenyRootUser"
            Effect = "Deny"
            Action = "*"
            Resource = "*"
            Condition = {
              StringLike = {
                "aws:PrincipalArn": [
                  "arn:aws:iam::*:root"
                ]
              }
            }
          }
        ]
      })
    }
  }
}

Secure VPC with Transit Gateway

Deploy a secure VPC architecture with Transit Gateway:

module "transit_gateway" {
  source = "./modules/transit-gateway"

  name = "main-tgw"
  description = "Main Transit Gateway"
  
  amazon_side_asn = 64512
  
  enable_auto_accept_shared_attachments = true
  enable_default_route_table_association = false
  enable_default_route_table_propagation = false
  
  tags = local.common_tags
}

module "vpc" {
  source = "./modules/vpc"
  
  for_each = {
    prod = {
      cidr = "10.0.0.0/16"
      azs = ["us-west-2a", "us-west-2b", "us-west-2c"]
    }
    staging = {
      cidr = "10.1.0.0/16"
      azs = ["us-west-2a", "us-west-2b"]
    }
  }

  name = "${each.key}-vpc"
  cidr = each.value.cidr
  azs  = each.value.azs
  
  private_subnets = [for i, az in each.value.azs : cidrsubnet(each.value.cidr, 8, i)]
  public_subnets  = [for i, az in each.value.azs : cidrsubnet(each.value.cidr, 8, i + length(each.value.azs))]
  
  enable_nat_gateway = true
  single_nat_gateway = each.key == "staging"
  
  enable_vpn_gateway = false
  
  enable_transit_gateway_attachment = true
  transit_gateway_id = module.transit_gateway.id
  
  tags = merge(local.common_tags, {
    Environment = each.key
  })
}

EKS Cluster with Node Groups

Deploy a production-ready EKS cluster:

module "eks" {
  source = "./modules/eks"

  cluster_name = "prod-eks"
  cluster_version = "1.28"

  vpc_config = {
    subnet_ids = var.private_subnet_ids
    endpoint_private_access = true
    endpoint_public_access  = true
    public_access_cidrs    = ["ADMIN_IP/32"]
  }

  cluster_addons = {
    coredns = {
      most_recent = true
    }
    kube-proxy = {
      most_recent = true
    }
    vpc-cni = {
      most_recent = true
    }
    aws-ebs-csi-driver = {
      most_recent = true
    }
  }

  node_groups = {
    system = {
      desired_size = 2
      min_size     = 2
      max_size     = 4

      instance_types = ["m6i.large"]
      capacity_type  = "ON_DEMAND"
      
      labels = {
        role = "system"
      }
      
      taints = [
        {
          key    = "dedicated"
          value  = "system"
          effect = "NO_SCHEDULE"
        }
      ]
    }
    
    application = {
      desired_size = 3
      min_size     = 3
      max_size     = 10

      instance_types = ["m6i.xlarge"]
      capacity_type  = "SPOT"
      
      labels = {
        role = "application"
      }
    }
  }

  aws_auth_roles = [
    {
      rolearn  = "arn:aws:iam::66666666666:role/role1"
      username = "role1"
      groups   = ["system:masters"]
    },
  ]

  aws_auth_users = [
    {
      userarn  = "arn:aws:iam::66666666666:user/user1"
      username = "user1"
      groups   = ["system:masters"]
    },
  ]

  tags = local.common_tags
}

Aurora Serverless v2 Database

Deploy a highly available Aurora Serverless v2 cluster:

module "aurora_serverless_v2" {
  source = "./modules/aurora-serverless-v2"

  cluster_name = "prod-aurora"
  engine      = "aurora-postgresql"
  engine_version = "14.6"
  
  database_name = "application"
  master_username = "admin"
  
  vpc_config = {
    vpc_id = var.vpc_id
    subnet_ids = var.database_subnet_ids
    allowed_security_group_ids = var.application_security_group_ids
  }

  serverless_config = {
    min_capacity = 0.5
    max_capacity = 16
  }

  backup_config = {
    retention_period = 30
    preferred_window = "03:00-04:00"
  }

  monitoring_config = {
    enhanced_monitoring_interval = 30
    enable_performance_insights = true
    performance_insights_retention = 7
  }

  scaling_config = {
    auto_pause = true
    min_capacity = 0.5
    max_capacity = 16
    seconds_until_auto_pause = 300
    timeout_action = "ForceApplyCapacityChange"
  }

  tags = local.common_tags
}

CloudFront with S3 Origin

Deploy a secure CloudFront distribution with S3:

module "static_website" {
  source = "./modules/static-website"

  domain_name = "example.com"
  environment = "production"

  origin_config = {
    s3_bucket_name = "example-static-content"
    
    origin_access_identity = {
      comment = "Access identity for example.com static content"
    }
  }

  cdn_config = {
    price_class = "PriceClass_All"
    
    custom_error_responses = [
      {
        error_code = 404
        response_code = 200
        response_page_path = "/index.html"
      }
    ]
    
    cache_policy = {
      min_ttl = 0
      default_ttl = 3600
      max_ttl = 86400
      
      cookies = {
        forward = "none"
      }
      
      headers = [
        "Origin",
        "Access-Control-Request-Headers",
        "Access-Control-Request-Method"
      ]
      
      query_strings = {
        forward = "none"
      }
    }
  }

  security_config = {
    waf_web_acl_id = var.waf_web_acl_id
    ssl_certificate_arn = var.acm_certificate_arn
    minimum_protocol_version = "TLSv1.2_2021"
  }

  tags = local.common_tags
}

Best Practices

1. Resource Tagging Strategy

locals {
  mandatory_tags = {
    Environment  = var.environment
    Project      = var.project_name
    Owner        = var.team_email
    CostCenter   = var.cost_center
    ManagedBy    = "terraform"
  }
  
  resource_tags = merge(local.mandatory_tags, var.additional_tags)
}

resource "aws_resourcegroups_group" "project" {
  name = "project-resources"

  resource_query {
    query = jsonencode({
      ResourceTypeFilters = ["AWS::AllSupported"]
      TagFilters = [
        {
          Key = "Project"
          Values = [var.project_name]
        }
      ]
    })
  }
}

2. IAM Role Strategy

module "iam_roles" {
  source = "./modules/iam-roles"

  environment = var.environment
  
  custom_roles = {
    application = {
      trusted_services = ["ec2.amazonaws.com"]
      custom_policies = [
        {
          name = "ApplicationS3Access"
          policy = jsonencode({
            Version = "2012-10-17"
            Statement = [
              {
                Effect = "Allow"
                Action = [
                  "s3:GetObject",
                  "s3:ListBucket"
                ]
                Resource = [
                  "arn:aws:s3:::${var.application_bucket}",
                  "arn:aws:s3:::${var.application_bucket}/*"
                ]
              }
            ]
          })
        }
      ]
      managed_policy_arns = [
        "arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess",
        "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
      ]
    }
  }
}

3. Security Groups

module "security_groups" {
  source = "./modules/security-groups"

  vpc_id = var.vpc_id
  
  groups = {
    web = {
      name = "web-tier"
      description = "Security group for web tier"
      ingress_rules = [
        {
          from_port = 443
          to_port = 443
          protocol = "tcp"
          cidr_blocks = ["0.0.0.0/0"]
          description = "HTTPS from anywhere"
        }
      ]
    }
    app = {
      name = "app-tier"
      description = "Security group for application tier"
      ingress_rules = [
        {
          from_port = 8080
          to_port = 8080
          protocol = "tcp"
          source_security_group_id = "web"
          description = "Access from web tier"
        }
      ]
    }
    db = {
      name = "db-tier"
      description = "Security group for database tier"
      ingress_rules = [
        {
          from_port = 5432
          to_port = 5432
          protocol = "tcp"
          source_security_group_id = "app"
          description = "PostgreSQL access from app tier"
        }
      ]
    }
  }
}

Testing

Integration Tests with Terratest

package test

import (
    "testing"
    "github.com/gruntwork-io/terratest/modules/aws"
    "github.com/gruntwork-io/terratest/modules/terraform"
    "github.com/stretchr/testify/assert"
)

func TestECSDeployment(t *testing.T) {
    t.Parallel()

    terraformOptions := &terraform.Options{
        TerraformDir: "../examples/ecs-service",
        
        Vars: map[string]interface{}{
            "environment": "test",
            "region": "us-west-2",
        },
        
        EnvVars: map[string]string{
            "AWS_DEFAULT_REGION": "us-west-2",
        },
    }
    
    defer terraform.Destroy(t, terraformOptions)
    terraform.InitAndApply(t, terraformOptions)
    
    // Verify ECS Cluster exists
    clusterName := terraform.Output(t, terraformOptions, "cluster_name")
    cluster := aws.GetEcsCluster(t, "us-west-2", clusterName)
    assert.Equal(t, "ACTIVE", *cluster.Status)
    
    // Verify ECS Service is running
    serviceName := terraform.Output(t, terraformOptions, "service_name")
    service := aws.GetEcsService(t, "us-west-2", clusterName, serviceName)
    assert.Equal(t, "ACTIVE", *service.Status)
}
PreviousService Principal in envNextAWS Authentication

Last updated 16 days ago

🛠️