Skip to content

Commit

Permalink
chore: tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
mystist committed Aug 24, 2024
1 parent e6c498a commit 42c5cba
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,18 @@ jobs:
- name: Replace AWS account ID in task definition
env:
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_GITHUB_PAT_ARN_ID: ${{ secrets.AWS_GITHUB_PAT_ARN_ID }}
run: |
sed -i 's|${AWS_ACCOUNT_ID}|'"$AWS_ACCOUNT_ID"'|' ${{ env.ECS_TASK_DEFINITION }}
sed -i 's|${AWS_GITHUB_PAT_ARN_ID}|'"$AWS_GITHUB_PAT_ARN_ID"'|' ${{ env.AWS_GITHUB_PAT_ARN_ID }}
- name: Render Amazon ECS task definition
id: render-task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/task-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
"hostPort": 3000
}
],
"secrets": [
{
"name": "GITHUB_PAT",
"valueFrom": "arn:aws:secretsmanager:ap-east-1:${AWS_ACCOUNT_ID}:secret:${AWS_GITHUB_PAT_ARN_ID}"
}
],
"essential": true,
"logConfiguration": {
"logDriver": "awslogs",
Expand Down
32 changes: 31 additions & 1 deletion terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,12 @@ resource "aws_ecs_task_definition" "main" {
}
]
essential = true

secrets = [
{
name = "GITHUB_PAT"
valueFrom = data.aws_secretsmanager_secret.github_pat.arn
}
]
logConfiguration = {
logDriver = "awslogs"
options = {
Expand Down Expand Up @@ -397,6 +402,31 @@ resource "aws_iam_role_policy_attachment" "ecs_task_execution_role_policy" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
}

resource "aws_iam_role_policy" "ecs_task_execution_secrets_policy" {
name = "${var.project_name}-ecs-task-secrets-policy"
role = aws_iam_role.ecs_task_execution_role.id

policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"secretsmanager:GetSecretValue"
]
Resource = [
data.aws_secretsmanager_secret.github_pat.arn
]
}
]
})
}

# secret
data "aws_secretsmanager_secret" "github_pat" {
name = "github-pat"
}

# cloudwatch
resource "aws_cloudwatch_log_group" "ecs_logs" {
name = "/ecs/${var.project_name}"
Expand Down

0 comments on commit 42c5cba

Please sign in to comment.