generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (119 loc) · 4.9 KB
/
.deployer.yml
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: .Terraform Deployer
on:
workflow_call:
inputs:
### Required
environment_name:
description: 'The name of the environment to deploy to'
required: true
default: 'dev'
type: string
command:
description: 'The terragrunt command to run'
required: true
default: 'apply'
type: string
working_directory:
description: 'The working directory to run the command in'
required: true
default: 'database'
type: string
tag:
description: 'The tag of the containers to deploy'
default: 'latest'
type: string
required: false
app_env:
required: false
type: string
description: 'The APP env separates between AWS ENV and Actual APP, since AWS dev is where PR, and TEST is deployed'
stack_prefix:
required: true
type: string
description: 'The stack prefix to use for the resources'
outputs:
API_GW_URL:
value: ${{ jobs.infra.outputs.API_GW_URL }}
S3_BUCKET_ARN:
value: ${{ jobs.infra.outputs.S3_BUCKET_ARN }}
CF_DOMAIN:
value: ${{ jobs.infra.outputs.CF_DOMAIN }}
CF_DISTRIBUTION_ID:
value: ${{ jobs.infra.outputs.CF_DISTRIBUTION_ID }}
env:
TG_VERSION: 0.55.2
TF_VERSION: 1.5.3
TG_SRC_PATH: terraform/${{ inputs.working_directory }}
AWS_REGION: ca-central-1
jobs:
infra:
environment: ${{ inputs.environment_name }}
name: Terraform ${{inputs.command}} ${{inputs.working_directory}} ${{inputs.environment_name}}
runs-on: ubuntu-24.04
outputs:
API_GW_URL: ${{ steps.tg-outputs.outputs.API_GW_URL }}
S3_BUCKET_ARN: ${{ steps.tg-outputs-frontend.outputs.S3_BUCKET_ARN }}
CF_DOMAIN: ${{ steps.tg-outputs-frontend.outputs.CF_DOMAIN }}
CF_DISTRIBUTION_ID: ${{ steps.tg-outputs-frontend.outputs.CF_DISTRIBUTION_ID }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE_ARN }}
role-session-name: ${{ inputs.environment_name }}-deployment
aws-region: ${{ env.AWS_REGION }}
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}
- name: Setup Terragrunt
uses: autero1/action-terragrunt@v3
with:
terragrunt-version: ${{ env.TG_VERSION }}
- name: Terragrunt ${{inputs.command}}
working-directory: terraform/${{ inputs.working_directory }}/${{ inputs.environment_name }}
env:
target_env: ${{ inputs.environment_name }}
aws_license_plate: ${{ secrets.AWS_LICENSE_PLATE }}
flyway_image: ghcr.io/${{github.repository}}/migrations:${{inputs.tag}}
api_image: ghcr.io/${{github.repository}}/backend:${{inputs.tag}}
app_env: ${{inputs.app_env}}
stack_prefix: ${{ inputs.stack_prefix }}
run: |
# Run terraform
terragrunt run-all ${{inputs.command}} --terragrunt-non-interactive
- name: Terragrunt API Outputs
if: ${{ inputs.working_directory == 'api' && inputs.command == 'apply' }}
working-directory: terraform/${{ inputs.working_directory }}/${{ inputs.environment_name }}
id: tg-outputs
env:
target_env: ${{ inputs.environment_name }}
aws_license_plate: ${{ secrets.AWS_LICENSE_PLATE }}
flyway_image: ghcr.io/${{github.repository}}/migrations:${{inputs.tag}}
api_image: ghcr.io/${{github.repository}}/backend:${{inputs.tag}}
app_env: ${{inputs.app_env}}
stack_prefix: ${{ inputs.stack_prefix }}
run: |
terragrunt output -json > outputs.json
#print the output
cat outputs.json
echo "API_GW_URL=$(jq -r .apigw_url.value outputs.json)" >> $GITHUB_OUTPUT
- name: Terragrunt Frontend Outputs
if: ${{ inputs.working_directory == 'frontend' && inputs.command == 'apply' }}
working-directory: terraform/${{ inputs.working_directory }}/${{ inputs.environment_name }}
id: tg-outputs-frontend
env:
target_env: ${{ inputs.environment_name }}
aws_license_plate: ${{ secrets.AWS_LICENSE_PLATE }}
flyway_image: ghcr.io/${{github.repository}}/migrations:${{inputs.tag}}
api_image: ghcr.io/${{github.repository}}/backend:${{inputs.tag}}
app_env: ${{inputs.app_env}}
stack_prefix: ${{ inputs.stack_prefix }}
run: |
terragrunt output -json > outputs.json
#print the output
cat outputs.json
echo "S3_BUCKET_ARN=$(jq -r .s3_bucket_arn.value outputs.json)" >> $GITHUB_OUTPUT
echo "CF_DOMAIN=$(jq -r .cloudfront.value.domain_name outputs.json)" >> $GITHUB_OUTPUT
echo "CF_DISTRIBUTION_ID=$(jq -r .cloudfront.value.distribution_id outputs.json)" >> $GITHUB_OUTPUT