-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (66 loc) · 2.15 KB
/
terraform-destroy.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
name: destroy
on:
workflow_dispatch:
jobs:
init:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: hashicorp/setup-terraform@v2
- uses: actions/cache@v3
with:
path: |
.terraform/**
.terraform.lock.hcl
plan.cache
key: terraform-lock-${{ steps.extract_branch.outputs.branch }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY}}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY}}
aws-region: ${{ secrets.AWS_REGION }}
- name: Terraform Init
id: init
run: |
cat main.tf
terraform init
destroy:
runs-on: ubuntu-latest
needs: init
# if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v3
- uses: hashicorp/setup-terraform@v2
# with:
# terraform_version: 1.3.0
# cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- uses: actions/cache@v3
with:
path: |
.terraform/**
.terraform.lock.hcl
plan.cache
key: terraform-lock-${{ github.event.workflow_run.head_branch }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY}}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY}}
aws-region: ${{ secrets.AWS_REGION }}
# - name: Terraform Plan
# id: plan
# run: terraform plan -no-color -out plan.cache
# - name: encrypt cache
# run: zip --password "${{ secrets.ZIP_PASSWORD }}" plan.zip plan.cache
# - name: "Upload Artifact"
# uses: actions/upload-artifact@v2
# with:
# name: plan-cache
# path: plan.cache
- name: Terraform destroy
run: terraform destroy -auto-approve