-
Notifications
You must be signed in to change notification settings - Fork 751
Expand file tree
/
Copy pathReusableJobWorkflowPlanRemote.yml
More file actions
57 lines (54 loc) · 1.88 KB
/
ReusableJobWorkflowPlanRemote.yml
File metadata and controls
57 lines (54 loc) · 1.88 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
name: Terraform Plan Reusable Workflow
on:
workflow_call:
defaults:
run:
shell: bash
env:
#Below secrets are inherited from the parent workflow
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
jobs:
reusable-workflow-job:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./CustomerAlpha
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.10.4
- name: Print Branch Reference & Folder
run: echo The Current Branch Is $GITHUB_REF && pwd && ls -al
- name: Exporting AWS Credentials
run: |
export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
- name: Terraform Init, Format, Validate
run: |
terraform init
terraform fmt
terraform validate
- name: Creating Terraform Workspace
shell: bash
run: |
rm -rf .terraform && terraform init
terraform workspace select dev || terraform workspace new dev
terraform workspace select prod || terraform workspace new prod
terraform workspace list
- name: Terraform Plan
run: |
if [ ${GITHUB_REF} == 'refs/heads/development' ]; then
echo "Running Terraform Plan For Development Environment"
terraform workspace select dev
terraform plan --var-file=dev.tfvars
elif [ ${GITHUB_REF} == 'refs/heads/production' ]; then
echo "Running Terraform Plan For Production Environment"
terraform workspace select prod
terraform plan --var-file=prod.tfvars
else
echo "Nothing Is Deployed As The Branch Is Not Dev or Prod."
fi