-
Notifications
You must be signed in to change notification settings - Fork 0
98 lines (79 loc) · 2.71 KB
/
terraform-deploy-to-pre-prod-manual.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
# .github/workflows/terraform-dev
name: 'Deploy and Version Main to Pre-Prod'
on:
workflow_dispatch:
permissions:
pull-requests: write
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
tag_and_release:
runs-on: ubuntu-latest
outputs:
tag: ${{steps.versioning.outputs.tag}}
new_tag: ${{steps.versioning.outputs.new_tag}}
permissions: write-all
steps:
- uses: actions/checkout@v3
with:
ref: main
fetch-depth: '0'
- name: Bump version and push tag
id: versioning
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: false
DEFAULT_BUMP: patch
- name: View outputs
run: |
echo Current tag: ${{steps.versioning.outputs.tag}}
echo New tag: ${{steps.versioning.outputs.new_tag}}
terraform_process:
runs-on: ubuntu-latest
needs: ['tag_and_release']
environment: pre-prod
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{needs.tag_and_release.outputs.tag}}
fetch-depth: '0'
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }}
role-skip-session-tagging: true
aws-region: ${{ vars.AWS_REGION }}
- name: View AWS Role
run: aws sts get-caller-identity
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.5.4
terraform_wrapper: false
- name: Terraform Init
id: init
run: terraform init -backend-config=backend-pre-prod.conf
working-directory: ./infrastructure
shell: bash
- name: Terraform Set Workspace
id: workspace
run: terraform workspace select ${{ secrets.AWS_WORKSPACE }}
working-directory: ./infrastructure
shell: bash
# Checks that all Terraform configuration files adhere to a canonical format
- name: Terraform Format
run: terraform fmt -check
working-directory: ./infrastructure
- name: Terraform Plan
id: plan
run: |
terraform plan -input=false -no-color -var-file="${{vars.TF_VARS_FILE}}" -out tf.plan
working-directory: ./infrastructure
shell: bash
- name: Terraform Apply
run: terraform apply -auto-approve -input=false tf.plan
working-directory: ./infrastructure