-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdeploy.yaml
More file actions
72 lines (61 loc) · 2.8 KB
/
deploy.yaml
File metadata and controls
72 lines (61 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: Deploy to AWS
on:
workflow_dispatch:
inputs:
processing_image_tag:
description: "Processing image tag"
required: true
deploy_environment:
description: "Deployment environment (e.g., staging, production)"
required: true
env:
TF_VAR_processing_image_tag: ${{ github.event.inputs.processing_image_tag }}
jobs:
check-admin-permissions:
name: Set deployment environment
runs-on: ubuntu-latest
steps:
- id: check-admin
name: Check if user is an admin
run: |
if [ "${{ github.event_name }}" = 'workflow_dispatch' ]; then
RESPONSE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/collaborators/${{ github.actor }}/permission)
PERMISSION=$(echo $RESPONSE | jq -r .permission)
if [ "$PERMISSION" != "admin" ]; then
echo "::error::This workflow can only be run by admin users." && exit 1
fi
fi
- id: check-valid-environment
name: Check if the environment is valid
run: |
if [ "${{ github.event.inputs.deploy_environment }}" != "staging" && "${{ github.event.inputs.deploy_environment }}" != "production" ]; then
echo "::error::Invalid environment. Please choose either 'staging' or 'production'." && exit 1
fi
deploy:
name: Terraform Deployment
runs-on: ubuntu-latest
environment:
name: ${{ github.event.inputs.deploy_environment }}
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: "1.4.6"
- name: Set up AWS CLI
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2
- name: Terraform Init
working-directory: deployment/environments/${{ github.event.inputs.deploy_environment }}
run: terraform init
- name: Terraform Plan
working-directory: deployment/environments/${{ github.event.inputs.deploy_environment }}
run: terraform plan
- name: Terraform Apply with Auto Confirm
working-directory: deployment/environments/${{ github.event.inputs.deploy_environment }}
run: terraform apply -auto-approve