Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions aws/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ This repository provides a set of reusable, **self-contained Terraform modules**

---

## Prerequisites

Before using these modules, ensure you have the following tools installed:

- [Terraform](https://developer.hashicorp.com/terraform/install) (>= 1.0)
- [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
- [kubectl](https://kubernetes.io/docs/tasks/tools/) (required for cleaning up Karpenter NodeClaims)

---

## Modular Architecture

Each module is designed to be used independently. You can compose them in any way that fits your use case.
Expand Down
14 changes: 12 additions & 2 deletions aws/modules/karpenter-nodepool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ resource "terraform_data" "destroyer" {

command = <<-EOF
set -euo pipefail
nodeclaims=$(kubectl --kubeconfig <(echo "$${KUBECONFIG_DATA}") get nodeclaims -l "karpenter.sh/nodepool=$${NODEPOOL_NAME}" -o name)

if [ -z "$${KUBECONFIG_DATA}" ]; then
echo "Error: KUBECONFIG_DATA is empty"
exit 1
fi

kubeconfig_file=$(mktemp)
echo "$${KUBECONFIG_DATA}" > "$${kubeconfig_file}"
trap "rm -f $${kubeconfig_file}" EXIT
Copy link
Contributor

@alex-hunt-materialize alex-hunt-materialize Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This trap line should happen before the write on the line above.
The file name should also be quoted inside the trap command.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, i kinda guessed if doing everything in one line is causing the issue. I will wait for @jubrad to reply, incase he knows exact steps to repro this. Otherwise i would just get rid of this file change.


nodeclaims=$(kubectl --kubeconfig "$${kubeconfig_file}" get nodeclaims -l "karpenter.sh/nodepool=$${NODEPOOL_NAME}" -o name)
if [ -n "$${nodeclaims}" ]; then
echo "$${nodeclaims}" | xargs kubectl --kubeconfig <(echo "$${KUBECONFIG_DATA}") delete --wait=true
echo "$${nodeclaims}" | xargs kubectl --kubeconfig "$${kubeconfig_file}" delete --wait=true
fi
EOF
interpreter = ["/usr/bin/env", "bash", "-c"]
Expand Down