Skip to content

Commit 4eabe5c

Browse files
committed
ci: Added deployment jobs.
1 parent f2b012d commit 4eabe5c

4 files changed

Lines changed: 142 additions & 1 deletion

File tree

.github/workflows/deploy-app.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Deploy application
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
application:
7+
description: Application to deploy.
8+
required: true
9+
type: string
10+
environment:
11+
description: Environment to deploy to.
12+
default: development
13+
required: true
14+
type: environment
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
deploy:
21+
name: Deploy ${{ inputs.application }} to ${{ inputs.environment }}
22+
runs-on: ubuntu-latest
23+
environment: ${{ inputs.environment }}
24+
env:
25+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
26+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
27+
AWS_REGION: ${{ vars.AWS_REGION || 'us-east-1' }}
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
- name: Set up AWS credentials
32+
uses: aws-actions/configure-aws-credentials@v4
33+
with:
34+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
35+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
36+
aws-region: us-east-1
37+
- name: Setup OpenTofu
38+
uses: opentofu/setup-opentofu@v1
39+
- name: Initialize OpenTofu
40+
working-directory: ./tofu/config/${{ inputs.environment }}/infra
41+
run: tofu init
42+
- name: Apply changes
43+
working-directory: ./tofu/config/${{ inputs.environment }}/infra
44+
run: tofu apply --target module.app\[\"${{ inputs.application }}\"] --auto-approve

.github/workflows/deploy.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Deploy infrastructure
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
environment:
7+
description: Environment to deploy to.
8+
default: development
9+
required: true
10+
type: environment
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
deploy:
17+
name: Deploy infrastrucure to ${{ inputs.environment }}
18+
runs-on: ubuntu-latest
19+
environment: ${{ inputs.environment }}
20+
env:
21+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
22+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
23+
AWS_REGION: ${{ vars.AWS_REGION || 'us-east-1' }}
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
- name: Set up AWS credentials
28+
uses: aws-actions/configure-aws-credentials@v4
29+
with:
30+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
31+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
32+
aws-region: us-east-1
33+
- name: Setup OpenTofu
34+
uses: opentofu/setup-opentofu@v1
35+
- name: Initialize OpenTofu
36+
working-directory: ./tofu/config/${{ inputs.environment }}/infra
37+
run: tofu init
38+
- name: Apply changes
39+
working-directory: ./tofu/config/${{ inputs.environment }}/infra
40+
run: tofu apply --auto-approve

.github/workflows/plan-app.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Plan application deployment
2+
3+
on:
4+
repository_dispatch:
5+
types:
6+
- plan-app
7+
workflow_dispatch:
8+
inputs:
9+
application:
10+
description: Application to plan.
11+
required: true
12+
type: string
13+
environment:
14+
description: Environment to plan on.
15+
default: development
16+
required: true
17+
type: environment
18+
19+
permissions:
20+
contents: read
21+
22+
jobs:
23+
plan:
24+
name: Plan deploy of ${{ inputs.application }} to ${{ inputs.environment }}
25+
runs-on: ubuntu-latest
26+
environment: ${{ inputs.environment }}
27+
env:
28+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
29+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
30+
AWS_REGION: ${{ vars.AWS_REGION || 'us-east-1' }}
31+
steps:
32+
- name: "DEBUG: Dump inputs"
33+
run: |
34+
echo "Inputs: ${{ toJson(inputs) }}
35+
- name: "DEBUG: Dump payload"
36+
run: |
37+
echo "Environment: ${{ toJson(github.event.client_payload.environment) }}"
38+
- name: Checkout code
39+
uses: actions/checkout@v4
40+
- name: Set up AWS credentials
41+
uses: aws-actions/configure-aws-credentials@v4
42+
with:
43+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
44+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
45+
aws-region: us-east-1
46+
- name: Setup OpenTofu
47+
uses: opentofu/setup-opentofu@v1
48+
- name: Initialize OpenTofu
49+
working-directory: ./tofu/config/${{ inputs.environment }}/infra
50+
run: tofu init
51+
- name: Plan changes
52+
working-directory: ./tofu/config/${{ inputs.environment }}/infra
53+
run: tofu plan --target module.app\[\"${{ inputs.application }}\"]
54+
- name: Display plan
55+
uses: imesense/gha-echo-action@v0.2
56+
with:
57+
input-string: ${{ steps.plan.outputs.stdout }}

.github/workflows/plan.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
with:
4444
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
4545
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
46-
aws-region: us-east-1
46+
aws-region: ${{ vars.AWS_REGION || 'us-east-1' }}
4747
- name: Setup OpenTofu
4848
uses: opentofu/setup-opentofu@v1
4949
- name: Initialize OpenTofu

0 commit comments

Comments
 (0)