-
Notifications
You must be signed in to change notification settings - Fork 1
82 lines (74 loc) · 2.46 KB
/
deployment.yaml
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: Terraform (Plan||Apply)
run-name: Terraform ${{ inputs.terraform_action }} ${{ inputs.workspace }} by @${{ github.actor }}
on:
workflow_dispatch:
inputs:
workspace:
description: 'The workspace to terraform against'
required: true
type: choice
options:
- ""
- prod
terraform_action:
description: 'The terraform action to perform'
required: true
type: choice
options:
- plan
- apply
concurrency:
group: ${{ github.event.inputs.workspace }}-terraform
cancel-in-progress: false
permissions:
id-token: write
contents: read
env:
workspace: ${{ github.event.inputs.workspace }}
terraform_action: ${{ github.event.inputs.terraform_action }}
jobs:
terraform:
name: Run Terraform
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ./terraform/implementation/ecs
steps:
- name: Check Out Changes
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
role-session-name: githubDeploymentWorkflow
aws-region: ${{ secrets.AWS_REGION }}
- name: Terraform
env:
ACTION: ${{ env.terraform_action }}
BUCKET: ${{ secrets.TFSTATE_BUCKET }}
DYNAMODB_TABLE: ${{ secrets.TFSTATE_DYNAMODB_TABLE }}
OWNER: ${{ vars.OWNER }}
PROJECT: ${{ vars.PROJECT }}
REGION: ${{ secrets.AWS_REGION }}
WORKSPACE: ${{ env.workspace }}
shell: bash
run: |
echo "owner = \"$OWNER\"" >> $WORKSPACE.tfvars
echo "project = \"$PROJECT\"" >> $WORKSPACE.tfvars
echo "region = \"$REGION\"" >> $WORKSPACE.tfvars
terraform init \
-var-file="$WORKSPACE.tfvars" \
-backend-config "bucket=$BUCKET" \
-backend-config "dynamodb_table=$DYNAMODB_TABLE" \
-backend-config "region=$REGION" \
|| (echo "terraform init failed, exiting..." && exit 1)
terraform workspace select "$WORKSPACE"
if [ "$ACTION" == "plan" ]; then
terraform plan -var-file="$WORKSPACE.tfvars"
fi
if [ "$ACTION" == "apply" ]; then
terraform apply -auto-approve -var-file="$WORKSPACE.tfvars"
fi