-
Notifications
You must be signed in to change notification settings - Fork 77
62 lines (53 loc) · 1.73 KB
/
tf_code_validation_aws.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
name: Terraform AWS Workflow
on:
workflow_call:
workflow_dispatch:
# Inputs the workflow accepts.
inputs:
tfpath:
description: 'TF File Path'
required: false
default: 'aws_samples/create_ec2'
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
tf_code_check:
name: Terraform Validation and Build
runs-on: ubuntu-latest
if: ${{ inputs.tfpath }}
steps:
- name: Checkout tf code in runner environment
uses: actions/[email protected]
- name: Configure AWS Credentials Action For GitHub Actions
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Setup Terraform CLI
uses: hashicorp/[email protected]
- name: Terraform init and validate
run: |
echo `pwd`
echo "tfpath ${{ github.event.inputs.tfpath }}"
echo "** Running Terraform Init**"
terraform init
echo "** Running Terraform Validate**"
terraform validate
working-directory: ${{ github.event.inputs.tfpath }}
- name: Terraform plan and apply
run: |
echo `pwd`
echo "tfpath ${{ github.event.inputs.tfpath }}"
echo "** Running Terraform Plan**"
terraform plan
echo "** Running Terraform Apply**"
terraform apply -auto-approve
working-directory: ${{ github.event.inputs.tfpath }}
- name: Terraform Destroy
run: |
echo "** Running Terraform Destroy**"
terraform destroy -auto-approve
working-directory: ${{ github.event.inputs.tfpath }}