-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
82 lines (70 loc) · 2.68 KB
/
justfile
File metadata and controls
82 lines (70 loc) · 2.68 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
#!/usr/bin/env -S just --justfile
set quiet := true
set shell := ['bash', '-euo', 'pipefail', '-c']
terragrunt_args := "--non-interactive"
# Displayt he available commands
[private]
default:
just --list
[private]
log lvl msg *args:
gum log --time=rfc3339 --structured --level="{{ lvl }}" "{{ msg }}" {{ args }}
# Run the given command against the lab stack
lab *command:
terragrunt {{ terragrunt_args }} --working-dir "tf-stacks/dev" run --all --queue-include-dir "lab" -- {{ command }}
# Run the given command against the all the network stacks
network command *flags:
terragrunt {{ terragrunt_args }} --working-dir "tf-stacks/dev" run --all --queue-exclude-dir "lab" {{ flags }} -- {{ command }}
# Deoploy the lab and run bootstrap the network stack
bootstrap-lab: (lab "apply")
#!/usr/bin/env bash
set -euo pipefail
export TF_VAR_routeros_username=admin
export TF_VAR_routeros_password=admin
just network apply
# Reset network state then mark VMs for recreation
lab-reset: clear-network-state
#!/usr/bin/env bash
set -euo pipefail
regex="proxmox_virtual_environment_vm.devices|routeros_ip_dhcp_server_lease.leases"
for item in $(terragrunt --working-dir tf-stacks/dev/lab state list); do
if [[ $item =~ $regex ]]; then
terragrunt --working-dir tf-stacks/dev/lab run taint $item
fi
done
clear-stack-state stack:
#!/usr/bin/env bash
set -euo pipefail
mapfile -t items < <(terragrunt --working-dir "tf-stacks/{{ stack }}" state list)
if [[ ${#items[@]} -gt 0 ]]; then
terragrunt --working-dir "tf-stacks/{{ stack }}" state rm "${items[@]}"
fi
# Reset the terraform state on all network stacks
clear-network-state:
#!/usr/bin/env bash
set -euo pipefail
for stack in $(terragrunt --working-dir "tf-stacks/dev/network" list); do
mapfile -t items < <(terragrunt --working-dir "tf-stacks/dev/network/$stack" state list)
if [[ ${#items[@]} -gt 0 ]]; then
terragrunt --working-dir "tf-stacks/dev/network/$stack" state rm "${items[@]}"
fi
done
# Prepare all stacks for local development
develop:
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="tf-catalog/modules"
# Iterate through likely module directories (two and three levels deep)
for dir in $(ls -d "$ROOT_DIR"/* "$ROOT_DIR"/*/* 2>/dev/null); do
base="$(basename "$dir")"
# Skip directories starting with '_'
if [[ "$base" == _* ]]; then
continue
fi
if ls "$dir"/*.tofu >/dev/null 2>&1; then
echo "Initializing tofu module in: $dir"
(cd "$dir" && tofu init -upgrade)
fi
done
test:
cd test && go test -v