generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 20
177 lines (173 loc) · 6.89 KB
/
apex.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
---
name: apex
on:
push:
branches:
- main
paths:
- 'terraform/environments/apex/**'
- '.github/workflows/apex.yml'
pull_request:
branches:
- main
types: [opened, edited, reopened, synchronize]
paths:
- 'terraform/environments/apex/**'
- '.github/workflows/apex.yml'
workflow_dispatch:
env:
TF_IN_AUTOMATION: true
AWS_REGION: "eu-west-2"
ENVIRONMENT_MANAGEMENT: ${{ secrets.MODERNISATION_PLATFORM_ENVIRONMENTS }}
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
defaults:
run:
shell: bash
jobs:
plan-dev-test:
strategy:
matrix:
include:
- environment: development
# - environment: test
name: Plan - ${{ matrix.environment }}
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main' || github.event_name == 'workflow_dispatch'
env:
TF_ENV: ${{ matrix.environment }}
steps:
- name: Checkout Repository
uses: actions/[email protected]
- name: Set Account Number
run: echo "ACCOUNT_NUMBER=$(jq -r -e --arg account_name "${GITHUB_WORKFLOW}-${TF_ENV}" '.account_ids[$account_name]' <<< $ENVIRONMENT_MANAGEMENT)" >> $GITHUB_ENV
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: "arn:aws:iam::${{ env.ACCOUNT_NUMBER }}:role/github-actions"
role-session-name: githubactionsrolesession
aws-region: ${{ env.AWS_REGION }}
- name: Load and Configure Terraform
uses: hashicorp/[email protected]
with:
terraform_version: "~1"
terraform_wrapper: false
- name: Plan - ${{ matrix.environment }}
run: |
terraform --version
echo "Terraform plan - ${TF_ENV}"
bash scripts/terraform-init.sh terraform/environments/$GITHUB_WORKFLOW
terraform -chdir="terraform/environments/${GITHUB_WORKFLOW}" workspace select "${GITHUB_WORKFLOW}-${TF_ENV}"
bash scripts/terraform-plan.sh terraform/environments/$GITHUB_WORKFLOW
# These jobs run when creating a pull request
deploy-dev-test:
needs: plan-dev-test
if: success()
strategy:
matrix:
include:
- environment: development
# - environment: test
name: Apply - ${{ matrix.environment }}
runs-on: ubuntu-latest
env:
TF_ENV: ${{ matrix.environment }}
environment:
name: ${{ github.workflow }}-${{ matrix.environment }}
steps:
- name: Checkout Repository
uses: actions/[email protected]
- name: Set Account Number
run: echo "ACCOUNT_NUMBER=$(jq -r -e --arg account_name "${GITHUB_WORKFLOW}-${TF_ENV}" '.account_ids[$account_name]' <<< $ENVIRONMENT_MANAGEMENT)" >> $GITHUB_ENV
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: "arn:aws:iam::${{ env.ACCOUNT_NUMBER }}:role/github-actions"
role-session-name: githubactionsrolesession
aws-region: ${{ env.AWS_REGION }}
- name: Load and Configure Terraform
uses: hashicorp/[email protected]
with:
terraform_version: "~1"
terraform_wrapper: false
- name: Apply - ${{ matrix.environment }}
run: |
terraform --version
echo "Terraform apply - ${TF_ENV}"
bash scripts/terraform-init.sh terraform/environments/$GITHUB_WORKFLOW
terraform -chdir="terraform/environments/${GITHUB_WORKFLOW}" workspace select "${GITHUB_WORKFLOW}-${TF_ENV}"
bash scripts/terraform-apply.sh terraform/environments/$GITHUB_WORKFLOW
# # Plan + deploy for pre-production and production environments, only from main
# plan-preprod-prod:
# strategy:
# matrix:
# include:
# - environment: preproduction
# - environment: production
# name: Plan - ${{ matrix.environment }}
# runs-on: ubuntu-latest
# if: github.ref == 'refs/heads/main'
# env:
# TF_ENV: ${{ matrix.environment }}
# steps:
# - name: Checkout Repository
# uses: actions/[email protected]
# - name: Set Account Number
# run: echo "ACCOUNT_NUMBER=$(jq -r -e --arg account_name "${GITHUB_WORKFLOW}-${TF_ENV}" '.account_ids[$account_name]' <<< $ENVIRONMENT_MANAGEMENT)" >> $GITHUB_ENV
# - name: configure aws credentials
# uses: aws-actions/configure-aws-credentials@v1
# with:
# role-to-assume: "arn:aws:iam::${{ env.ACCOUNT_NUMBER }}:role/github-actions"
# role-session-name: githubactionsrolesession
# aws-region: ${{ env.AWS_REGION }}
# - name: Load and Configure Terraform
# uses: hashicorp/[email protected]
# with:
# terraform_version: "~1"
# terraform_wrapper: false
# - name: Plan - ${{ matrix.environment }}
# run: |
# terraform --version
# echo "Terraform plan - ${TF_ENV}"
# bash scripts/terraform-init.sh terraform/environments/$GITHUB_WORKFLOW
# terraform -chdir="terraform/environments/${GITHUB_WORKFLOW}" workspace select "${GITHUB_WORKFLOW}-${TF_ENV}"
# bash scripts/terraform-plan.sh terraform/environments/$GITHUB_WORKFLOW
# # These jobs run when creating a pull request
# deploy-preprod-prod:
# needs: plan-preprod-prod
# if: success()
# strategy:
# matrix:
# include:
# - environment: preproduction
# - environment: production
# name: Apply - ${{ matrix.environment }}
# runs-on: ubuntu-latest
# env:
# TF_ENV: ${{ matrix.environment }}
# environment:
# name: ${{ github.workflow }}-${{ matrix.environment }}
# steps:
# - name: Checkout Repository
# uses: actions/[email protected]
# - name: Set Account Number
# run: echo "ACCOUNT_NUMBER=$(jq -r -e --arg account_name "${GITHUB_WORKFLOW}-${TF_ENV}" '.account_ids[$account_name]' <<< $ENVIRONMENT_MANAGEMENT)" >> $GITHUB_ENV
# - name: configure aws credentials
# uses: aws-actions/configure-aws-credentials@v1
# with:
# role-to-assume: "arn:aws:iam::${{ env.ACCOUNT_NUMBER }}:role/github-actions"
# role-session-name: githubactionsrolesession
# aws-region: ${{ env.AWS_REGION }}
# - name: Load and Configure Terraform
# uses: hashicorp/[email protected]
# with:
# terraform_version: "~1"
# terraform_wrapper: false
# - name: Apply - ${{ matrix.environment }}
# run: |
# terraform --version
# echo "Terraform apply - ${TF_ENV}"
# bash scripts/terraform-init.sh terraform/environments/$GITHUB_WORKFLOW
# terraform -chdir="terraform/environments/${GITHUB_WORKFLOW}" workspace select "${GITHUB_WORKFLOW}-${TF_ENV}"
# bash scripts/terraform-apply.sh terraform/environments/$GITHUB_WORKFLOW