Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable blue green deployment #99

Merged
merged 36 commits into from
Oct 6, 2024
Merged

Enable blue green deployment #99

merged 36 commits into from
Oct 6, 2024

Conversation

kunduso
Copy link
Owner

@kunduso kunduso commented Oct 6, 2024

This PR closes #98 closes #97 and closes #94

@kunduso kunduso self-assigned this Oct 6, 2024
Copy link

github-actions bot commented Oct 6, 2024

💰 Infracost report

Monthly estimate generated

Estimate details (includes details of unsupported resources)
──────────────────────────────────
1 project has no cost estimate change.
Run the following command to see its breakdown: infracost breakdown --path=/path/to/code

──────────────────────────────────
13 cloud resources were detected:
∙ 1 was estimated
∙ 11 were free
∙ 1 is not supported yet, see https://infracost.io/requested-resources:
  ∙ 1 x aws_codedeploy_deployment_group
This comment will be updated when code changes.

Copy link

github-actions bot commented Oct 6, 2024

Terraform Format and Style 🖌success

Terraform Initialization ⚙️success

Terraform Plan 📖success

Terraform Validation 🤖success

Show Plan

terraform
data.aws_caller_identity.current: Reading...
aws_service_discovery_http_namespace.namespace: Refreshing state... [id=ns-cc5i7ykaj67ppst3]
aws_kms_key.custom_kms_key: Refreshing state... [id=ef68e503-5cdd-4baf-9547-3d39d0e4a0c8]
aws_vpc.this: Refreshing state... [id=vpc-0177cbea506968866]
data.aws_caller_identity.current: Read complete after 0s [id=743794601996]
aws_ecr_repository.image_repo: Refreshing state... [id=app-6]
aws_kms_alias.key: Refreshing state... [id=alias/app-6]
aws_secretsmanager_secret.ecs_secret: Refreshing state... [id=arn:aws:secretsmanager:us-east-2:743794601996:secret:ecs_secret-xyMvld]
aws_kms_key_policy.encrypt_app: Refreshing state... [id=ef68e503-5cdd-4baf-9547-3d39d0e4a0c8]
aws_cloudwatch_log_group.logs: Refreshing state... [id=/amazon-ecs/app-6/log]
aws_secretsmanager_secret_version.ecs_secret_version: Refreshing state... [id=arn:aws:secretsmanager:us-east-2:743794601996:secret:ecs_secret-xyMvld|terraform-20241004214323955000000001]
aws_ecs_cluster.app_cluster: Refreshing state... [id=arn:aws:ecs:us-east-2:743794601996:cluster/app-6]
aws_default_security_group.default: Refreshing state... [id=sg-0e90b718d992b31ea]
aws_vpc_endpoint.s3: Refreshing state... [id=vpce-08ac7d43bbc3bb49d]
aws_route_table.this_rt: Refreshing state... [id=rtb-0ee63cd483cdda2a6]
aws_lb_target_group.blue_target_group: Refreshing state... [id=arn:aws:elasticloadbalancing:us-east-2:743794601996:targetgroup/app-6-blue/bee4cbd72f2fedfe]
aws_route_table.this_rt_private: Refreshing state... [id=rtb-076c0decdd5557da1]
aws_lb_target_group.green_target_group: Refreshing state... [id=arn:aws:elasticloadbalancing:us-east-2:743794601996:targetgroup/app-6-green/8054f7143db62529]
aws_internet_gateway.this_igw: Refreshing state... [id=igw-0c1c35cd1eebdf561]
aws_subnet.private[1]: Refreshing state... [id=subnet-09b612ab68f8cf06d]
aws_subnet.public[0]: Refreshing state... [id=subnet-0265de33fcbcc74bf]
aws_subnet.private[0]: Refreshing state... [id=subnet-0da40b020a8b8fca6]
aws_subnet.public[1]: Refreshing state... [id=subnet-0ba781f8c180ec1c5]
aws_security_group.endpoint_sg: Refreshing state... [id=sg-0318f588f4818e5cf]
aws_security_group.custom_sg: Refreshing state... [id=sg-0f503030dfa8c9ef8]
aws_security_group.container_sg: Refreshing state... [id=sg-011020866225de511]
aws_route.internet_route: Refreshing state... [id=r-rtb-0ee63cd483cdda2a61080289494]
aws_route_table_association.private[0]: Refreshing state... [id=rtbassoc-0dfbe27f944a69c10]
aws_route_table_association.private[1]: Refreshing state... [id=rtbassoc-05abae80d12bb9a36]
aws_vpc_endpoint.cloudwatch: Refreshing state... [id=vpce-0accdb89f1535e6c5]
aws_security_group_rule.ingress_vpc_endpoint: Refreshing state... [id=sgrule-993827166]
aws_vpc_endpoint.secrets_manager: Refreshing state... [id=vpce-0a6cf8ee910b8e883]
aws_vpc_endpoint.ecr: Refreshing state... [id=vpce-0eda08325c5d33c42]
aws_vpc_endpoint.ecr_api: Refreshing state... [id=vpce-07314797ccaba5e5f]
aws_security_group_rule.egress_load_balancer: Refreshing state... [id=sgrule-4047886860]
aws_security_group_rule.ingress_load_balancer: Refreshing state... [id=sgrule-2183468127]
aws_lb.app_lb: Refreshing state... [id=arn:aws:elasticloadbalancing:us-east-2:743794601996:loadbalancer/app/app-6/dd3117db6f42b247]
aws_route_table_association.public[1]: Refreshing state... [id=rtbassoc-01e8adeb6b52b7d82]
aws_route_table_association.public[0]: Refreshing state... [id=rtbassoc-068a2547cce99ca0d]
aws_vpc_endpoint_route_table_association.s3_association: Refreshing state... [id=a-vpce-08ac7d43bbc3bb49d1013104409]
aws_security_group_rule.egress_container: Refreshing state... [id=sgrule-4292562398]
aws_security_group_rule.ingress_container: Refreshing state... [id=sgrule-1962334996]
aws_alb_listener.listener: Refreshing state... [id=arn:aws:elasticloadbalancing:us-east-2:743794601996:listener/app/app-6/dd3117db6f42b247/97befa50e51ff9bc]
aws_ssm_parameter.infra_output: Refreshing state... [id=/app-6/output]

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # aws_secretsmanager_secret_version.ecs_secret_version must be replaced
-/+ resource "aws_secretsmanager_secret_version" "ecs_secret_version" {
      ~ arn            = "arn:aws:secretsmanager:us-east-2:743794601996:secret:ecs_secret-xyMvld" -> (known after apply)
      ~ id             = "arn:aws:secretsmanager:us-east-2:743794601996:secret:ecs_secret-xyMvld|terraform-20241004214323955000000001" -> (known after apply)
      ~ secret_string  = (sensitive value) # forces replacement
      ~ version_id     = "terraform-20241004214323955000000001" -> (known after apply)
      ~ version_stages = [
          - "AWSCURRENT",
        ] -> (known after apply)
        # (2 unchanged attributes hidden)
    }

Plan: 1 to add, 0 to change, 1 to destroy.

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: TFplan.JSON

To perform exactly these actions, run the following command to apply:
    terraform apply "TFplan.JSON"

Pushed by: @kunduso, Action: pull_request

Copy link

github-actions bot commented Oct 6, 2024

Terraform Format and Style 🖌success

Terraform Initialization ⚙️success

Terraform Plan 📖success

Terraform Validation 🤖success

Show Plan

terraform
data.aws_ssm_parameter.infra_output: Reading...
data.aws_caller_identity.current: Reading...
aws_codedeploy_app.application_main: Refreshing state... [id=b326775b-2c4f-418c-afe6-c643eafbbc4b:app-6]
aws_iam_role.codedeploy_role: Refreshing state... [id=app-6-code-deploy-role]
aws_iam_role.ecs_task_execution_role: Refreshing state... [id=app-6-task-execution-role]
data.aws_caller_identity.current: Read complete after 0s [id=743794601996]
aws_iam_role.ecs_task_role: Refreshing state... [id=app-6-task-role]
data.aws_ssm_parameter.infra_output: Read complete after 1s [id=/app-6/output]
aws_iam_policy.secrets_manager_read_policy: Refreshing state... [id=arn:aws:iam::743794601996:policy/app-6-ecs-fargate-secrets-manager-access]
aws_iam_role_policy_attachment.custom: Refreshing state... [id=app-6-task-execution-role-20241003153209502800000001]
aws_iam_role_policy_attachment.attach_secrets_read_task_execution_role: Refreshing state... [id=app-6-task-execution-role-20241003153209508300000002]
aws_iam_role_policy_attachment.codedeploy_policy_attachement: Refreshing state... [id=app-6-code-deploy-role-20241006015657334100000001]
aws_iam_role_policy_attachment.attach_secrets_read_task_role: Refreshing state... [id=app-6-task-role-20241003153209524100000003]
aws_iam_policy.custom_codedeploy_policy: Refreshing state... [id=arn:aws:iam::743794601996:policy/app-6-code-deploy-policy]
aws_ecs_task_definition.web_app: Refreshing state... [id=app-6]
aws_ecs_service.service: Refreshing state... [id=arn:aws:ecs:us-east-2:743794601996:service/app-6/app-6]
aws_codedeploy_deployment_group.application_main: Refreshing state... [id=664c9ff4-b726-4afb-9654-85030ab22491]
local_file.code_deploy_sh: Refreshing state... [id=b15436ff24f0caa1a1d39925b90d288e94c4f469]
null_resource.code_deploy: Refreshing state... [id=4032747766715569796]

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # aws_ecs_task_definition.web_app must be replaced
-/+ resource "aws_ecs_task_definition" "web_app" {
      ~ arn                      = "arn:aws:ecs:us-east-2:743794601996:task-definition/app-6:68" -> (known after apply)
      ~ arn_without_revision     = "arn:aws:ecs:us-east-2:743794601996:task-definition/app-6" -> (known after apply)
      ~ container_definitions    = (sensitive value) # forces replacement
      ~ id                       = "app-6" -> (known after apply)
      ~ revision                 = 68 -> (known after apply)
      - tags                     = {} -> null
        # (12 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

  # local_file.code_deploy_sh will be created
  + resource "local_file" "code_deploy_sh" {
      + content              = (known after apply)
      + content_base64sha256 = (known after apply)
      + content_base64sha512 = (known after apply)
      + content_md5          = (known after apply)
      + content_sha1         = (known after apply)
      + content_sha256       = (known after apply)
      + content_sha512       = (known after apply)
      + directory_permission = "0777"
      + file_permission      = "0755"
      + filename             = "./code_deploy.sh"
      + id                   = (known after apply)
    }

  # null_resource.code_deploy must be replaced
-/+ resource "null_resource" "code_deploy" {
      ~ id       = "4032747766715569796" -> (known after apply)
      ~ triggers = { # forces replacement
          ~ "script_content" = <<-EOT
                #!/bin/bash
                set -e
                
                echo "Starting CodeDeploy agent deployment"
                aws --version
                
                echo "Constructing deployment command..."
                COMMAND=$(cat <<EOT
                aws deploy create-deployment \
                    --application-name "app-6" \
                    --deployment-config-name CodeDeployDefault.ECSAllAtOnce \
                    --deployment-group-name "app-6-deploy-group" \
                    --revision '{"revisionType": "AppSpecContent", "appSpecContent": {"content": "{\"Resources\":[{\"TargetService\":{\"Properties\":{\"LoadBalancerInfo\":{\"ContainerName\":\"first\",\"ContainerPort\":8080},\"TaskDefinition\":\"arn:aws:ecs:us-east-2:743794601996:task-definition/app-6:68\"},\"Type\":\"AWS::ECS::Service\"}}],\"version\":\"0.0\"}", "sha256":"b919d0df0b796940bc7a39dc40904cf09a7c0719e0d19388b54d92b53c3d8e00"}}' \
                    --description "Deployment from Terraform" \
                    --output json
                EOT
                )
                
                echo "Command to be executed:"
                echo "$COMMAND"
                
                echo "Executing deployment command..."
                DEPLOYMENT_INFO=$(eval "$COMMAND")
                COMMAND_EXIT_CODE=$?
                
                echo "Command exit code: $COMMAND_EXIT_CODE"
                echo "Raw output:"
                echo "$DEPLOYMENT_INFO"
                
                if [ $COMMAND_EXIT_CODE -ne 0 ]; then
                    echo "Error: AWS CLI command failed"
                    exit $COMMAND_EXIT_CODE
                fi
                
                echo "Parsing deployment info..."
                if ! DEPLOYMENT_ID=$(echo "$DEPLOYMENT_INFO" | jq -r '.deploymentId'); then
                    echo "Error: Failed to parse deployment ID from output"
                    exit 1
                fi
                
                if [ "$DEPLOYMENT_ID" == "null" ] || [ -z "$DEPLOYMENT_ID" ]; then
                    echo "Error: Deployment ID is null or empty"
                    exit 1
                fi
                
                echo "Deployment ID: $DEPLOYMENT_ID"
                
                echo "Deployment created successfully"
            EOT -> (known after apply)
        }
    }

Plan: 3 to add, 0 to change, 2 to destroy.

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: TFplan.JSON

To perform exactly these actions, run the following command to apply:
    terraform apply "TFplan.JSON"

Pushed by: @kunduso, Action: pull_request

@kunduso kunduso merged commit d03b77e into main Oct 6, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant