-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (72 loc) · 2.26 KB
/
deploy.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
name: Deploy
on:
workflow_dispatch:
inputs:
environment:
type: environment
image-hash:
type: string
required: false
default: ''
description: SHA256 of the image to deploy
image-tag:
type: string
required: false
default: 'latest'
description: Tag of the image to deploy
jobs:
deploy:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
permissions:
id-token: write
packages: write
contents: write
steps:
#
# Setup Terraform
#
- name: Setup Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
with:
terraform_version: 1.9.7
#
# Checkout the source code
#
- name: Checkout the source code
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
with:
token: ${{ secrets.GIT_PAT }}
fetch-depth: 0
#
# Terraform init
#
- name: Terraform
shell: bash
working-directory: src/main/terraform
env:
IMAGE_HASH: "${{ inputs.image-hash }}"
IMAGE_TAG: "${{ inputs.image-tag }}"
ENVIRONMENT: "${{ inputs.environment }}"
ARM_CLIENT_ID: "${{ secrets.AZURE_CLIENT_ID }}"
ARM_SUBSCRIPTION_ID: "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
ARM_TENANT_ID: "${{ secrets.AZURE_TENANT_ID }}"
run: |
if [ -n "$IMAGE_HASH" ]; then
IMAGE="ghcr.io/pagopa/mil-auth:$IMAGE_TAG@sha256:$IMAGE_HASH"
else
IMAGE="ghcr.io/pagopa/mil-auth:$IMAGE_TAG"
fi
echo "*** [$IMAGE] will be deployed."
if [[ "$ENVIRONMENT" == "prod-cd" ]]; then
ENV_FOLDER="prod"
elif [[ "$ENVIRONMENT" == "uat-cd" ]]; then
ENV_FOLDER="uat"
else
ENV_FOLDER="dev"
fi
echo "*** [$ENV_FOLDER] folder will be used."
echo "Terraform init..."
terraform init -backend-config="env/$ENV_FOLDER/backend.tfvars" -reconfigure
echo "Terraform apply..."
terraform apply -var-file="env/$ENV_FOLDER/backend.tfvars" -var="mil_auth_image=$IMAGE" -auto-approve -lock-timeout=300s