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

updated to trigger based on local_file #109 #112

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

kunduso
Copy link
Owner

@kunduso kunduso commented Oct 30, 2024

No description provided.

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_codedeploy_app.application_main: Refreshing state... [id=b326775b-2c4f-418c-afe6-c643eafbbc4b:app-6]
data.aws_caller_identity.current: Reading...
aws_iam_role.ecs_task_execution_role: Refreshing state... [id=app-6-task-execution-role]
aws_iam_role.codedeploy_role: Refreshing state... [id=app-6-code-deploy-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 0s [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=0d001b23bcf7d008fa408c6ad2c73a08c1fa18f3]
terraform_data.trigger_code_deploy_deployment: Refreshing state... [id=f7d2aaa0-c3a3-3c0b-d226-69bbc7233a09]

Note: Objects have changed outside of Terraform

Terraform detected the following changes made outside of Terraform since the
last "terraform apply" which may have affected this plan:

  # local_file.code_deploy_sh has been deleted
  - resource "local_file" "code_deploy_sh" {
      - 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:74\"},\"Type\":\"AWS::ECS::Service\"}}],\"version\":\"0.0\"}", "sha256":"2b98149e412a15af861a6fdebe63d8b5c78515e3e83b9d3492a04648ca817445"}}' \
                --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
      - content_base64sha256 = "wBb9nhzDxJyG4kjoRxZ8VMgIXwGPbg2yoa5cWYQBWL4=" -> null
      - content_base64sha512 = "H/PadEwMSJj1WyTrqGMxqrnqkfYN4roLxF981bBto5dqzqKZ+Y0WCKpQS+KvNqvB0C1/X1oFyV3MlYNAv9LTcQ==" -> null
      - content_md5          = "24dd5501552a775300ca4ebb8deffc7b" -> null
      - content_sha1         = "0d001b23bcf7d008fa408c6ad2c73a08c1fa18f3" -> null
      - content_sha256       = "c016fd9e1cc3c49c86e248e847167c54c8085f018f6e0db2a1ae5c59840158be" -> null
      - content_sha512       = "1ff3da744c0c4898f55b24eba86331aab9ea91f60de2ba0bc45f7cd5b06da3976acea299f98d1608aa504be2af36abc1d02d7f5f5a05c95dcc958340bfd2d371" -> null
      - directory_permission = "0777" -> null
      - file_permission      = "0755" -> null
      - filename             = "./code_deploy.sh" -> null
      - id                   = "0d001b23bcf7d008fa408c6ad2c73a08c1fa18f3" -> null
    }


Unless you have made equivalent changes to your configuration, or ignored the
relevant attributes using ignore_changes, the following plan may include
actions to undo or respond to these changes.

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

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:74" -> (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                 = 74 -> (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               = "f7d2aaa0-c3a3-3c0b-d226-69bbc7233a09" -> (known after apply)
      + triggers_replace = {
          + content              = (known after apply)
          + content_base64       = null
          + 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)
          + sensitive_content    = (sensitive value)
          + source               = 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 f990a09 into main Oct 30, 2024
9 checks passed
@kunduso
Copy link
Owner Author

kunduso commented Oct 31, 2024

This PR closed #112

@kunduso kunduso linked an issue Oct 31, 2024 that may be closed by this pull request
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