-
Notifications
You must be signed in to change notification settings - Fork 77
71 lines (58 loc) · 2.05 KB
/
tf_code_validation_k8s.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
name: Terraform Kubernetes Workflow
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
# Inputs the workflow accepts.
inputs:
tfpath:
description: 'TF Code Path'
required: false
default: 'kubernetes'
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
tf_code_check:
name: Terraform Validation and Build
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
if: ${{ inputs.tfpath }}
steps:
- name: Checkout Code
uses: actions/[email protected]
- name: Install Minikube for GitHub Actions
uses: medyagh/[email protected]
- name: Install Kubectl tool for GitHub Actions
uses: Azure/setup-kubectl@v3
- name: Setup Terraform CLI
uses: hashicorp/[email protected]
- name: Terraform init and velidate and plan
run: |
echo `pwd`
echo "tfpath ${{ github.event.inputs.tfpath }}"
echo "** Running Terraform Init**"
terraform init
echo "** Running Terraform Validate**"
terraform validate
echo "** Running Terraform Plan**"
terraform plan
working-directory: ${{ github.event.inputs.tfpath }}
- name: Terraform Apply
run: |
echo "** Running Terraform Apply**"
terraform apply -auto-approve
working-directory: ${{ github.event.inputs.tfpath }}
- name: Verify Kubernetes Deployment
run: |
echo "** kubectl get deployment **"
kubectl get deployment -n k8s-ns-by-tf
- name: Terraform Destroy
run: |
echo "** Running Terraform Destroy**"
terraform plan -destroy
working-directory: ${{ github.event.inputs.tfpath }}