-
Notifications
You must be signed in to change notification settings - Fork 0
121 lines (107 loc) · 4.07 KB
/
tf_apply.yml
File metadata and controls
121 lines (107 loc) · 4.07 KB
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
name: TF Apply
on:
workflow_call:
inputs:
environment:
description: Github action environment and AWS account type
type: string
required: true
oidc-domain:
description: 'OIDC Domain. Ex: "core" or "reveng"'
required: true
type: string
commit-identifier:
description: SHA or tag to apply
type: string
required: true
release-tag:
description: release name to apply to resources
type: string
required: false
default: unnamed
terraform-workspace:
description: Terraform Workspace
type: string
required: true
terraform-root:
description: Root directory of terraform
type: string
required: true
terraform-version:
description: Terraform version to use
type: string
required: true
secrets:
ORG_READ_ONLY_SSH_KEY:
required: true
ORG_GITHUB_PACKAGES_READ_ONLY_TOKEN:
required: true
concurrency:
group: ${{ github.repository }}-${{ inputs.environment }}-TF-Apply
permissions:
id-token: write
contents: read
env:
TF_INPUT: false
TF_IN_AUTOMATION: true
jobs:
Summary:
runs-on: ubuntu-latest
steps:
- name: Markdown Summary
run: |
echo "### Apply Infrastructure Context" >> $GITHUB_STEP_SUMMARY
echo "**Trigger**: ${{ github.event_name }} ${{ github.event.action }}" >> $GITHUB_STEP_SUMMARY
echo "**Actor**: ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY
echo "**Workflow Ref (branch)**: ${{ github.workflow_ref }}" >> $GITHUB_STEP_SUMMARY
echo -e "**Workflow Sha (commit)**: ${{ github.workflow_sha }}\n" >> $GITHUB_STEP_SUMMARY
echo "**Inputs**" >> $GITHUB_STEP_SUMMARY
echo -e "${{ toJson(inputs) }}\n" >> $GITHUB_STEP_SUMMARY
echo "**Release Tag**: ${{ inputs.release-tag }}" >> $GITHUB_STEP_SUMMARY
echo "*Note: Workflow Ref & Sha represent the branch and commit of the workflow defintion. This may not be the same as the branch/commit checked out supplying the code. The 'SHA or tag to apply' aka commit-identifier, is what specifies the code.*" >> $GITHUB_STEP_SUMMARY
TF-Apply:
name: Terraform Apply
runs-on: ubuntu-latest
environment: ${{ inputs.environment}}
defaults:
run:
working-directory: ${{ inputs.terraform-root }}
env:
TF_VAR_IACDeploymentRef: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
TF_VAR_release_name: ${{ inputs.release-tag }}
steps:
- id: get-role-arn
uses: OpenSesame/gha-oidc-access/get-role-arn@v2
with:
domain: ${{ inputs.oidc-domain }}
env: ${{ inputs.environment }}
ORG_READ_ONLY_SSH_KEY: ${{ secrets.ORG_READ_ONLY_SSH_KEY }}
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ steps.get-role-arn.outputs.role-arn }}
role-session-name: ${{ inputs.terraform-workspace }}-${{ inputs.environment }}-Run${{ github.run_id }}
aws-region: ${{ steps.get-role-arn.outputs.region }}
- name: Checkout Actions
uses: actions/checkout@v4
with:
ref: ${{ inputs.commit-identifier }}
- name: Configure Github Credentials
id: configure-credentials
shell: bash
run: |
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo '${{ secrets.ORG_READ_ONLY_SSH_KEY }}' > ~/.ssh/id_rsa
ssh-keyscan github.com > ~/.ssh/known_hosts
chmod 600 ~/.ssh/id_rsa ~/.ssh/known_hosts
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ inputs.terraform-version }}
terraform_wrapper: false # required to access terraform outputs after apply
- name: Init Terraform
run: terraform init -upgrade
- name: Select Workspace
run: terraform workspace select -or-create ${{ inputs.terraform-workspace }}
- name: Apply Terraform
run: terraform apply -auto-approve -input=false