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

removing triggers #109 #111

Merged
merged 1 commit into from
Oct 30, 2024
Merged

removing triggers #109 #111

merged 1 commit into from
Oct 30, 2024

Conversation

kunduso
Copy link
Owner

@kunduso kunduso commented Oct 30, 2024

This PR closes #109

Copy link

💰 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

──────────────────────────────────
12 cloud resources were detected:
∙ 1 was estimated
∙ 10 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

Terraform Format and Style 🖌success

Terraform Initialization ⚙️success

Terraform Plan 📖success

Terraform Validation 🤖success

Show Plan

terraform
data.aws_ssm_parameter.infra_output: Reading...
aws_iam_role.codedeploy_role: Refreshing state... [id=app-6-code-deploy-role]
data.aws_caller_identity.current: Reading...
aws_iam_role.ecs_task_execution_role: Refreshing state... [id=app-6-task-execution-role]
aws_codedeploy_app.application_main: Refreshing state... [id=b326775b-2c4f-418c-afe6-c643eafbbc4b:app-6]
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.codedeploy_policy_attachement: Refreshing state... [id=app-6-code-deploy-role-20241023021723338900000001]
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.attach_secrets_read_task_role: Refreshing state... [id=app-6-task-role-20241003153209524100000003]
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=dc299e321321b1c70ce8615f6f5041cd6dab75a1]
terraform_data.trigger_code_deploy_deployment: Refreshing state... [id=7ada572d-f701-48c3-cad7-0252d08e42b6]

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:73" -> (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                 = 73 -> (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)
    }

  # terraform_data.trigger_code_deploy_deployment must be replaced
-/+ resource "terraform_data" "trigger_code_deploy_deployment" {
      ~ id               = "7ada572d-f701-48c3-cad7-0252d08e42b6" -> (known after apply)
      - triggers_replace = <<-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:73\"},\"Type\":\"AWS::ECS::Service\"}}],\"version\":\"0.0\"}", "sha256":"81a488aca06ccd063ff08756fc1f31529bb57fc944dc055da922c5a3e4ac966b"}}' \
                --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 -> null
    }

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 44e80a8 into main Oct 30, 2024
9 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
Development

Successfully merging this pull request may close these issues.

Add logic to trigger deployment on each terraform apply
1 participant