-
Notifications
You must be signed in to change notification settings - Fork 1
94 lines (81 loc) · 2.49 KB
/
drift.yml
File metadata and controls
94 lines (81 loc) · 2.49 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
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
83
84
85
86
87
88
89
90
91
92
93
94
name: Scheduled Terraform Drift Detection
on:
schedule:
- cron: '0 2 * * *'
workflow_dispatch:
jobs:
drift-detection:
name: Check Drift
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
pull-requests: read
checks: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Terramate
uses: terramate-io/terramate-action@v3.2.0
- name: Install asdf
uses: asdf-vm/actions/setup@v3
- name: Install Terraform with asdf
run: |
asdf plugin add terraform
asdf install terraform
# # Comment this step out if not using AWS
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/github
env:
AWS_REGION: us-east-1
AWS_ACCOUNT_ID: ${{ vars.AWS_ACCOUNT_ID }}
- name: Verify AWS credentials
run: aws sts get-caller-identity
- name: Initialize Terraform
id: init
run: |
terramate run \
--parallel 1 \
-- \
terraform init -lock-timeout=5m
- name: Run drift detection
id: drift
run: |
terramate run \
--sync-drift-status \
--terraform-plan-file=drift.tfplan \
--continue-on-error \
--parallel 5 \
-- \
terraform plan -out drift.tfplan -detailed-exitcode -lock=false
env:
GITHUB_TOKEN: ${{ github.token }}
# # Optional step to reconcile (apply) the drifted stacks
# # This only applies to stack with a `reconcile` tag by default
# # Uncomment if desired
# - name: Check for auto reconcile
# id: find-drifted
# run: |
# terramate list \
# --status=drifted \
# --tags reconcile
#
# - name: Drift reconciliation
# id: drift-reconcile
# if: steps.find-drifted.outputs.stdout
# run: |
# terramate run \
# --status=drifted \
# --tags reconcile \
# --parallel 5 \
# --sync-deployment \
# --terraform-plan-file=drift.tfplan \
# -- \
# terraform apply -input=false -auto-approve -lock-timeout=5m drift.tfplan
# env:
# GITHUB_TOKEN: ${{ github.token }}