-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtpr
More file actions
executable file
·55 lines (41 loc) · 1.12 KB
/
tpr
File metadata and controls
executable file
·55 lines (41 loc) · 1.12 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
#!/usr/bin/env bash
source "$(cd "${BASH_SOURCE[0]%/*}" || exit 1; pwd)/init.sh"
log_tf_title "[t]erraform [p]lan [r]eview"
[[ $# -gt 0 ]] && exit 1
LATEST_PLAN="$(get_latest_tf_plan_file)"
TF_OUTPUT=""
if [[ -n "${LATEST_PLAN}" ]]; then
log_message "Latest plan file:"
log_message "'${LATEST_PLAN}'"
log_message "❯ terraform show $(basename "${LATEST_PLAN}")"
TF_OUTPUT="$(terraform show "${LATEST_PLAN}")"
else
log_warning "No terraform plan files found in '${TFPLAN_DIR}'"
log_message "Running terraform plan"
log_message "❯ terraform plan"
TF_OUTPUT=$(tp)
fi
if [[ -z "${TF_OUTPUT}" ]]; then
log_error "ERROR: Terraform output is empty"
exit 1
fi
log_message "Reviewing terraform output..."
prompt="$(cat <<EOF
$(cat "${SCRIPT_DIR}/tpr-prompt.md")
## Terraform Output
\`\`\`md
${TF_OUTPUT}
\`\`\`
EOF
)"
if ! review=$(eval "$(ai_get_command aichat pro "${TERRAFORM_LIB_DIR}/tpr-prompt.md" "${prompt}")"); then
log_error "ERROR: AI chat command failed"
exit 1
fi
if [[ -z "${review}" ]]; then
log_error "ERROR: Generated review is empty"
exit 1
fi
log_newline
echo "${review}"
log_newline