<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Abraham Acha on Medium]]></title>
        <description><![CDATA[Stories by Abraham Acha on Medium]]></description>
        <link>https://medium.com/@ryank5617?source=rss-c57688f2edcd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*keSx7g3Y6-cmXwMjUHAXpA.jpeg</url>
            <title>Stories by Abraham Acha on Medium</title>
            <link>https://medium.com/@ryank5617?source=rss-c57688f2edcd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 15:57:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ryank5617/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[End to End CI CD Pipeline with Terraform, Docker, ECS Blue Green Deployment and AWS CodePipeline]]></title>
            <link>https://medium.com/@ryank5617/end-to-end-ci-cd-pipeline-with-terraform-docker-ecs-blue-green-deployment-and-aws-codepipeline-8d0419a3f869?source=rss-c57688f2edcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d0419a3f869</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws-codedeploy]]></category>
            <category><![CDATA[aws-codebuild]]></category>
            <category><![CDATA[devsecops]]></category>
            <category><![CDATA[aws-codepipeline]]></category>
            <dc:creator><![CDATA[Abraham Acha]]></dc:creator>
            <pubDate>Thu, 25 Dec 2025 23:23:39 GMT</pubDate>
            <atom:updated>2025-12-25T23:23:39.005Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qfHJy52iMB-scPvbbyhJ6A.jpeg" /></figure><h3>Introduction</h3><p>In this project, I implemented a complete end to end CI CD pipeline on AWS using <strong>Terraform as the only provisioning tool</strong>.<br>All infrastructure was created in a single run using terraform apply.</p><p>The application deployed is a <strong>Swiggy clone</strong>, containerized with Docker and deployed to <strong>Amazon ECS on EC2</strong> using a <strong>Blue Green deployment strategy</strong> powered by <strong>AWS CodeDeploy</strong>.</p><p>Unlike a traditional ECS Blue Green setup, this pipeline introduces <strong>AWS CodePipeline</strong> to manage the full lifecycle<br>from source retrieval, build, image creation, artifact generation, and finally deployment to ECS.</p><h3>High Level Architecture</h3><p>The solution consists of the following components</p><ul><li>Terraform for infrastructure provisioning</li><li>AWS CodePipeline for CI CD orchestration</li><li>AWS CodeBuild for Docker build and testing</li><li>AWS CodeDeploy for ECS Blue Green deployments</li><li>Amazon ECS (EC2 launch type)</li><li>Application Load Balancer with Blue and Green target groups</li><li>AWS SSM Parameter Store for secrets</li><li>AWS S3 to Store created artifacts from the build stage</li><li>Docker Hub as the image registry</li><li>SonarQube for static code analysis</li></ul><p>All components were provisioned together using Terraform.</p><h3>Terraform Project Structure</h3><pre>infrastructure/<br>├── main.tf<br>├── variables.tf<br>├── terraform.tfvars<br>├── modules/<br>│   ├── vpc/<br>│   ├── iam/<br>│   ├── alb/<br>│   ├── ecs/<br>│   ├── codedeploy/<br>│   ├── codebuild/<br>│   └── codepipeline/<br>│   └── ssm-secrets/<br>│   └── sonarqube/<br>│   └── s3/</pre><p>Each AWS service is encapsulated as a Terraform module to keep the setup clean and reusable.</p><h3>S3 Artifact Storage</h3><p>Amazon S3 is used as the <strong>central artifact store</strong> for the pipeline.</p><p>Artifacts generated in the build stage include</p><ul><li>imagedefinitions.json</li><li>taskdef.json</li><li>appspec.yaml</li></ul><p>These artifacts are uploaded to S3 by CodePipeline and consumed by CodeDeploy during the deploy stage.</p><h3>Terraform Code Placeholder</h3><pre># S3 ARTIFACT BUCKET CODE <br>resource &quot;random_id&quot; &quot;bucket_suffix&quot; {<br>  byte_length = 4<br>}<br><br>resource &quot;aws_s3_bucket&quot; &quot;artifacts&quot; {<br>  bucket = &quot;${var.project_name}-artifacts-${random_id.bucket_suffix.hex}&quot;<br>}<br><br>resource &quot;aws_s3_bucket_versioning&quot; &quot;artifacts&quot; {<br>  bucket = aws_s3_bucket.artifacts.id<br>  <br>  versioning_configuration {<br>    status = &quot;Enabled&quot;<br>  }<br>}</pre><h3>Networking and Load Balancer Provisioning</h3><p>Terraform provisions the VPC, subnets, security groups, and Application Load Balancer required for ECS Blue Green deployments.</p><h3>Terraform Code Placeholder</h3><pre># modules/vpc/main.tf<br>resource &quot;aws_vpc&quot; &quot;swiggy-clone-vpc&quot; {<br>  cidr_block = var.vpc_cidr<br>  enable_dns_hostnames = var.enable_dns_hostnames<br>  enable_dns_support = var.enable_dns_support<br><br>  tags = {<br>    Name = &quot;${var.project_name}-vpc&quot;<br>  }<br>}<br><br>resource &quot;aws_internet_gateway&quot; &quot;igw&quot; {<br>  vpc_id = aws_vpc.swiggy-clone-vpc.id<br><br>  tags = {<br>    Name = &quot;${var.project_name}-igw&quot;<br>  }<br>}<br><br>resource &quot;aws_subnet&quot; &quot;public&quot; {<br>  for_each = var.public_subnets<br><br>  vpc_id                  = aws_vpc.swiggy-clone-vpc.id<br>  cidr_block              = each.value.cidr_block<br>  availability_zone       = each.value.availability_zone<br>  map_public_ip_on_launch = each.value.map_public_ip<br><br>  tags = {<br>    Name = &quot;${var.project_name}-${each.key}&quot;<br>    Type = &quot;public&quot;<br>  }<br>}<br><br>resource &quot;aws_subnet&quot; &quot;private&quot; {<br>  for_each = var.private_subnets<br><br>  vpc_id                  = aws_vpc.swiggy-clone-vpc.id<br>  cidr_block              = each.value.cidr_block<br>  availability_zone       = each.value.availability_zone<br>  map_public_ip_on_launch = false<br><br>  tags = {<br>    Name = &quot;${var.project_name}-${each.key}&quot;<br>    Type = &quot;private&quot;<br>  }<br>}<br><br>resource &quot;aws_eip&quot; &quot;nat&quot; {<br>  for_each = var.enable_nat_gateway ? (var.single_nat_gateway ? { for k in [element(keys(var.public_subnets), 0)] : &quot;single&quot; =&gt; k } : { for k, v in var.public_subnets : k =&gt; k }) : {}<br><br>  domain = &quot;vpc&quot;<br><br>  tags = {<br>    Name = &quot;${var.project_name}-nat-eip-${each.key}&quot;<br>  }<br><br>  depends_on = [aws_internet_gateway.igw]<br>}<br><br># Create NAT Gateways (using public subnet keys)<br>resource &quot;aws_nat_gateway&quot; &quot;nat&quot; {<br>  for_each = var.enable_nat_gateway ? (var.single_nat_gateway ? { for k in [element(keys(var.public_subnets), 0)] : &quot;single&quot; =&gt; k } : { for k, v in var.public_subnets : k =&gt; k }) : {}<br><br>  allocation_id = aws_eip.nat[each.key].id<br>  subnet_id     = aws_subnet.public[each.value].id<br><br>  tags = {<br>    Name = &quot;${var.project_name}-nat-${each.key}&quot;<br>  }<br><br>  depends_on = [aws_internet_gateway.igw]<br>}<br><br># Create a local map to link private subnets to NAT gateways<br>locals {<br>  # Map private subnet keys to their corresponding public subnet keys<br>  # Assumes: &quot;private_1&quot; maps to &quot;public_1&quot;, &quot;private_2&quot; maps to &quot;public_2&quot;, etc.<br>  private_to_nat_map = var.single_nat_gateway ? {<br>    for k in keys(var.private_subnets) : k =&gt; &quot;single&quot;<br>  } : {<br>    for k in keys(var.private_subnets) : k =&gt; replace(k, &quot;private&quot;, &quot;public&quot;)<br>  }<br>}<br><br>resource &quot;aws_route_table&quot; &quot;public&quot; {<br>  vpc_id = aws_vpc.swiggy-clone-vpc.id<br><br>  route {<br>    cidr_block = &quot;0.0.0.0/0&quot;<br>    gateway_id = aws_internet_gateway.igw.id<br>  }<br><br>  tags = {<br>    Name = &quot;${var.project_name}-public-rt&quot;<br>  }<br>}<br><br>resource &quot;aws_route_table_association&quot; &quot;public&quot; {<br>  for_each = aws_subnet.public<br><br>  subnet_id      = each.value.id<br>  route_table_id = aws_route_table.public.id<br>}<br><br><br># Private Route Tables<br>resource &quot;aws_route_table&quot; &quot;private&quot; {<br>  for_each = var.enable_nat_gateway ? (var.single_nat_gateway ? { &quot;single&quot; = &quot;single&quot; } : { for k, v in var.private_subnets : k =&gt; k }) : { &quot;default&quot; = &quot;default&quot; }<br><br>  vpc_id = aws_vpc.swiggy-clone-vpc.id<br><br>  dynamic &quot;route&quot; {<br>    for_each = var.enable_nat_gateway ? [1] : []<br>    content {<br>      cidr_block     = &quot;0.0.0.0/0&quot;<br>      nat_gateway_id = var.single_nat_gateway ? aws_nat_gateway.nat[&quot;single&quot;].id : aws_nat_gateway.nat[local.private_to_nat_map[each.key]].id<br>    }<br>  }<br><br>  tags = {<br>    Name = &quot;${var.project_name}-private-rt-${each.key}&quot;<br>  }<br>}<br><br>resource &quot;aws_route_table_association&quot; &quot;private&quot; {<br>  for_each = aws_subnet.private<br><br>  subnet_id      = each.value.id<br>  route_table_id = var.single_nat_gateway ? aws_route_table.private[&quot;single&quot;].id : aws_route_table.private[each.key].id<br>}</pre><p>The ALB includes two target groups</p><ul><li>Blue target group</li><li>Green target group</li></ul><p>Traffic shifting between them is controlled by CodeDeploy.</p><h3>ECS Cluster and Service</h3><p>An ECS cluster running on EC2 was created, backed by an Auto Scaling Group.</p><p>The ECS service is configured to work with CodeDeploy instead of direct service updates.</p><h3>Terraform Code Placeholder</h3><pre># ECS CLUSTER CODE <br>resource &quot;aws_ecs_cluster&quot; &quot;this&quot; {<br>  name = &quot;${var.project_name}-cluster&quot;<br><br>  setting {<br>    name  = &quot;containerInsights&quot;<br>    value = &quot;enabled&quot;<br>  }<br>}<br><br># AUTOSCALING GROUP<br># Data source for ECS optimized AMI<br>data &quot;aws_ami&quot; &quot;ecs_optimized&quot; {<br>  most_recent = true<br>  owners      = [&quot;amazon&quot;]<br><br>  filter {<br>    name   = &quot;name&quot;<br>    values = [&quot;amzn2-ami-ecs-hvm-*-x86_64-ebs&quot;]<br>  }<br><br>  filter {<br>    name   = &quot;virtualization-type&quot;<br>    values = [&quot;hvm&quot;]<br>  }<br>}<br><br># Security Group for ECS Instances<br>resource &quot;aws_security_group&quot; &quot;ecs_instances&quot; {<br>  name        = &quot;${var.project_name}-ecs-instances-sg&quot;<br>  description = &quot;Security group for ECS container instances&quot;<br>  vpc_id      = var.vpc_id<br><br>  ingress {<br>    description     = &quot;Allow traffic from ALB&quot;<br>    from_port       = 0<br>    to_port         = 65535<br>    protocol        = &quot;tcp&quot;<br>    security_groups = [var.alb_security_group_id]<br>  }<br><br>  ingress {<br>    description = &quot;SSH access&quot;<br>    from_port   = 22<br>    to_port     = 22<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  egress {<br>    description = &quot;Allow all outbound traffic&quot;<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  tags = {<br>    Name = &quot;${var.project_name}-ecs-instances-sg&quot;<br>  }<br>}<br><br>resource &quot;aws_launch_template&quot; &quot;ecs&quot; {<br>  name_prefix   = &quot;${var.project_name}-ecs-&quot;<br>  image_id      = data.aws_ami.ecs_optimized.id<br>  instance_type = &quot;t2.medium&quot;<br>  key_name      = var.key_pair_name != &quot;&quot; ? var.key_pair_name : null<br>  <br>  iam_instance_profile {<br>    name = var.ecs_instance_profile_name<br>  }<br>  <br>  vpc_security_group_ids = [aws_security_group.ecs_instances.id]<br>  <br>  user_data = base64encode(&lt;&lt;-EOF<br>              #!/bin/bash<br>              echo ECS_CLUSTER=${aws_ecs_cluster.this.name} &gt;&gt; /etc/ecs/ecs.config<br>              EOF<br>  )<br>  <br>  tag_specifications {<br>    resource_type = &quot;instance&quot;<br>    tags = {<br>      Name = &quot;${var.project_name}-ecs-instance&quot;<br>    }<br>  }<br>}<br><br>resource &quot;aws_autoscaling_group&quot; &quot;ecs&quot; {<br>  name                = &quot;${var.project_name}-ecs-asg&quot;<br>  desired_capacity    = 2<br>  max_size            = 3<br>  min_size            = 1<br>  vpc_zone_identifier = var.private_subnet_ids<br>  target_group_arns   = [var.target_group_arn]<br>  health_check_type   = &quot;ELB&quot;<br>  health_check_grace_period = 300<br>  <br>  launch_template {<br>    id      = aws_launch_template.ecs.id<br>    version = &quot;$Latest&quot;<br>  }<br>  <br>  tag {<br>    key                 = &quot;Name&quot;<br>    value               = &quot;${var.project_name}-ecs-instance&quot;<br>    propagate_at_launch = true<br>  }<br>  <br>  tag {<br>    key                 = &quot;AmazonECSManaged&quot;<br>    value               = true<br>    propagate_at_launch = true<br>  }<br>}<br># CloudWatch Log Group<br>resource &quot;aws_cloudwatch_log_group&quot; &quot;app&quot; {<br>  name              = &quot;/ecs/${var.project_name}&quot;<br>  retention_in_days = 7<br><br>  tags = {<br>    Name = &quot;${var.project_name}-${var.app_name}-logs&quot;<br>  }<br>}<br><br>resource &quot;aws_ecs_task_definition&quot; &quot;this&quot; {<br>  family                   = var.project_name<br>  network_mode             = &quot;bridge&quot;<br>  requires_compatibilities = [&quot;EC2&quot;]<br>  cpu                      = &quot;256&quot;<br>  memory                   = &quot;512&quot;<br>  execution_role_arn       = var.ecs_task_execution_role_arn<br><br>  container_definitions = jsonencode([<br>    {<br>      name      = var.project_name<br>      image     = &quot;${var.image}:latest&quot;<br>       cpu       = 256<br>        memory    = 512<br>      essential = true<br><br>      portMappings = [<br>        {<br>          containerPort = var.container_port<br>          hostPort      = 0<br>          protocol      = &quot;tcp&quot;<br>        }<br>      ]<br>      logConfiguration = {<br>      logDriver = &quot;awslogs&quot;<br>      options = {<br>        &quot;awslogs-group&quot;         = aws_cloudwatch_log_group.app.name<br>        &quot;awslogs-region&quot;        = var.aws_region<br>        &quot;awslogs-stream-prefix&quot; = &quot;ecs&quot;<br>      }<br>    }<br>    }<br>  ])<br>  tags = {<br>    Name = &quot;${var.project_name}-${var.app_name}-task&quot;<br>  }<br>}</pre><h3>IAM Roles and Permissions</h3><p>IAM roles were created for</p><ul><li>ECS task execution → Defined in the IAM module</li><li>CodeBuild → Attached to the CodeBuild Module</li><li>CodePipeline → Attached to the CodeBuild Module</li><li>CodeDeploy → Attached to the CodeBuild Module</li></ul><p>Permissions were scoped to only what each service requires.</p><h3>Terraform Code Placeholder</h3><pre># INSERT IAM ROLE AND POLICY DEFINITIONS HERE<br># ECS Task Execution Role<br>resource &quot;aws_iam_role&quot; &quot;ecs_task_execution_role&quot; {<br>  name = &quot;${var.project_name}-ecs-task-execution-role&quot;<br>  <br>  assume_role_policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [{<br>      Action = &quot;sts:AssumeRole&quot;<br>      Effect = &quot;Allow&quot;<br>      Principal = {<br>        Service = &quot;ecs-tasks.amazonaws.com&quot;<br>      }<br>    }]<br>  })<br>}<br><br>resource &quot;aws_iam_role_policy_attachment&quot; &quot;ecs_task_execution_role_policy&quot; {<br>  role       = aws_iam_role.ecs_task_execution_role.name<br>  policy_arn = &quot;arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy&quot;<br>}<br><br># ECS Instance Role (for EC2 instances in ECS cluster)<br>resource &quot;aws_iam_role&quot; &quot;ecs_instance_role&quot; {<br>  name = &quot;${var.project_name}-ecs-instance-role&quot;<br>  <br>  assume_role_policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [{<br>      Action = &quot;sts:AssumeRole&quot;<br>      Effect = &quot;Allow&quot;<br>      Principal = {<br>        Service = &quot;ec2.amazonaws.com&quot;<br>      }<br>    }]<br>  })<br>}<br><br>resource &quot;aws_iam_role_policy_attachment&quot; &quot;ecs_instance_role_policy&quot; {<br>  role       = aws_iam_role.ecs_instance_role.name<br>  policy_arn = &quot;arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role&quot;<br>}<br><br>resource &quot;aws_iam_instance_profile&quot; &quot;ecs_instance&quot; {<br>  name = &quot;${var.project_name}-ecs-instance-profile&quot;<br>  role = aws_iam_role.ecs_instance_role.name<br>}<br><br># CodeDeploy Role<br>resource &quot;aws_iam_role&quot; &quot;codedeploy_role&quot; {<br>  name = &quot;${var.project_name}-codedeploy-role&quot;<br>  <br>  assume_role_policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [{<br>      Action = &quot;sts:AssumeRole&quot;<br>      Effect = &quot;Allow&quot;<br>      Principal = {<br>        Service = &quot;codedeploy.amazonaws.com&quot;<br>      }<br>    }]<br>  })<br>}<br><br>resource &quot;aws_iam_role_policy_attachment&quot; &quot;codedeploy_role_policy&quot; {<br>  role       = aws_iam_role.codedeploy_role.name<br>  policy_arn = &quot;arn:aws:iam::aws:policy/AWSCodeDeployRoleForECS&quot;<br>}</pre><h3>CI CD Orchestration with CodePipeline</h3><p>CodePipeline defines three main stages</p><ol><li>Source</li><li>Build</li><li>Deploy</li></ol><p>The source stage pulls the Swiggy clone repository.<br>The build stage triggers CodeBuild.<br>The deploy stage hands off to CodeDeploy for ECS Blue Green deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZS2Rh9qICNVDqzqKMB5kyg.png" /><figcaption>Codepipeline Stages In Action</figcaption></figure><h3>Terraform Code Placeholder</h3><pre># CODEPIPELINE MODULE CODE <br><br>resource &quot;aws_iam_role&quot; &quot;codepipeline&quot; {<br>  name = &quot;${var.project_name}-codepipeline-role&quot;<br><br>  assume_role_policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [{<br>      Effect = &quot;Allow&quot;<br>      Principal = {<br>        Service = &quot;codepipeline.amazonaws.com&quot;<br>      }<br>      Action = &quot;sts:AssumeRole&quot;<br>    }]<br>  })<br>}<br><br>resource &quot;aws_iam_role_policy&quot; &quot;codepipeline_s3&quot; {<br>  name = &quot;codepipeline-s3-policy&quot;<br>  role = aws_iam_role.codepipeline.name<br>  <br>  policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [<br>      {<br>        Effect = &quot;Allow&quot;<br>        Action = [<br>          &quot;s3:GetObject&quot;,<br>          &quot;s3:GetObjectVersion&quot;,<br>          &quot;s3:PutObject&quot;,<br>          &quot;s3:GetBucketLocation&quot;,<br>          &quot;s3:ListBucket&quot;<br>        ]<br>        Resource = [<br>          var.artifact_bucket_arn,<br>          &quot;${var.artifact_bucket_arn}/*&quot;<br>        ]<br>      }<br>    ]<br>  })<br>}<br><br>resource &quot;aws_iam_role_policy&quot; &quot;codepipeline_codebuild&quot; {<br>  name = &quot;codepipeline-codebuild-policy&quot;<br>  role = aws_iam_role.codepipeline.name<br>  <br>  policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [<br>      {<br>        Effect   = &quot;Allow&quot;<br>        Action   = [&quot;codebuild:BatchGetBuilds&quot;, &quot;codebuild:StartBuild&quot;]<br>        Resource = var.codebuild_project_arn<br>      }<br>    ]<br>  })<br>}<br><br>resource &quot;aws_iam_role_policy&quot; &quot;codepipeline_codedeploy&quot; {<br>  name = &quot;codepipeline-codedeploy-policy&quot;<br>  role = aws_iam_role.codepipeline.name<br>  <br>  policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [<br>      {<br>        Effect = &quot;Allow&quot;<br>        Action = [<br>          &quot;codedeploy:CreateDeployment&quot;,<br>          &quot;codedeploy:GetApplication&quot;,<br>          &quot;codedeploy:GetApplicationRevision&quot;,<br>          &quot;codedeploy:GetDeployment&quot;,<br>          &quot;codedeploy:GetDeploymentConfig&quot;,<br>          &quot;codedeploy:RegisterApplicationRevision&quot;<br>        ]<br>        Resource = &quot;*&quot;<br>      }<br>    ]<br>  })<br>}<br><br>resource &quot;aws_iam_role_policy&quot; &quot;codepipeline_ecs&quot; {<br>  name = &quot;codepipeline-ecs-policy&quot;<br>  role = aws_iam_role.codepipeline.name<br>  <br>  policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [<br>      {<br>        Effect   = &quot;Allow&quot;<br>        Action   = &quot;ecs:*&quot;<br>        Resource = &quot;*&quot;<br>      }<br>    ]<br>  })<br>}<br><br>resource &quot;aws_iam_role_policy&quot; &quot;codepipeline_passrole&quot; {<br>  name = &quot;codepipeline-passrole-policy&quot;<br>  role = aws_iam_role.codepipeline.name<br>  <br>  policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [<br>      {<br>        Effect   = &quot;Allow&quot;<br>        Action   = &quot;iam:PassRole&quot;<br>        Resource = &quot;*&quot;<br>      }<br>    ]<br>  })<br>}<br>resource &quot;aws_iam_role_policy&quot; &quot;codepipeline_codestar&quot; {<br>  name = &quot;codepipeline-codestar-policy&quot;<br>  role = aws_iam_role.codepipeline.name<br>  <br>  # Only create if codestar_connection_arn is provided<br>  count = var.codestar_connection_arn != &quot;&quot; &amp;&amp; var.codestar_connection_arn != null ? 1 : 0<br>  <br>  policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [<br>      {<br>        Effect   = &quot;Allow&quot;<br>        Action   = &quot;codestar-connections:UseConnection&quot;<br>        Resource = var.codestar_connection_arn<br>      }<br>    ]<br>  })<br>}<br><br>resource &quot;aws_iam_role_policy_attachment&quot; &quot;codepipeline_admin&quot; {<br>  role       = aws_iam_role.codepipeline.name<br>  policy_arn = &quot;arn:aws:iam::aws:policy/AdministratorAccess&quot;<br>}<br><br><br><br>resource &quot;aws_codepipeline&quot; &quot;this&quot; {<br>  name     = &quot;${var.project_name}-codepipeline&quot;<br>  role_arn = var.role_arn<br><br>   artifact_store {<br>    location = var.artifact_bucket_name<br>    type     = &quot;S3&quot;<br><br>    <br>  }<br><br>  stage {<br>    name = &quot;Source&quot;<br><br>    action {<br>      name             = &quot;Source&quot;<br>      category         = &quot;Source&quot;<br>      owner            = &quot;AWS&quot;<br>      provider         = &quot;CodeStarSourceConnection&quot;<br>      version          = &quot;1&quot;<br>      output_artifacts = [&quot;source_output&quot;]<br><br>      configuration = {<br>        ConnectionArn     = var.codestar_connection_arn<br>        FullRepositoryId  = var.github_repo<br>        BranchName        = var.github_branch<br>      }<br>    }<br>  }<br><br>  stage {<br>    name = &quot;Build&quot;<br><br>    action {<br>      name             = &quot;Build&quot;<br>      category         = &quot;Build&quot;<br>      owner            = &quot;AWS&quot;<br>      provider         = &quot;CodeBuild&quot;<br>      input_artifacts  = [&quot;source_output&quot;]<br>      output_artifacts = [&quot;build_output&quot;]<br>      version          = &quot;1&quot;<br>      configuration = {<br>        ProjectName = var.codebuild_project<br>      }<br>    }<br>  }<br><br>  stage {<br>    name = &quot;Deploy&quot;<br><br>    action {<br>      name            = &quot;Deploy&quot;<br>      category        = &quot;Deploy&quot;<br>      owner           = &quot;AWS&quot;<br>      provider        = &quot;CodeDeployToECS&quot;<br>      input_artifacts = [&quot;build_output&quot;]<br>      version          = &quot;1&quot;<br><br>      configuration = {<br>        ApplicationName     = var.codedeploy_app<br>        DeploymentGroupName = var.codedeploy_group<br>        TaskDefinitionTemplateArtifact = &quot;build_output&quot;<br>        AppSpecTemplateArtifact        = &quot;build_output&quot;<br>     <br>      }<br>    }<br>  }<br>  tags = {<br>    Name = &quot;${var.project_name}-pipeline&quot;<br>  }<br>}</pre><h3>Build and Test with CodeBuild</h3><p>CodeBuild is configured to read the buildspec.yaml file located inside the Swiggy_clone directory.</p><p>Secrets such as Docker credentials and SonarQube token are retrieved securely from <strong>AWS SSM Parameter Store</strong>.</p><h3>buildspec.yaml</h3><p>Responsibilities of the buildspec file include</p><ul><li>Docker Hub authentication</li><li>Docker image build and tagging</li><li>Image push to registry</li><li>Generation of ECS deployment artifacts</li></ul><p>Artifacts generated</p><ul><li>imagedefinitions.json</li><li>taskdef.json</li><li>appsec.yaml</li></ul><h3>Terraform Code Placeholder</h3><pre># CODEBUILD FILE<br>resource &quot;aws_iam_role&quot; &quot;codebuild&quot; {<br>  name = &quot;${var.project_name}-codebuild-role&quot;<br><br>  assume_role_policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [{<br>      Effect = &quot;Allow&quot;<br>      Principal = {<br>        Service = &quot;codebuild.amazonaws.com&quot;<br>      }<br>      Action = &quot;sts:AssumeRole&quot;<br>    }]<br>  })<br>}<br><br>resource &quot;aws_iam_role_policy&quot; &quot;codebuild_policy&quot; {<br>  role = aws_iam_role.codebuild.name<br>  <br>  policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [<br>      {<br>        Effect = &quot;Allow&quot;<br>        Action = [<br>          &quot;logs:CreateLogGroup&quot;,<br>          &quot;logs:CreateLogStream&quot;,<br>          &quot;logs:PutLogEvents&quot;<br>        ]<br>        Resource = &quot;*&quot;<br>      },<br>      {<br>        Effect = &quot;Allow&quot;<br>        Action = [<br>          &quot;s3:GetObject&quot;,<br>          &quot;s3:PutObject&quot;<br>        ]<br>        Resource = &quot;${var.artifact_bucket_arn}/*&quot;<br>      },<br>      {<br>        Effect = &quot;Allow&quot;<br>        Action = [<br>          &quot;ecr:GetAuthorizationToken&quot;,<br>          &quot;ecr:BatchCheckLayerAvailability&quot;,<br>          &quot;ecr:GetDownloadUrlForLayer&quot;,<br>          &quot;ecr:PutImage&quot;,<br>          &quot;ecr:InitiateLayerUpload&quot;,<br>          &quot;ecr:UploadLayerPart&quot;,<br>          &quot;ecr:CompleteLayerUpload&quot;<br>        ]<br>        Resource = &quot;*&quot;<br>      },<br>      {<br>        Effect = &quot;Allow&quot;<br>        Action = [<br>          &quot;ssm:GetParameters&quot;<br>        ]<br>        Resource = &quot;*&quot;<br>      }<br>    ]<br>  })<br>}<br><br>resource &quot;aws_iam_role_policy_attachment&quot; &quot;codebuild_admin&quot; {<br>  role       = aws_iam_role.codebuild.name<br>  policy_arn = &quot;arn:aws:iam::aws:policy/AdministratorAccess&quot;<br>}<br><br><br>resource &quot;aws_codebuild_project&quot; &quot;this&quot; {<br>  name = var.project_name<br>  description   = &quot;Build project for ${var.project_name}&quot;<br>  build_timeout = &quot;30&quot;<br>  service_role  = var.role_arn<br><br>  artifacts {<br>    type = &quot;CODEPIPELINE&quot;<br>  }<br><br>  source {<br>    type      = &quot;CODEPIPELINE&quot;<br>    buildspec = &quot;Swiggy_clone/buildspec.yaml&quot;<br>  }<br><br>  environment {<br>    compute_type = &quot;BUILD_GENERAL1_SMALL&quot;<br>    image        = &quot;aws/codebuild/standard:5.0&quot;<br>    type         = &quot;LINUX_CONTAINER&quot;<br>    image_pull_credentials_type = &quot;CODEBUILD&quot;<br>    privileged_mode             = true<br>  }<br>  logs_config {<br>    cloudwatch_logs {<br>      group_name  = &quot;/aws/codebuild/${var.project_name}&quot;<br>      stream_name = &quot;build&quot;<br>    }<br>  }<br><br>  tags = {<br>    Name = &quot;${var.project_name}-codebuild&quot;<br>  }<br>}</pre><pre># BUILDSPEC.YAML FILE <br>version: 0.2<br><br>env:<br>  parameter-store:<br>    DOCKER_REGISTRY_USERNAME: /cicd/docker-credentials/username<br>    DOCKER_REGISTRY_PASSWORD: /cicd/docker-credentials/password<br>    SONAR_TOKEN: /cicd/sonar/sonar-token<br><br>phases:<br>  install:<br>    runtime-versions:<br>      python: 3.11<br>      <br>  pre_build:<br>    commands:<br>      - cd Swiggy_clone<br>      - echo &quot;Logging in to Docker Hub...&quot;<br>      - echo &quot;$DOCKER_REGISTRY_PASSWORD&quot; | docker login -u &quot;$DOCKER_REGISTRY_USERNAME&quot; --password-stdin<br>      - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c1-7)<br>      - echo &quot;Image tag is $IMAGE_TAG&quot;<br>      <br>  build:<br>    commands:<br>      - echo &quot;Building Docker image for linux/amd64...&quot;<br>      - export IMAGE_TAG=${IMAGE_TAG:-latest}<br>      - export DOCKER_REGISTRY_USERNAME=${DOCKER_REGISTRY_USERNAME:-airfluke}<br>      - docker build --platform linux/amd64 -t $DOCKER_REGISTRY_USERNAME/swiggy-clone:$IMAGE_TAG -t $DOCKER_REGISTRY_USERNAME/swiggy-clone:latest .<br>      - echo &quot;Pushing Docker image...&quot;<br>      - docker push $DOCKER_REGISTRY_USERNAME/swiggy-clone:$IMAGE_TAG<br>      - docker push $DOCKER_REGISTRY_USERNAME/swiggy-clone:latest<br>      <br>  post_build:<br>    commands:<br>      - echo &quot;Build completed on `date`&quot;<br>      - printf &#39;[{&quot;name&quot;:&quot;swiggy-app&quot;,&quot;imageUri&quot;:&quot;%s&quot;}]&#39; $DOCKER_REGISTRY_USERNAME/swiggy-clone:$IMAGE_TAG &gt; imagedefinitions.json<br>      - |<br>        cat &gt; taskdef.json &lt;&lt; EOF<br>        {<br>          &quot;family&quot;: &quot;swiggy&quot;,<br>          &quot;networkMode&quot;: &quot;bridge&quot;,<br>          &quot;requiresCompatibilities&quot;: [&quot;EC2&quot;],<br>          &quot;cpu&quot;: &quot;256&quot;,<br>          &quot;memory&quot;: &quot;512&quot;,<br>          &quot;containerDefinitions&quot;: [<br>            {<br>              &quot;name&quot;: &quot;swiggy&quot;,<br>              &quot;image&quot;: &quot;$DOCKER_REGISTRY_USERNAME/swiggy-clone:$IMAGE_TAG&quot;,<br>              &quot;cpu&quot;: 256,<br>              &quot;memory&quot;: 512,<br>              &quot;essential&quot;: true,<br>              &quot;portMappings&quot;: [<br>                {<br>                  &quot;containerPort&quot;: 3000,<br>                  &quot;hostPort&quot;: 0,<br>                  &quot;protocol&quot;: &quot;tcp&quot;<br>                }<br>              ],<br>              &quot;logConfiguration&quot;: {<br>                &quot;logDriver&quot;: &quot;awslogs&quot;,<br>                &quot;options&quot;: {<br>                  &quot;awslogs-group&quot;: &quot;/ecs/swiggy-app&quot;,<br>                  &quot;awslogs-region&quot;: &quot;ap-northeast-1&quot;,<br>                  &quot;awslogs-stream-prefix&quot;: &quot;ecs&quot;<br>                }<br>              }<br>            }<br>          ]<br>        }<br>        EOF<br>      - cat imagedefinitions.json<br>      - cat taskdef.json<br><br>artifacts:<br>  base-directory: Swiggy_clone<br>  files:<br>    - imagedefinitions.json<br>    - appspec.yaml<br>    - taskdef.json</pre><h3>Secure Secret Management</h3><p>Sensitive values were <strong>not stored in Terraform variables</strong>.</p><p>Instead, AWS SSM Parameter Store was used to store</p><ul><li>Docker registry username</li><li>Docker registry password</li><li>SonarQube token</li></ul><p>CodeBuild retrieves these values at runtime.</p><p>This prevents secrets from leaking into Terraform state files or version control.</p><h3>Blue Green Deployment with CodeDeploy</h3><p>AWS CodeDeploy is responsible for deploying new task sets to ECS.</p><p>The deployment uses the <strong>appspec.yaml</strong> file to define</p><ul><li>ECS service name</li><li>Task definition file</li><li>Load balancer target groups</li><li>Traffic shifting behavior</li></ul><p>CodeDeploy validates the new deployment before shifting traffic and terminating old tasks.</p><h3>Terraform Code Placeholder</h3><pre>#CODEDEPLOY APPLICATION AND DEPLOYMENT GROUP CODE <br>resource &quot;aws_codedeploy_app&quot; &quot;ecs&quot; {<br>  name             = &quot;${var.project_name}-ecs-app&quot;<br>  compute_platform = &quot;ECS&quot;<br>}<br><br>resource &quot;aws_codedeploy_deployment_group&quot; &quot;ecs&quot; {<br>  app_name               = aws_codedeploy_app.ecs.name<br>  deployment_group_name  = &quot;${var.project_name}-ecs-deployment-group&quot;<br>  service_role_arn = var.codedeploy_role_arn<br>  deployment_config_name = &quot;CodeDeployDefault.ECSAllAtOnce&quot;<br><br>    auto_rollback_configuration {<br>    enabled = true<br>    events  = [&quot;DEPLOYMENT_FAILURE&quot;]<br>  }<br>  <br>  blue_green_deployment_config {<br>    deployment_ready_option {<br>      action_on_timeout = &quot;CONTINUE_DEPLOYMENT&quot;<br>    }<br>    <br>    terminate_blue_instances_on_deployment_success {<br>      action                           = &quot;TERMINATE&quot;<br>      termination_wait_time_in_minutes = 5<br>    }<br>  }<br>  <br>  ecs_service {<br>    cluster_name = var.cluster_name<br>    service_name = var.service_name<br>  }<br><br>  load_balancer_info {<br>    target_group_pair_info {<br>      target_group {<br>        name = var.blue_tg_name<br>      }<br>      target_group {<br>        name = var.green_tg_name<br>      }<br><br>      prod_traffic_route {<br>        listener_arns = [var.listener_arn]<br>      }<br>    }<br>  }<br><br>  deployment_style {<br>    deployment_option = &quot;WITH_TRAFFIC_CONTROL&quot;<br>    deployment_type   = &quot;BLUE_GREEN&quot;<br>  }<br>}</pre><h3>Deployment Artifacts</h3><p>The following files play a critical role in deployment</p><h4>appspec.yaml</h4><p>Defines how CodeDeploy deploys the ECS service.</p><h4>buildspec.yaml</h4><p>Controls build, test, image creation, and artifact generation.</p><h4>imagedefinitions.json</h4><p>Maps container names to Docker image URIs.</p><h4>taskdef.json</h4><p>Defines the ECS task definition dynamically with the new image.</p><p>All files are generated or consumed automatically by the pipeline.</p><h3>End to End Execution Flow</h3><ol><li>Terraform provisions all infrastructure</li><li>CodePipeline pulls source code</li><li>CodeBuild builds and pushes Docker image</li><li>SonarQube analysis runs</li><li>Deployment artifacts are generated</li><li>CodeDeploy performs ECS Blue Green deployment</li><li>ALB shifts traffic to the new version</li></ol><p>No manual intervention is required.</p><h3>Conclusion</h3><p>This project demonstrates how to build a <strong>production grade CI CD pipeline</strong> using Terraform and AWS native services.</p><p>Key highlights</p><ul><li>One command infrastructure provisioning</li><li>Secure secret management</li><li>Zero downtime ECS deployments</li><li>Automated Docker image lifecycle</li><li>Integrated quality checks</li></ul><p>The entire system is reproducible, scalable, and aligned with real world DevOps practices.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d0419a3f869" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Implementing ECS Blue/Green Deployments with Terraform and CodeDeploy]]></title>
            <link>https://medium.com/@ryank5617/implementing-ecs-blue-green-deployments-with-terraform-and-codedeploy-74e8f1b4389a?source=rss-c57688f2edcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/74e8f1b4389a</guid>
            <category><![CDATA[devops-practice]]></category>
            <category><![CDATA[blue-green-deployment]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[blue-green-infrastructure]]></category>
            <dc:creator><![CDATA[Abraham Acha]]></dc:creator>
            <pubDate>Tue, 09 Dec 2025 15:07:18 GMT</pubDate>
            <atom:updated>2025-12-09T15:07:18.813Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KhUSh4-uR3G5EtBrHwgpKA.jpeg" /></figure><h3>A Complete, Real-World Walkthrough (With Errors, Fixes, and Terraform Lessons)</h3><blockquote>A technical walkthrough of how I built a full ECS Blue/Green deployment pipeline using Terraform, CodeDeploy, ALB, EC2 capacity providers, and an automated Python deployment trigger.</blockquote><h3>📌 Short Description</h3><p>A practical, educational guide showing how I built an AWS ECS Blue/Green deployment using Terraform + CodeDeploy. The article explains the full workflow, the errors I encountered (and their fixes), and the specific Terraform patterns needed to make CodeDeploy and ECS work together without drift or race conditions. Includes placeholders for screenshots of the ECS cluster, Load Balancer, running app, CodeDeploy deployment group, and successful deployment.</p><h3>🟦 SITUATION — Why I Needed a Blue/Green Deployment</h3><p>I wanted a <strong>zero-downtime deployment flow</strong> for a containerized app running on Amazon ECS (EC2 launch type). Traditional rolling deployments worked, but Blue/Green offered:</p><ul><li>instant rollback</li><li>predictable cutovers</li><li>separate target groups for revision isolation</li><li>health-checked traffic shifting</li><li>easy visualization in CodeDeploy</li></ul><p>On top of that, I wanted the <strong>entire setup to be infrastructure-as-code</strong>, reproducible end-to-end using Terraform.</p><p>But building ECS Blue/Green with Terraform isn’t straightforward. The AWS APIs have ordering dependencies, CodeDeploy mutates resources during deployment, and eventual consistency causes frustrating race conditions.</p><p>This article documents <strong>exactly how I solved all of that</strong>, using real screenshots and real error messages.</p><blockquote><em>✔️ </em>Goal: A stable Terraform project that deploys ECS → ALB → CodeDeploy Blue/Green → automatic traffic shifting.</blockquote><h3>🧩 TASK — What I Needed to Deliver</h3><p>To achieve full ECS Blue/Green automation, my Terraform needed to:</p><h3>1. Build the core infrastructure</h3><ul><li>VPC, subnets, routing, security groups</li><li>Application Load Balancer</li><li><strong>Two target groups:</strong> blue (production) and green (test)</li><li>ECS cluster with EC2 capacity provider</li><li>ECS task definition</li><li>ECS service configured for <strong>CODE_DEPLOY</strong></li></ul><h3>2. Configure CodeDeploy for ECS</h3><ul><li>CodeDeploy application</li><li>CodeDeploy deployment group with:</li><li>→blue TG + green TG</li><li>→listener switch</li><li>→hooks and termination settings</li></ul><h3>3. Automate deployments</h3><p>Terraform triggers a Python script that:</p><ul><li>registers a <strong>new ECS task definition</strong></li><li>instructs CodeDeploy to run a Blue/Green deployment</li></ul><h3>4. Prevent Terraform drift</h3><p>CodeDeploy changes ALB listener rules during deployment, so I needed:</p><pre>lifecycle {<br>  ignore_changes = [default_action, load_balancer, task_definition]<br>}</pre><h3>5. Handle AWS eventual consistency</h3><p>Some AWS resources take time before they become visible to other APIs.<br> I used:</p><ul><li>depends_on</li><li>replace_triggered_by</li><li>and a small sleep before Python executes</li></ul><h3>⚙️ ACTION — How I Built It (Full Teaching Walkthrough)</h3><p>Below is the educational, step-by-step breakdown of how this architecture comes together.</p><h3>🧱 1. Provider and Region (Absolutely Critical)</h3><p>One of my early mistakes was region mismatches. Everything must live in <strong>one region</strong>, and Terraform must supply it consistently.</p><pre>provider &quot;aws&quot; {<br>  region = &quot;eu-west-2&quot;<br>}</pre><p>If regions differ, you get errors like:</p><blockquote><em>ClusterNotFoundException: Could not load ECS service information for cluster: main-cluster</em></blockquote><p>or</p><blockquote><em>ApplicationDoesNotExistException: No application found for name: ecs-app</em></blockquote><h3>🌐 2. Application Load Balancer + Blue/Green Target Groups</h3><p>The ALB front-ends the application.<br> The <strong>blue</strong> TG serves production traffic.<br> The <strong>green</strong> TG receives the new version during deployment.</p><pre>resource &quot;aws_lb_target_group&quot; &quot;blue_tg&quot; { ... }</pre><pre>resource &quot;aws_lb_target_group&quot; &quot;green_tg&quot; { ... }</pre><h3>❌ Issue Encountered</h3><p>During a later update Terraform tried deleting a target group:</p><blockquote><em>ResourceInUse: Target group ... is currently in use by a listener or a rule</em></blockquote><h3>✅ Fix</h3><p>Always detach listeners before deleting TGs.</p><h3>🎧 3. ALB Listener (with ignore_changes)</h3><p>CodeDeploy will modify listener rules during deployments, and if Terraform tracks those changes it causes constant drift.</p><pre>resource &quot;aws_lb_listener&quot; &quot;http&quot; {<br>  load_balancer_arn = aws_lb.main.arn<br>  port              = 80<br>  protocol          = &quot;HTTP&quot;</pre><pre>  default_action {<br>    type             = &quot;forward&quot;<br>    target_group_arn = aws_lb_target_group.blue_tg.arn<br>  }</pre><pre>  lifecycle {<br>    ignore_changes = [default_action]  # IMPORTANT<br>  }<br>}</pre><blockquote><em>❗ </em><strong><em>Why ignore_changes?</em></strong><em><br> Because CodeDeploy automatically rewrites listener rules during a Blue/Green deployment.<br> If Terraform tries to “fix” them, you break the deployment flow.</em></blockquote><h3>🧵 4. ECS Cluster + EC2 Capacity Provider</h3><p>Creating the ECS cluster is simple:</p><pre>resource &quot;aws_ecs_cluster&quot; &quot;main&quot; {<br>  name = &quot;main-cluster&quot;<br>}</pre><p>The capacity provider connects the cluster to the ASG.</p><h3>📦 5. ECS Task Definition (Never Use data Lookup Here)</h3><p>I define it directly:</p><pre>resource &quot;aws_ecs_task_definition&quot; &quot;app&quot; {<br>  family                   = &quot;app-task&quot;<br>  network_mode             = &quot;awsvpc&quot;<br>  requires_compatibilities = [&quot;EC2&quot;]<br>  cpu                      = &quot;256&quot;<br>  memory                   = &quot;512&quot;</pre><pre>  container_definitions = jsonencode([...])<br>}</pre><p>This ensures:</p><ul><li>correct ordering</li><li>no “task definition not found” issues</li><li>predictable workflow</li></ul><h3>🛠️ 6. ECS Service (Must Use CODE_DEPLOY Controller)</h3><p>This is where ECS ties into CodeDeploy:</p><pre>resource &quot;aws_ecs_service&quot; &quot;app&quot; {<br>  name            = &quot;app-service&quot;<br>  cluster         = aws_ecs_cluster.main.id<br>  task_definition = aws_ecs_task_definition.app.arn<br>  deployment_controller { type = &quot;CODE_DEPLOY&quot; }</pre><pre>  load_balancer {<br>    target_group_arn = aws_lb_target_group.blue_tg.arn<br>    container_name   = &quot;app&quot;<br>    container_port   = 5000<br>  }</pre><pre>  lifecycle {<br>    ignore_changes = [task_definition, load_balancer]<br>  }</pre><pre>  depends_on = [aws_lb_listener.http]<br>}</pre><h3>❗ Why ignore_changes?</h3><p>Because CodeDeploy will temporarily modify ECS fields during Blue/Green transitions.</p><h3>📦 7. CodeDeploy Application + Deployment Group</h3><h3>Application:</h3><pre>resource &quot;aws_codedeploy_app&quot; &quot;ecs_app&quot; {<br>  name             = &quot;ecs-app&quot;<br>  compute_platform = &quot;ECS&quot;<br>}</pre><h3>Deployment Group:</h3><pre>ecs_service {<br>  cluster_name = aws_ecs_cluster.main.name<br>  service_name = aws_ecs_service.app.name<br>}</pre><p>Using references instead of literal strings avoids huge debugging headaches.</p><h3>🐍 8. Automating Deployments with Python + Terraform</h3><p>Terraform calls:</p><pre>resource &quot;null_resource&quot; &quot;register_task_definition&quot; {<br>  depends_on = [<br>    aws_codedeploy_app.ecs_app,<br>    aws_codedeploy_deployment_group.ecs_dg<br>  ]</pre><pre>  provisioner &quot;local-exec&quot; {<br>    command = &quot;sleep 10 &amp;&amp; python3 register_task_definition.py&quot;<br>  }<br>}</pre><p>And the Python script triggers deployment:</p><pre>codedeploy_client.create_deployment(<br>    applicationName=&quot;ecs-app&quot;,<br>    deploymentGroupName=&quot;ecs-dg&quot;,<br>    revision={ ... }<br>)</pre><h3>❗ Error Encountered</h3><blockquote><em>ApplicationDoesNotExistException: No application found for name: ecs-app</em></blockquote><h3>✅ Fix</h3><p>Add:</p><ul><li>depends_on</li><li>and a <strong>small sleep</strong> (AWS propagation delay)</li></ul><h3>🐛 9. The Real Errors I Encountered (and How I Fixed Them)</h3><h3>Error #1: Account not activated</h3><pre>SubscriptionRequiredException</pre><p>✔️ Fix: verify and activate AWS account.</p><h3>Error #2: ECS Cluster Not Found</h3><pre>ClusterNotFoundException</pre><p>✔️ Fix: region alignment + name references + depends_on.</p><h3>Error #3: CodeDeploy App Not Found</h3><pre>ApplicationDoesNotExistException</pre><p>✔️ Fix: Python executed too early → added sleep + depends_on.</p><h3>Error #4: Target Group Cannot Be Deleted</h3><pre>ResourceInUse</pre><p>✔️ Fix: detach listeners first.</p><h3>🟩 RESULT — What I Achieved</h3><p>By the end of this build:</p><p>✔️ A full Blue/Green infrastructure deployed via Terraform</p><p>✔️ Automatic task definition registration</p><p>✔️ Automatic CodeDeploy traffic shifting</p><p>✔️ Zero-downtime deployments</p><p>✔️ Stable Terraform plans (no drift)</p><p>✔️ A reusable blueprint for future projects</p><p>And best of all:<br> <strong>I can deploy new versions simply by updating the container image and running </strong><strong>terraform apply —auto-approve .</strong></p><h3>🖼️ Screenshots</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xWea9A2u9mP8lSTjpr88Gw.png" /><figcaption><strong>Live ECS Cluster</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OnYMpRNYMhG2AQqf5exS9Q.png" /><figcaption><strong>Application Load Balancer</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mfoTB9DsZkt6x0Kw1ZsSXA.png" /><figcaption><strong>Live App Runnning On Load Balancer</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UUX5hR2adI-axKlKkJVLPg.png" /><figcaption><strong>CodeDeploy Deployment App</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wpF9NnUo-McVCwIbLvihMg.png" /><figcaption><strong>Codedeploy Deployment Group</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5xg-fyS12hYCUneWwxx6bg.png" /><figcaption><strong>Codedeploy Deployment</strong></figcaption></figure><h3>🧠 Final Lessons Learned</h3><ul><li>AWS CodeDeploy will <strong>modify ALB listener rules</strong> → you must use ignore_changes.</li><li>Use Terraform references for <strong>every name and ARN</strong>.</li><li>AWS APIs may not see each other’s resources instantly → sleeps help.</li><li>Blue/Green needs strict <strong>ordering</strong> in Terraform → depends_on is essential.</li><li>Automation requires both IaC and scripting — Terraform + Python pair extremely well.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74e8f1b4389a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Building a Full GitOps CI/CD Pipeline with Jenkins, ArgoCD, Docker, Kubernetes & Monitoring]]></title>
            <link>https://medium.com/@ryank5617/building-a-full-gitops-ci-cd-pipeline-with-jenkins-argocd-docker-kubernetes-monitoring-11bf68afa6af?source=rss-c57688f2edcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/11bf68afa6af</guid>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Abraham Acha]]></dc:creator>
            <pubDate>Thu, 04 Dec 2025 23:56:20 GMT</pubDate>
            <atom:updated>2025-12-04T23:56:20.313Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ti-NGBSGZ8-DEEg0SIOSHQ.png" /></figure><blockquote><em>A real-world walk-through of how I automated build, security, deployment &amp; delivery using GitOps<br> </em>(from local cluster to production workflow concepts).</blockquote><h3>🌍 Why This Project? — The Situation</h3><p>Software teams want automation that keeps going even when humans step away.<br> That was the situation I faced:</p><blockquote>How do I automate code delivery end-to-end, ensure traceability and security,<br> without deploying manually each time?</blockquote><p>So I took on the challenge using:</p><p>✔ GitHub<br> ✔ Jenkins<br> ✔ Docker Hub<br> ✔ ArgoCD<br> ✔ Kubernetes<br> ✔ Trivy<br> ✔ Sonarqube<br> ✔ Prometheus + Grafana<br> ✔ Cert-manager TLS automation</p><p>📌 <em>Below is the pipeline we built from scratch.</em></p><h3>🎯 Objective — The Task</h3><p>We needed to:</p><p>✓ Automate build → container → deploy → observe<br> ✓ Detect vulnerabilities early<br> ✓ Remove manual deployments<br> ✓ Implement GitOps (Git = source of truth)<br> ✓ Give dashboards that prove results<br> ✓ Provide HTTPS-secured Proof Of Work</p><h3>🧩 How We Built It — The Action</h3><p>Follow this as a step-by-step teaching walkthrough.<br> Whenever I say <em>now we …</em>, imagine applying it in your environment.</p><h3>🔧 Step 1 — Jenkins Setup &amp; Credentials</h3><p>We created two Jenkins pipeline jobs:</p><pre>amazon-build-job   → Build + scan + push  <br>argo-build-job     → Update GitOps repo for ArgoCD</pre><p>Inside Jenkins, we secured:</p><p>✔ GitHub tokens<br> ✔ Docker Hub credentials<br> ✔ Sonarqube integration credentials</p><p>📌 <strong>Tip:</strong> Always use Jenkins credentials store — never hardcode secrets.</p><h3>🧪 Step 2 — Source Control Integration</h3><p>Both pipelines pointed to the correct Git branches using Jenkins SCM config.</p><p>This ensures:</p><p>➡ Jenkins reacts to commits<br> ➡ Workspaces remain clean and traceable</p><h3>🧠 Step 3 — Code Quality &amp; Static Analysis</h3><p>We configured Sonarqube for:</p><p>✔ Code smell detection<br> ✔ Bug detection<br> ✔ Quality gates</p><p>Results appeared in Jenkins pipeline logs:</p><blockquote><em>Code must pass quality analysis before build continues.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vUjOp9qbo8p99a6J4o1bzA.png" /></figure><h3>🏗️ Step 4 — Building &amp; Scanning Docker Images</h3><p>We authenticated Jenkins against Docker Hub:</p><pre>docker login -u $DOCKER_USER -p $DOCKER_PASS</pre><p>➡ Build container<br> ➡ Scan vulnerabilities using Trivy<br> ➡ If clean → push to registry</p><p>🎯 Security is automated — zero manual review required.</p><h3>🔁 Step 5 — GitOps Integration: “Automation Magic Moment”</h3><p>Here is the game-changer:</p><p>Once pipeline 1 pushes the Docker image,<br> it automatically triggers pipeline 2.</p><p>That job:</p><p>✔ Clones our GitOps repo<br> ✔ Locates deployment.yaml<br> ✔ Updates image tag to $BUILD_NUMBER<br> ✔ Pushes change back to GitHub</p><p>Meaning:</p><p>✨ Kubernetes is updated simply because Git changed,<br> not because we kubectl apply manually.</p><p>That is GitOps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0PtWJtnb3wIY1-RuAM7uPg.png" /><figcaption>Full Pipeline For Pipeline 1 running</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ocBAf-dCMx-qbOUESMuyVw.png" /><figcaption>Pipeline 2 is automatically ran without external help</figcaption></figure><h3>🚢 Step 6 — Kubernetes &amp; ArgoCD Deployment</h3><p>We installed ArgoCD, logged in, changed admin password, and created an application:</p><p>✔ Repo URL → our GitOps repo<br> ✔ Path → Kubernetes manifests folder<br> ✔ Sync strategy → automatic</p><p>Immediately — <br> our cluster began deploying on its own.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YKZWV3_CY6rhwMyTEEDOMw.png" /></figure><h3>🌐 Step 7 — Exposing Our App via NGINX Ingress</h3><p>We installed ingress-nginx using Helm in a dedicated namespace.</p><p>Then applied ingress in the namespace where the app runs:</p><pre>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: ingress-prod<br>spec:<br>  ingressClassName: nginx<br>  rules:<br>  - host: myapp.example.site<br>    http:<br>      paths:<br>      - path: /<br>        pathType: Prefix<br>        backend:<br>          service:<br>            name: amazon-service<br>            port:<br>              number: 80</pre><h3>🔍 Running Locally?</h3><p>Minikube users run:</p><pre>minikube tunnel</pre><p>→ Your app becomes publicly reachable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zd3_zK3PFNez0ncYB1yS2Q.png" /></figure><h3>🔐 Step 8 (Optional but Powerful) — Auto TLS using Cert-Manager</h3><p>Because Proof-of-Work often requires HTTPS,<br> we used Let’s Encrypt automation.</p><ol><li>Installed cert-manager via Helm</li><li>Added issuer annotation in ingress</li><li>Created Issuer resource (in default namespace):</li></ol><pre>apiVersion: cert-manager.io/v1<br>kind: Issuer<br>metadata:<br>  name: letsencrypt-nginx<br>  namespace: default<br>spec:<br>  acme:<br>    email: you@example.com<br>    server: https://acme-v02.api.letsencrypt.org/directory<br>    privateKeySecretRef:<br>      name: letsencrypt-prod-account-key<br>    solvers:<br>    - http01:<br>        ingress:<br>          class: nginx</pre><p>➡ In minutes, Kubernetes generated SSL certificates automatically.</p><p>📌 Perfect for showcasing a <strong>secure deployment proof</strong>.</p><h3>📊 Step 9 — Cluster Monitoring with Prometheus &amp; Grafana</h3><p>Observability is mandatory in DevOps.</p><p>We installed both using Helm in <strong>separate namespaces</strong>.</p><p>To access dashboards:</p><pre>kubectl port-forward svc/prometheus-server -n prometheus 9090:9090<br>kubectl port-forward svc/grafana -n grafana 3000:3000</pre><p>Inside Grafana:</p><p>✔ Add Prometheus data source<br> ✔ Import dashboard IDs:<br> 3119, 8010, 14623, 14205, 3662</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ke2UinSpRh0BHOND-lBng.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WeT3qEJ5k0YWMi8iFbBDMQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a5YRy-83l44bvmwRYnxlVQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9_vvyBZAGON9e3BswVXGNw.png" /></figure><blockquote><em>Now we can </em><strong><em>prove</em></strong><em> our system is working — visually.</em></blockquote><h3>🏁 The Outcome — The Result</h3><p>We successfully delivered:</p><p>✨ A fully automated CI/CD + GitOps deployment pipeline<br> ✨ Security scanning, quality enforcement, monitoring and TLS<br> ✨ A real demonstration of DevOps maturity principles</p><p>Final flow:</p><pre>Commit → Scan → Build → Push → Update Git → Argo Deploy → Observe</pre><p>Zero manual deployment.</p><h3>🙌 Final Reflection</h3><p>This wasn’t just tooling — <br> it was learning how automation systems cooperate.</p><p>Challenges came from:</p><p>🔹 namespace scoping<br> 🔹 networking behaviour<br> 🔹 credential handoffs<br> 🔹 Git updating manifests</p><p>But solving these is what makes DevOps valuable.</p><p>The outcome?</p><blockquote><em>A system that keeps shipping even when you are away.</em></blockquote><p><a href="https://youtu.be/tIgpjEknAS0">https://youtu.be/tIgpjEknAS0</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11bf68afa6af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Database Backup and Restore from Amazon RDS SQL Server to Amazon S3]]></title>
            <link>https://medium.com/@ryank5617/database-backup-and-restore-from-amazon-rds-sql-server-to-amazon-s3-46660e59d06c?source=rss-c57688f2edcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/46660e59d06c</guid>
            <category><![CDATA[aws-rds]]></category>
            <category><![CDATA[aws-s3]]></category>
            <category><![CDATA[database-administration]]></category>
            <dc:creator><![CDATA[Abraham Acha]]></dc:creator>
            <pubDate>Thu, 20 Nov 2025 00:25:28 GMT</pubDate>
            <atom:updated>2025-11-20T00:25:28.173Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QiQ1znb7vhhV8rF7EqDaqw.png" /></figure><p>A Practical Walkthrough for Real Engineering Workflows</p><p>Backing up a production database and restoring it safely for internal testing is one of the most important tasks in any engineering workflow. In real companies you do not want your developers or data teams experimenting directly on production. Instead you give them a copy. This is exactly what I set out to do in this project using Amazon Web Services.</p><p>In this article I walk you through how I backed up a Microsoft SQL Server database from Amazon RDS into Amazon S3 and then restored the backup into a new database. It is a simple concept but it involves learning many AWS services and putting them together in a clean secure workflow.</p><h3>1. Building the Foundation</h3><p>Creating the RDS Instance in a Private Subnet</p><p>I started by launching an RDS instance using Microsoft SQL Server engine. The instance was placed inside a private subnet. This means it cannot be reached directly from the internet. This is the recommended best practice because databases should never be public facing.</p><h3>2. Secure Access</h3><p>Connecting to the Database without Opening Any Ports</p><p>The next step was figuring out a secure way to access the SQL Server engine. Normally people open RDP ports to log into a Windows EC2 instance and then connect through SQL Server Management Studio. But opening ports is not ideal from a security perspective.</p><p>Instead I used Session Manager through AWS Systems Manager. When using this method you do not open any inbound ports. Only IAM permissions are required which makes the entire setup much safer.</p><p>To prepare for this I created an IAM role called <strong>ec2SessionManager role</strong> that gives the EC2 instance the right to communicate with Systems Manager.</p><h3>3. Provisioning the Windows EC2 Instance</h3><p>Access through Fleet Manager instead of RDP</p><p>Since SQL Server Management Studio only works on Windows, I launched a Windows EC2 instance and attached the ec2SessionManager role during creation.<br> Instead of RDP, I used <strong>Fleet Manager</strong>, which is a feature inside Systems Manager. It allows you to open a secure, browser based remote session into the Windows machine without exposing the instance to the internet.</p><p><strong>Screenshot placeholder: Windows EC2 instance and Fleet Manager access</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yWkBrZRvY4KTIkD83KtJbg.png" /><figcaption>EC2 Config</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dFv6a_SczISVnWHbrkvTGQ.png" /></figure><h3>4. Connecting to SQL Server Management Studio</h3><p>Once inside the Windows instance, I downloaded and installed SQL Server Management Studio.<br> Then I connected to the RDS SQL Server database using the RDS endpoint, my login credentials and the ARN of the database.</p><h3>5. Creating the Database and Dummy Tables</h3><p>With the connection established, I created a new database and multiple tables using SQL scripts.<br> I then seeded the tables with dummy data. This step helps to simulate a real world workload before performing the backup and restore process.</p><p><strong>Screenshot placeholder: SQL code creating tables and inserting data</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*StoUDfEygoAYsTE5gg2BZw.png" /><figcaption>Creating Tables in SQL</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dcB53NUFxfR_fpoOVW3ruQ.png" /></figure><h3>6. Preparing RDS for Backup and Restore</h3><p>Configuring the Option Group</p><p>SQL Server on RDS requires a feature called <strong>SQL Server Backup and Restore</strong>. This is only available when you configure an <strong>Option Group</strong>.</p><p>So I created a new Option Group that matched the same SQL engine and version as my RDS instance. Inside the Option Group I enabled:</p><p><strong>SQLSERVER BACKUP RESTORE</strong></p><p>This option allows the database to interact with an S3 bucket during backup and restore operations.</p><p>Next I created a new IAM role for RDS and attached a policy that gives the role full access to S3. The RDS instance needs this permission so it can write backups to my bucket.</p><p>After setting all this up, I applied the Option Group to the RDS instance.</p><p><strong>Screenshot placeholder: Option Group with Backup and Restore enabled</strong></p><h3>7. Performing the Backup to Amazon S3</h3><p>Now everything was ready.</p><p>Inside SSMS I ran the SQL command that sends the backup to my S3 bucket. The command specifies the bucket name and the database name. Once executed, a .bak file was successfully created in the S3 bucket.</p><p><strong>Screenshot placeholder: SSMS backup query and S3 bucket result</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r5xBFGp1_w4TZHc_S9qHyg.png" /><figcaption>backup query screenshot</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-lAGYHyOc_MiOA_RHReQtA.png" /><figcaption>s3 bucket screenshot</figcaption></figure><h3>8. Restoring from S3 into a New Database</h3><p>The restore process was just as simple.<br> I used a SQL query to restore the .bak file into a new database instance. After the restore completed I performed several queries on the restored database to verify that the data matched the original.</p><p>This final test confirmed the backup integrity and the overall success of the workflow.</p><p><strong>Screenshot placeholder: restore query and restored database</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qlp9w5tEMtk_Xh-hqE5XKA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qLxt6kJtpIe9ZOhC9fCsyA.png" /></figure><h3>9. Why This Workflow Matters</h3><p>This setup allows engineering teams to get fresh copies of production data without ever touching the production environment.<br> It also follows AWS best practices for security:</p><p>No public access<br> No exposed ports<br> IAM based authentication<br> Private subnets<br> Secure backups inside S3</p><p>This replicates what real production companies do when they want to safely give developers an environment to test new features without risk.</p><h3>Conclusion</h3><p>This project connected multiple AWS services together in a real world use case.<br> I worked with RDS private networking, Amazon EC2, IAM roles, Systems Manager, Fleet Manager, Option Groups, SQL Server Management Studio and Amazon S3. All parts came together to produce a complete backup and restore solution.</p><p>If you want to explore this workflow further I can share my SQL scripts or the architectural diagram used in this setup.</p><p>Thank you for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46660e59d06c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Troubleshooting Jenkins SSH Deployments on Windows]]></title>
            <link>https://medium.com/@ryank5617/troubleshooting-jenkins-ssh-deployments-on-windows-12348840268b?source=rss-c57688f2edcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/12348840268b</guid>
            <dc:creator><![CDATA[Abraham Acha]]></dc:creator>
            <pubDate>Sat, 18 Oct 2025 11:35:23 GMT</pubDate>
            <atom:updated>2025-10-18T11:35:23.843Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fPn4sfk6C8hjw-oD5i4tfA.png" /></figure><p>If you’ve ever tried to deploy a build from <strong>Jenkins on Windows</strong> to a <strong>remote Linux server (like AWS EC2)</strong> using SSH, chances are you’ve run into authentication errors like:</p><pre>Auth fail for methods &#39;publickey&#39;</pre><p>or</p><pre>Permissions for private key are too open</pre><p>I recently hit the same issue while setting up a CI/CD pipeline that deployed a Maven-built JAR to a Tomcat server on AWS. After a lot of head-scratching, this is how I finally fixed it — and why it worked. 💡</p><h3>🧩 The Original Problem</h3><p>In my Jenkins pipeline, I used a bat step to copy the file via scp:</p><pre>bat &quot;scp -i ${SSH_KEY} target/ibt-maven-1.0-SNAPSHOTS.jar ubuntu@13.61.34.125:/opt/tomcat/apps/&quot;</pre><p>But Jenkins replaced ${SSH_KEY} with **** to hide secrets in logs.<br> So when the command reached Windows, it became:</p><pre>scp -i **** target/ibt-maven-1.0-SNAPSHOTS.jar ...</pre><p>The result? Jenkins couldn’t find the private key and scp failed with <em>“No such file or directory”</em>.</p><p>This happened because <strong>Groovy interpolates variables before Jenkins runs the command</strong>, and Jenkins masks all sensitive variables by default.</p><h3>⚙️ The Working Solution</h3><p>Here’s the final working stage that deployed successfully to EC2 👇</p><pre>stage(&#39;Deploy to Dev&#39;) {<br>    steps {<br>        withCredentials([sshUserPrivateKey(credentialsId: &#39;aws-ec2-key&#39;, keyFileVariable: &#39;SSH_KEY&#39;)]) {<br>            bat &#39;&#39;&#39;<br>                set &quot;BASH_PATH=C:\\Program Files\\Git\\bin\\bash.exe&quot;<br>                &quot;%BASH_PATH%&quot; -c &quot;scp -o StrictHostKeyChecking=no -i \\&quot;$SSH_KEY\\&quot; target/ibt-maven-1.0-SNAPSHOTS.jar ubuntu@13.61.34.125:/opt/tomcat/apps/&quot;<br>            &#39;&#39;&#39;<br>        }<br>    }<br>}</pre><p>✅ <strong>Result:</strong> Jenkins deployed the JAR from my Windows machine to /opt/tomcat/apps/ on my EC2 instance without errors.</p><h3>🔍 Step-by-Step Breakdown</h3><p>Let’s understand <em>why this works</em> — not just copy and paste it.</p><h3>1️⃣ withCredentials</h3><pre>withCredentials([sshUserPrivateKey(credentialsId: &#39;aws-ec2-key&#39;, keyFileVariable: &#39;SSH_KEY&#39;)])</pre><p>This securely loads your .pem key from Jenkins Credentials and stores it temporarily on disk like:</p><pre>C:\ProgramData\Jenkins\.jenkins\workspace\Airfluke@tmp\secretFiles\&lt;id&gt;\ssh-key-SSH_KEY</pre><p>It then exports the environment variable $SSH_KEY with the path to that temporary file — without showing it in logs.</p><h3>2️⃣ Using Triple Quotes &#39;&#39;&#39;</h3><pre>bat &#39;&#39;&#39;<br>    ...<br>&#39;&#39;&#39;</pre><p>Triple single quotes tell Jenkins <strong>not to interpolate variables</strong> (like ${SSH_KEY}) in Groovy.<br> This means Jenkins passes $SSH_KEY <strong>literally</strong> to Git Bash, where it gets expanded securely.</p><h3>3️⃣ Running through Git Bash</h3><pre>set &quot;BASH_PATH=C:\\Program Files\\Git\\bin\\bash.exe&quot;<br>&quot;%BASH_PATH%&quot; -c &quot;scp ...&quot;</pre><p>We explicitly run commands via <strong>Git Bash</strong>, not PowerShell or CMD.<br> Why? Because scp and chmod behave correctly in a Unix-like shell.<br> The -c flag tells Bash to execute the quoted command.</p><h3>4️⃣ Safe Variable Escaping</h3><pre>-i \\&quot;$SSH_KEY\\&quot;</pre><p>Double-escaping (\\&quot;) ensures:</p><ul><li>Windows doesn’t strip the quotes.</li><li>Bash sees the correct file path even with spaces (e.g., <em>Program Files</em>).</li></ul><p>This made sure the private key path stayed intact all the way through execution.</p><h3>💡 Behind the Scenes</h3><p>Here’s what happens under the hood:</p><ol><li>Jenkins creates a secure temp key file.</li><li>$SSH_KEY points to that file path.</li><li>Git Bash expands $SSH_KEY into the actual .pem path.</li><li>scp connects using the key, copies the JAR to the remote server, and Jenkins completes deployment.</li></ol><h3>🛡️ Why It’s the Safest Approach</h3><p>✅ Keeps your SSH key private (never printed in logs)<br> ✅ Works across Jenkins restarts<br> ✅ Compatible with Linux-based remote hosts<br> ✅ Bypasses Groovy interpolation issues<br> ✅ No permanent key files — Jenkins deletes them automatically after the stage</p><h3>🔄 Bonus: Restart Tomcat Automatically</h3><p>You can even restart Tomcat after deploying:</p><pre>&quot;%BASH_PATH%&quot; -c &quot;scp -o StrictHostKeyChecking=no -i \\&quot;$SSH_KEY\\&quot; target/ibt-maven-1.0-SNAPSHOTS.jar ubuntu@13.61.34.125:/opt/tomcat/apps/ &amp;&amp; ssh -i \\&quot;$SSH_KEY\\&quot; ubuntu@13.61.34.125 &#39;sudo systemctl restart tomcat&#39;&quot;</pre><p>This ensures that every new deployment goes live instantly. 🔥</p><h3>🧠 Key Takeaways</h3><ol><li><strong>Jenkins on Windows</strong> often masks credentials too aggressively.</li><li>Always wrap commands with &#39;&#39;&#39; to prevent Groovy interpolation.</li><li>Run Unix commands via <strong>Git Bash</strong> for Linux-compatible behavior.</li><li>Use withCredentials to safely handle SSH keys.</li></ol><h3>✨ In Summary</h3><p>It wasn’t just about fixing an SCP error — it was about understanding how <strong>Windows, Jenkins, and Git Bash interact</strong> during deployments.</p><p>Once you control how variables are passed and which shell runs them, Jenkins becomes one of the most powerful DevOps tools you’ll ever use. ⚡</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12348840268b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Understanding Maven: The DevOps Engineer’s Reliable Builder]]></title>
            <link>https://medium.com/@ryank5617/understanding-maven-the-devops-engineers-reliable-builder-791977d256f5?source=rss-c57688f2edcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/791977d256f5</guid>
            <dc:creator><![CDATA[Abraham Acha]]></dc:creator>
            <pubDate>Tue, 07 Oct 2025 13:18:55 GMT</pubDate>
            <atom:updated>2025-10-07T13:18:55.177Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C1TzwjLP7tQitz3zdj8Caw.png" /></figure><p>When you hear <strong>Maven</strong>, think <em>organization, structure, and automation.</em></p><p>It’s the quiet helper that takes care of all the messy work involved in building, testing, and packaging Java applications — so that as a DevOps engineer, you can focus on automating the delivery process instead of manually fixing build issues.</p><h3>💡 What Exactly Is Maven?</h3><p>Maven is a <strong>build automation and project management tool</strong> primarily used for Java applications.</p><p>It helps you:</p><ul><li>⚙️ <strong>Compile</strong> and <strong>test</strong> your code</li><li>📦 <strong>Package</strong> it into deployable files (like .jar, .war, or .ear)</li><li>☁️ <strong>Upload</strong> the build to a repository</li><li>🚀 <strong>Deploy</strong> the final build to a server</li></ul><p>In short: it manages everything between <em>writing code</em> and <em>deploying a ready-to-run application</em>.</p><h3>⚙️ The Maven Lifecycle (Phases You’ll Use Most)</h3><p>Each Maven command you run corresponds to a <strong>phase</strong> in its lifecycle:</p><ul><li>🧾 validate: Checks the pom.xml file to make sure everything is correctly configured.</li><li>💻 compile: Converts .java files into .class files that your server or JVM can understand.</li><li>🧪 test: Runs tests stored in the test folder to ensure your code logic works.</li><li>📦 package: Packages the application into a .jar or .war file ready for deployment.</li><li>🧹 clean: Deletes files and folders created during previous builds (usually the target folder).</li><li>☁️ deploy: Uploads your packaged build to a remote repository (like Artifactory).</li><li>🧭 site: Generates site documentation for your application.</li></ul><h3>🧱 Understanding the pom.xml File</h3><p>Every Maven project revolves around a single XML file called <strong>pom.xml</strong> (<em>Project Object Model</em>).<br> Think of it as your project’s <strong>recipe</strong> — it defines what Maven needs to build your application.</p><p>When creating a Maven project from scratch, you’ll be asked for the <strong>GAV parameters</strong>:</p><p>Parameter Meaning Example <strong>Group ID</strong> Your organization or domain in reverse com.ibt.airfluke <strong>Artifact ID</strong> The name of your app’s package Airfluke-app <strong>Version</strong> The version of your app 1.0-SNAPSHOT (for development)</p><blockquote><em>💬 “Snapshot” means the app is still under development. Once ready for production, you can release version numbers like </em><em>1.0.0, </em><em>1.1.0, etc.</em></blockquote><p>A typical project generation command looks like this:</p><pre>mvn -B archetype:generate \<br>  -DgroupId=com.ibt.abrahamacha \<br>  -DartifactId=Airfluke-app \<br>  -Dversion=1.0.0\ -&gt; use this when you want to archetype a release version directly <br>  -DarchetypeArtifactId=maven-archetype-quickstart \<br>  -DarchetypeVersion=1.4</pre><h3>🧩 Maven’s Folder Structure</h3><p>Maven gives your project a <strong>consistent folder structure</strong> right out of the box:</p><pre>src/<br> ├── main/   → main source code<br> └── test/   → test code<br>target/      → compiled code and packaged files<br>pom.xml      → project configuration</pre><p>This uniform structure means every developer or DevOps engineer can easily navigate any Maven project.</p><h3>🔍 Testing and Reports</h3><p>When you run mvn test, Maven automatically executes all the test files in the test folder.</p><p>Afterward, it creates a <strong>report</strong> in the surefire-reports directory — showing what passed, failed, or needs fixing.</p><p>This documentation is useful for debugging and continuous integration pipelines. Also used for relations with the Dev team on what an what not needs to be corrected</p><h3>📦 Packaging and Running the Build</h3><p>When you execute:</p><pre>mvn package</pre><p>Maven bundles everything into an archive file:</p><ul><li>.jar → Java ARchive</li><li>.war → Web ARchive</li><li>.ear → Enterprise ARchive</li></ul><p>You can then test your app locally before deployment:</p><pre>java -cp Airfluke-app-1.0-SNAPSHOT.jar com.ibt.abrahamacha.App</pre><p>This ensures the packaged file runs correctly before it’s pushed to the server.</p><p>But typing that long command every time can get tiring 😅.<br> Maven provides a simpler way using the <strong>Exec Plugin </strong>and this can be gotten from Maven Central ; all you need to do is add it to your pom.xml. Once configured, you can run your app directly with:</p><pre>mvn exec:java</pre><p>The plugin automatically locates and executes your app’s main class, saving you the trouble of typing that long command line each time.</p><h3>🌐 Repositories: Local, Remote, and Central</h3><p>Maven uses <strong>repositories</strong> to store and retrieve dependencies (libraries and plugins).</p><ul><li>💾 <strong>Local Repository:</strong> Stored on your computer in the .m2 folder.</li><li>🌍 <strong>Central Repository:</strong> The global repository where Maven downloads dependencies from.</li><li>🏢 <strong>Remote Repository:</strong> A company-managed server (e.g., Artifactory) where builds and dependencies are uploaded.</li></ul><p>If Maven can’t find a dependency locally, it automatically fetches it from the central repository and caches it for future use.</p><p>To connect to a remote repository like Artifactory:</p><ol><li>🔧 Get the settings.xml file from Artifactory.</li><li>📁 Copy it to your local .m2 directory.</li><li>✏️ Add the repository credentials and configuration to your pom.xml.</li></ol><p>Once configured, you can deploy with:</p><pre>mvn deploy</pre><h3>🚀 Maven in the DevOps Pipeline</h3><p>As a DevOps engineer, you’re mostly focused on:</p><ul><li>🧰 <strong>Building the code</strong> (mvn clean install)</li><li>🧪 <strong>Testing</strong> and verifying build quality</li><li>🛡️ <strong>Scanning for vulnerabilities or errors</strong></li><li>🔄 <strong>Passing the build to CI/CD tools like Jenkins</strong></li></ul><p>Maven itself isn’t a standalone automation platform — it’s a <strong>builder</strong>.</p><p>In CI/CD pipelines, it pairs perfectly with <strong>Jenkins</strong>, where Jenkins automates the workflow, and Maven handles the building and testing parts.</p><h3>🏁 Wrapping Up</h3><p>Maven might seem like just another Java tool, but it’s much more — it’s a <strong>bridge between development and deployment</strong>, ensuring consistency, repeatability, and structure.</p><p>For a DevOps engineer, Maven is the silent assistant that makes sure the code you ship is clean, well-packaged, and production-ready.</p><blockquote><em>💭 In short: Maven builds. Jenkins delivers. Together, they automate the world. 🌍</em></blockquote><p>✍️ <em>Written by Abraham Acha (Airfluke)</em>— A DevOps enthusiast passionate about simplifying automation, one build at a time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=791977d256f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>