carlos / platform Public

ci: OpenTofu module tests beside make test, pinned and mirrored

.amadan/opentofu.sh runs every *.tftest.hcl under infra/ (33 files, 263
runs today), found by walking the tree: a file's module is the nearest
directory above it with a .tf file, and a test directory other than
tests/ goes in -test-directory. Each file is its own tofu test -filter,
eight at a time, and passes only with its own "... pass" line and
"Success! N passed, 0 failed." for N > 0, so a filter matching nothing
or a skipped run fails. Mock providers only; AWS credentials unset and
the shared config files /dev/null.

Pins: OpenTofu 1.13.9 (1.13 is the first to accept instance keys in
override targets, which nine region-host files use; 1.12.x, up to
1.12.12, cannot load them), hashicorp/aws 6.73.0, hashicorp/archive
2.8.1. All from the CI mirror under opentofu/, sha256-checked as
30-minio-contract does; the CLI config names one filesystem mirror and
no direct install, so no public registry is reachable at run time. The
tests run in a scratch copy of infra/ with the rest of the tree linked
beside it, because the census walks every file under infra/ while make
test runs.

10-gate installs tofu first and runs the suite beside make test: steps
run one after another, so beside the gate it costs only the install
(about 6 s warm). With tofu on PATH in CI, TestRegionGroupUserDataOpenTofu
now fails without it there (groupGuardBinary) instead of skipping.
make tofu-test runs it locally.

Needs the six files under opentofu/ in the mirror bucket before CI can
pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 80e9995ad143752843b914f50e0cf11060b30673 parent 4c600ff
6 files changed, +482 −9
  • .amadan/README.md +26 −2
  • .amadan/ci.d/10-gate +26 −2
  • .amadan/opentofu.sh +404 −0
  • AGENTS.md +11 −0
  • Makefile +10 −1
  • internal/provision/region_group_guards_test.go +5 −4
diff --git a/.amadan/README.md b/.amadan/README.md
index 2d7dddce4..fd6ab479e 100644
--- a/.amadan/README.md
+++ b/.amadan/README.md
@@ -33,10 +33,11 @@ no longer exists.
| `minio-contract` | `30-minio-contract` | MinIO on loopback, no container |
| `gofmt` | `10-gate` | repo-wide, via `make test` — see below |
-Seven checks have no ancestor; the deleted workflow never ran them. The
+Eight checks have no ancestor; the deleted workflow never ran them. The
first three were added on 2026-11-16 after a code audit found the gate
could not see them, the code-health ratchet's two and the race detector
-on 2026-11-17, and gitleaks on 2026-11-18.
+on 2026-11-17, gitleaks on 2026-11-18, and the OpenTofu module tests on
+2026-11-19.
| added | here | |
|---|---|---|
@@ -47,6 +48,7 @@ on 2026-11-17, and gitleaks on 2026-11-18.
| code-health record | `61-code-health-record` | the record against the merge base's copy; see below |
| race detector | `70-race` | `make race`: `go test -race` over the edge, rootaws and systemd packages and host's loop and lease tests, sharded like the gate; see below |
| `gitleaks` | `80-gitleaks` | `make gitleaks`: v8.30.1 over the tracked files, after proving that planted keys are still reported; see below |
+| OpenTofu module tests | `10-gate` | `.amadan/opentofu.sh`: every `*.tftest.hcl` under `infra/` with pinned tofu 1.13.9 and providers from the CI mirror, beside `make test`; see below |
## `govulncheck`: what turns it red
@@ -198,6 +200,28 @@ file.
The log names the file and line of a finding and never its value. It needs
the Go module proxy, to fetch gitleaks.
+## OpenTofu: what runs, and why inside the gate
+
+`.amadan/opentofu.sh` runs every `*.tftest.hcl` under `infra/`, found by
+walking the tree: a test file's module is the nearest directory above it
+with a `.tf` file, and a test directory other than `tests` is passed as
+`-test-directory`. Each file runs as its own `tofu test -filter`, eight
+at a time. A file passes only with its own `... pass` line and
+`Success! N passed, 0 failed.` for some N above zero, so a filter that
+matches nothing, or a run skipped after a failure, fails the step.
+
+It runs inside `10-gate`, not as a step of its own, because amadan runs
+steps one after another: a separate step would add its whole duration to
+every run, while beside `make test` (which waits more than it computes)
+it adds only the install, a few seconds on a warm cache.
+
+tofu and the providers come from the bucket `30-minio-contract` uses,
+under `opentofu/`, pinned by sha256 and cached in
+`.amadan-cache/opentofu-<arch>/`. The CLI config it writes names one
+filesystem mirror and no direct installation, so a run cannot reach a
+public registry. The tests use mock providers, with the AWS credential
+variables unset and the shared config files pointed at `/dev/null`.
+
## `gofmt`: ported by widening it, not by reproducing it
This section is the reason it was safe to delete the workflow, so it is
diff --git a/.amadan/ci.d/10-gate b/.amadan/ci.d/10-gate
index 9bde76e88..a9f432490 100755
--- a/.amadan/ci.d/10-gate
+++ b/.amadan/ci.d/10-gate
@@ -44,14 +44,38 @@
# -count=1 and -timeout 15m live in .amadan/test-gate.sh, on each go test
# line, with the Makefile's note on why; they are still in force here,
# just not written down twice.
+#
+# The OpenTofu module tests run here too, beside `make test`, rather than
+# as a step of their own: steps run one after another, and beside the
+# gate they cost only their install. `.amadan/opentofu.sh`'s header says
+# what they run, what turns them red, and where tofu comes from. The
+# install comes first because `make test` has Go tests that shell out to
+# tofu and fail in CI without it.
set -eu
. .amadan/go-toolchain.sh
-# The build runs beside the tests rather than before them: neither needs
-# the other, and the gate's wall clock is whichever finishes last.
+tofu_dir=$(mktemp -d "${TMPDIR:-/tmp}/carlos-opentofu-XXXXXX")
+trap 'rm -rf "$tofu_dir"' EXIT
+trap 'exit 1' INT TERM
+.amadan/opentofu.sh install "$tofu_dir"
+PATH=$tofu_dir/bin:$PATH
+TF_CLI_CONFIG_FILE=$tofu_dir/tofurc
+export PATH TF_CLI_CONFIG_FILE
+
+# The build and the tofu tests run beside the Go tests rather than before
+# them: none needs another, and the gate's wall clock is whichever
+# finishes last. The tofu log is held back and printed whole at the end,
+# so it does not interleave with the gate's.
go build ./... &
build=$!
+.amadan/opentofu.sh test >"$tofu_dir/test.log" 2>&1 &
+tofu=$!
status=0
make test || status=$?
wait "$build" || status=1
+tofu_status=0
+wait "$tofu" || tofu_status=$?
+echo "=== opentofu ==="
+cat "$tofu_dir/test.log"
+[ "$tofu_status" -eq 0 ] || status=1
exit "$status"
diff --git a/.amadan/opentofu.sh b/.amadan/opentofu.sh
new file mode 100755
index 000000000..0b1f009f4
--- /dev/null
+++ b/.amadan/opentofu.sh
@@ -0,0 +1,404 @@
+#!/bin/sh
+# The OpenTofu module tests: every *.tftest.hcl under infra/, run by a
+# pinned tofu against mock providers, with no AWS credentials and no
+# public registry anywhere in sight.
+#
+# .amadan/opentofu.sh install DIR pinned tofu and providers into DIR
+# .amadan/opentofu.sh test every test file, tofu from PATH
+# .amadan/opentofu.sh both, in a scratch directory
+#
+# `make tofu-test` is the last form. CI runs the first two from
+# `10-gate`, beside `make test`, and the reason is wall time: amadan runs
+# the ci.d steps one after another, so a step of its own would add its
+# whole duration to every run. The gate's wall clock is `make test`
+# (about 220 s), which mostly waits rather than computes. This suite
+# finishes well inside it. Measured on docs-t1 on 2026-11-19, a busy
+# shared 16-core box: 170 s one file at a time, 78 s with eight workers,
+# and no file longer than 20 s alone (region-host's group.tftest.hcl).
+# So beside the gate it costs only the install, which comes before
+# `make test` (below): about 6 s on a warm cache, mostly tofu unzipping
+# the AWS provider.
+#
+# The install comes first because two Go tests in `make test` shell out
+# to tofu: internal/provision's TestRegionGroupUserDataOpenTofu (and,
+# when the media-conversion branch lands, internal/mediaaws'
+# TestModuleRenderIsCurrent). They skip without tofu on a laptop and
+# fail without it in CI, so the gate puts the pinned tofu on PATH, and
+# TF_CLI_CONFIG_FILE at the mirror below, before `make test` starts.
+#
+# WHAT RUNS. Every *.tftest.hcl under infra/, found by walking the tree,
+# so a new module or test directory is covered without touching this
+# file. A test file's module is the nearest directory at or above it
+# that holds a .tf or .tofu file; the path between them is the test
+# directory, passed as -test-directory unless it is the default `tests`
+# (infra/modules/region-host/tests/managed_fleets is the one that needs
+# it today). Each (module, test directory) is initialised once with
+# `tofu init -backend=false`, then every file runs as its own
+# `tofu test -filter=<file>`, eight at a time (OPENTOFU_JOBS).
+#
+# WHAT TURNS IT RED. A file passes only when tofu exits 0, prints the
+# file's own "... pass" line, and ends with "Success! N passed, 0
+# failed." for some N above zero. So a file that a filter typo, a rename
+# or a skipped run leaves unexercised fails: `tofu test` reports a
+# filter that matches nothing as "Success! 0 passed", and a run skipped
+# after an earlier failure as "N skipped".
+#
+# NO AWS. The tests use mock_provider "aws" only. The AWS credential and
+# profile variables are unset, the shared config and credentials files
+# are /dev/null, and instance metadata is off, so a test that lost its
+# mock could not reach an account even if a runner had one.
+#
+# THE PINS. OpenTofu 1.13.9, the newest release on 2026-11-19 (its 1.13
+# series is supported until 2027-08-01). 1.13.0 is the floor:
+# `tofu test` takes instance keys in override_data and
+# override_resource targets (data.aws_eip.group["eu-west-1a"]) from 1.13
+# on (opentofu#4067). Nine region-host test files use them, and 1.12.x,
+# up to 1.12.12, refuses to load the module's tests at all.
+#
+# The providers are those the modules require: hashicorp/aws (>= 6.0;
+# box-fence-writer says >= 5.0) and hashicorp/archive (>= 2.4, the
+# media-engine module on the media-conversion branch). Pinned to the
+# newest of each on 2026-11-19: aws 6.73.0, archive 2.8.1. The modules'
+# own constraints stay open-ended; this pin is what CI tests them with.
+#
+# THE SOURCE. Never a public registry at run time. Every file comes from
+# our own mirror (the bucket 30-minio-contract uses, under opentofu/),
+# is checked against the sha256 below after download and again on every
+# cache hit, and a mismatch refuses to run. The CLI config this writes
+# names one filesystem mirror and no direct installation, so tofu cannot
+# reach a registry even for a provider nobody pinned: it fails instead.
+#
+# The digests are upstream's. tofu: the release's tofu_1.13.9_SHA256SUMS
+# from the opentofu/opentofu GitHub release. Providers: the packages
+# registry.opentofu.org serves (opentofu/terraform-provider-* release
+# assets), which `tofu providers mirror` fetched and verified against
+# the registry's signing key, and whose digests match the registry's
+# published shasum. HashiCorp's own zips of the same versions are
+# packed differently and have other digests; these are not those.
+#
+# Bump a pin by fetching the new upstream files, checking them against
+# upstream's sums, uploading them to the mirror, and re-deriving the
+# digests here.
+#
+# THE CACHE. As in 30-minio-contract, an untracked dot-directory in the
+# checkout: .amadan-cache/opentofu-<arch>/, kept between jobs, never
+# trusted without its digests. Each run unpacks into its own scratch
+# directory: the tofu binary, and the providers unzipped once by tofu
+# itself (a bootstrap `tofu init` into a plugin cache). That plugin
+# cache then serves as an unpacked filesystem mirror, which tofu links
+# rather than copies, so the 800 MB AWS provider exists once per run, not
+# once per module.
+#
+# NOTHING WRITTEN UNDER infra/. tofu init writes a .terraform.lock.hcl
+# beside each module, and internal/provision's census walks every regular
+# file under infra/, dotfiles included, while `make test` runs beside
+# this. So the tests run in a scratch tree: a copy of infra/ (less any
+# .terraform directories and lock files a developer has), with every
+# other top-level entry of the checkout symlinked beside it, so a test's
+# file("../../../internal/...") still finds the real file. The
+# .terraform directories go to scratch too (TF_DATA_DIR).
+set -eu
+
+OPENTOFU_VERSION=1.13.9
+AWS_VERSION=6.73.0
+ARCHIVE_VERSION=2.8.1
+
+# OPENTOFU_MIRROR exists so the step can be checked against a local copy
+# of the mirror (file://...) before anything is uploaded. The digests
+# hold whatever the source.
+MIRROR=${OPENTOFU_MIRROR:-https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu}
+
+root=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd)
+
+case "$(uname -m)" in
+x86_64 | amd64)
+ arch=amd64
+ tofu_sha=b34b327cc1ef07178207b6f2cd1f5276537d3e5b7be316500f6dac50d4c0a857
+ aws_sha=a61f8e114e5233e63b8d2b034b1ad59a220e532fa34aaaa63eec6bad73a0ca21
+ archive_sha=167dcb2f3dfef941d300e4899c6b1852592e98cd5e20782289369bf0c81512f0
+ ;;
+aarch64 | arm64)
+ arch=arm64
+ tofu_sha=5dc196dde75b667e4806d358310ec96742774cd0993c54c1237efee5644b69b8
+ aws_sha=ba50cb9245a579285169565995e20bebb410e7f4d4181dc7de1205877fe04728
+ archive_sha=a77922d3edcc1288d52e5d225e0b98d6ae8b3ef8ef4f27a40a6c11136489b886
+ ;;
+*)
+ echo "no pinned OpenTofu build for $(uname -m): add one above, do not guess" >&2
+ exit 1
+ ;;
+esac
+
+fetch_pinned() {
+ fp_name=$1
+ fp_url=$2
+ fp_want=$3
+ fp_dest=$4
+
+ if [ -f "$fp_dest" ] && [ "$(sha256sum <"$fp_dest" | cut -d' ' -f1)" = "$fp_want" ]; then
+ echo " $fp_name: cached, digest verified"
+ return 0
+ fi
+
+ echo " $fp_name: downloading $fp_url"
+ mkdir -p "$(dirname "$fp_dest")"
+ curl -sfL --retry 3 -o "$fp_dest.part" "$fp_url"
+
+ fp_got=$(sha256sum <"$fp_dest.part" | cut -d' ' -f1)
+ if [ "$fp_got" != "$fp_want" ]; then
+ rm -f "$fp_dest.part"
+ echo "$fp_name digest mismatch: refusing to run" >&2
+ echo " want $fp_want" >&2
+ echo " got $fp_got" >&2
+ echo " from $fp_url" >&2
+ exit 1
+ fi
+ mv "$fp_dest.part" "$fp_dest"
+ echo " $fp_name: downloaded, digest verified"
+}
+
+# install DIR: DIR/bin/tofu, DIR/plugins (an unpacked provider mirror)
+# and DIR/tofurc (a CLI config naming that mirror and nothing else).
+install() {
+ dir=$1
+ for tool in curl sha256sum tar; do
+ command -v "$tool" >/dev/null 2>&1 || {
+ echo "$tool is required by this step but was not found on PATH" >&2
+ exit 1
+ }
+ done
+ echo "opentofu: $arch, tofu $OPENTOFU_VERSION, aws $AWS_VERSION, archive $ARCHIVE_VERSION"
+
+ cache=$root/.amadan-cache/opentofu-$arch
+ tarball=tofu_${OPENTOFU_VERSION}_linux_$arch.tar.gz
+ aws_zip=terraform-provider-aws_${AWS_VERSION}_linux_$arch.zip
+ archive_zip=terraform-provider-archive_${ARCHIVE_VERSION}_linux_$arch.zip
+ packed=$cache/providers/registry.opentofu.org/hashicorp
+ fetch_pinned tofu "$MIRROR/$tarball" "$tofu_sha" "$cache/$tarball"
+ fetch_pinned aws "$MIRROR/$aws_zip" "$aws_sha" "$packed/aws/$aws_zip"
+ fetch_pinned archive "$MIRROR/$archive_zip" "$archive_sha" "$packed/archive/$archive_zip"
+
+ mkdir -p "$dir/bin" "$dir/plugins" "$dir/bootstrap"
+ tar -xzf "$cache/$tarball" -C "$dir/bin" tofu
+ got=$("$dir/bin/tofu" version | head -n 1)
+ if [ "$got" != "OpenTofu v$OPENTOFU_VERSION" ]; then
+ echo "the pinned tarball says \"$got\", not OpenTofu v$OPENTOFU_VERSION" >&2
+ exit 1
+ fi
+
+ # The bootstrap: one init against the packed zips, which tofu unpacks
+ # into its plugin cache. Its own lock file lands in DIR/bootstrap.
+ cat >"$dir/bootstrap.tofurc" <<-EOF
+ provider_installation {
+ filesystem_mirror {
+ path = "$cache/providers"
+ }
+ }
+ plugin_cache_dir = "$dir/plugins"
+ EOF
+ cat >"$dir/bootstrap/main.tf" <<-EOF
+ terraform {
+ required_providers {
+ aws = { source = "hashicorp/aws", version = "$AWS_VERSION" }
+ archive = { source = "hashicorp/archive", version = "$ARCHIVE_VERSION" }
+ }
+ }
+ EOF
+ if ! (cd "$dir/bootstrap" &&
+ TF_CLI_CONFIG_FILE="$dir/bootstrap.tofurc" TF_DATA_DIR="$dir/bootstrap/.terraform" \
+ "$dir/bin/tofu" init -backend=false -input=false -no-color >"$dir/bootstrap.log" 2>&1); then
+ cat "$dir/bootstrap.log" >&2
+ echo "unpacking the pinned providers failed" >&2
+ exit 1
+ fi
+
+ cat >"$dir/tofurc" <<-EOF
+ provider_installation {
+ filesystem_mirror {
+ path = "$dir/plugins"
+ }
+ }
+ EOF
+ echo " installed in $dir"
+}
+
+# The module a test file belongs to: the nearest directory at or above
+# it holding a .tf or .tofu file.
+module_of() {
+ mo_dir=$(dirname "$1")
+ while [ "$mo_dir" != . ] && [ "$mo_dir" != / ]; do
+ for mo_f in "$mo_dir"/*.tf "$mo_dir"/*.tofu; do
+ if [ -f "$mo_f" ]; then
+ echo "$mo_dir"
+ return 0
+ fi
+ done
+ mo_dir=$(dirname "$mo_dir")
+ done
+ echo "no module above $1" >&2
+ return 1
+}
+
+test_all() {
+ command -v tofu >/dev/null 2>&1 || {
+ echo "tofu is not on PATH: run '.amadan/opentofu.sh install DIR' and put DIR/bin first" >&2
+ exit 1
+ }
+ : "${TF_CLI_CONFIG_FILE:?set TF_CLI_CONFIG_FILE to the tofurc that install wrote}"
+ got=$(tofu version | head -n 1)
+ if [ "$got" != "OpenTofu v$OPENTOFU_VERSION" ]; then
+ echo "tofu on PATH is \"$got\"; this step pins OpenTofu v$OPENTOFU_VERSION" >&2
+ exit 1
+ fi
+
+ unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN \
+ AWS_SECURITY_TOKEN AWS_PROFILE AWS_DEFAULT_PROFILE AWS_ROLE_ARN \
+ AWS_WEB_IDENTITY_TOKEN_FILE AWS_CONTAINER_CREDENTIALS_RELATIVE_URI \
+ AWS_CONTAINER_CREDENTIALS_FULL_URI
+ AWS_CONFIG_FILE=/dev/null
+ AWS_SHARED_CREDENTIALS_FILE=/dev/null
+ AWS_EC2_METADATA_DISABLED=true
+ TF_IN_AUTOMATION=1
+ CHECKPOINT_DISABLE=1
+ export AWS_CONFIG_FILE AWS_SHARED_CREDENTIALS_FILE AWS_EC2_METADATA_DISABLED \
+ TF_IN_AUTOMATION CHECKPOINT_DISABLE
+
+ run=$(mktemp -d "${TMPDIR:-/tmp}/carlos-opentofu-test-XXXXXX")
+ trap 'rm -rf "$run"' EXIT
+ trap 'exit 1' INT TERM
+ tree=$run/tree
+ mkdir -p "$run/data" "$run/logs" "$tree"
+
+ # The scratch tree: infra/ copied, everything else linked.
+ for entry in "$root"/*; do
+ [ "$(basename "$entry")" = infra ] || ln -s "$entry" "$tree/"
+ done
+ (cd "$root" && tar --exclude=.terraform --exclude=.terraform.lock.hcl -cf - infra) |
+ (cd "$tree" && tar -xf -)
+
+ cd "$tree"
+ find infra -name '*.tftest.hcl' | LC_ALL=C sort >"$run/files"
+ if [ ! -s "$run/files" ]; then
+ echo "no *.tftest.hcl under infra/: the walk is broken, or the tests moved" >&2
+ exit 1
+ fi
+
+ # jobs: one line per test file. suites: one per (module, test dir).
+ : >"$run/jobs"
+ : >"$run/suites"
+ while IFS= read -r file; do
+ module=$(module_of "$file")
+ rel=${file#"$module"/}
+ testdir=$(dirname "$rel")
+ [ "$testdir" = . ] && testdir=tests
+ key="$module $testdir"
+ suite=$(grep -n -x -F "$key" "$run/suites" | cut -d: -f1 || true)
+ if [ -z "$suite" ]; then
+ echo "$key" >>"$run/suites"
+ suite=$(wc -l <"$run/suites" | tr -d ' ')
+ fi
+ printf '%s %s %s %s\n' "$suite" "$module" "$testdir" "$rel" >>"$run/jobs"
+ done <"$run/files"
+ nfiles=$(wc -l <"$run/jobs" | tr -d ' ')
+ nsuites=$(wc -l <"$run/suites" | tr -d ' ')
+ echo "opentofu: $nfiles test files in $nsuites suites, $(tofu version | head -n 1)"
+
+ start=$(date +%s)
+ n=0
+ while read -r module testdir; do
+ n=$((n + 1))
+ flag=
+ [ "$testdir" = tests ] || flag=-test-directory=$testdir
+ # shellcheck disable=SC2086 # $flag is empty or one word
+ if ! (cd "$module" && TF_DATA_DIR="$run/data/$n" \
+ tofu init -backend=false -input=false -no-color $flag >"$run/logs/init-$n.log" 2>&1); then
+ cat "$run/logs/init-$n.log"
+ echo "opentofu: tofu init failed in $module ($testdir)" >&2
+ exit 1
+ fi
+ done <"$run/suites"
+ echo " initialised in $(($(date +%s) - start)) s"
+
+ # Each file in its own process, OPENTOFU_JOBS at a time.
+ OPENTOFU_RUN=$run
+ export OPENTOFU_RUN
+ awk '{ print NR }' "$run/jobs" |
+ xargs -P "${OPENTOFU_JOBS:-8}" -n 1 "$root/.amadan/opentofu.sh" _one || true
+
+ failed=0
+ n=0
+ while read -r suite module testdir rel; do
+ n=$((n + 1))
+ log=$run/logs/$n.log
+ rc=$(cat "$run/logs/$n.rc" 2>/dev/null || echo missing)
+ secs=$(cat "$run/logs/$n.secs" 2>/dev/null || echo '?')
+ summary=$(grep -E '^(Success|Failure)!' "$log" 2>/dev/null | tail -n 1 || true)
+ if [ "$rc" = 0 ] &&
+ grep -q -x -F "$rel... pass" "$log" &&
+ echo "$summary" | grep -q -E '^Success! [1-9][0-9]* passed, 0 failed\.$'; then
+ printf ' ok %4s s %s/%s %s\n' "$secs" "$module" "$rel" "$summary"
+ else
+ failed=$((failed + 1))
+ printf ' FAIL %4s s %s/%s exit %s %s\n' "$secs" "$module" "$rel" "$rc" "$summary"
+ sed 's/^/ /' "$log" 2>/dev/null || true
+ fi
+ done <"$run/jobs"
+
+ echo "opentofu: $nfiles files in $(($(date +%s) - start)) s"
+ if [ "$failed" -ne 0 ]; then
+ echo "opentofu: $failed of $nfiles test files did not pass (a file passes only with its own" >&2
+ echo "\"... pass\" line and \"Success! N passed, 0 failed.\", N > 0, so a skip fails too)" >&2
+ exit 1
+ fi
+ echo "opentofu: PASS"
+}
+
+# One test file: the Nth line of the job list.
+one() {
+ run=$OPENTOFU_RUN
+ line=$(sed -n "${1}p" "$run/jobs")
+ n=$1
+ # shellcheck disable=SC2086 # four space-separated fields, no spaces inside
+ set -- $line
+ suite=$1 module=$2 testdir=$3 rel=$4
+ flag=
+ [ "$testdir" = tests ] || flag=-test-directory=$testdir
+ t0=$(date +%s)
+ rc=0
+ # shellcheck disable=SC2086 # $flag is empty or one word
+ (cd "$run/tree/$module" && TF_DATA_DIR="$run/data/$suite" \
+ tofu test -no-color $flag -filter="$rel" >"$run/logs/$n.log" 2>&1) || rc=$?
+ echo "$(($(date +%s) - t0))" >"$run/logs/$n.secs"
+ echo "$rc" >"$run/logs/$n.rc"
+}
+
+case "${1:-}" in
+install)
+ [ $# -eq 2 ] || {
+ echo "usage: $0 install DIR" >&2
+ exit 2
+ }
+ install "$2"
+ ;;
+test)
+ test_all
+ ;;
+_one)
+ one "$2"
+ ;;
+'')
+ dir=$(mktemp -d "${TMPDIR:-/tmp}/carlos-opentofu-XXXXXX")
+ # test_all sets its own EXIT trap; the subshell keeps this one.
+ trap 'rm -rf "$dir"' EXIT
+ trap 'exit 1' INT TERM
+ install "$dir"
+ PATH=$dir/bin:$PATH
+ TF_CLI_CONFIG_FILE=$dir/tofurc
+ export PATH TF_CLI_CONFIG_FILE
+ (test_all)
+ ;;
+*)
+ echo "usage: $0 [install DIR | test]" >&2
+ exit 2
+ ;;
+esac
diff --git a/AGENTS.md b/AGENTS.md
index 38fcc3754..43fca6bdf 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -280,6 +280,17 @@ anything.
- **GitHub follows amadan.** If GitHub's `main` is behind amadan's after a
merge, fast-forward it from amadan; never the other way round, and
never with anything that is not already on amadan's `main`.
+- **The OpenTofu module tests run in CI**, beside `make test` in
+ `10-gate` (`make tofu-test` locally): every `*.tftest.hcl` under
+ `infra/`, mock providers only, AWS credentials unset. A new module or
+ test directory is found by walking the tree. tofu (1.13.9) and the AWS
+ and archive providers are pinned by sha256 and come from our CI mirror,
+ never a public registry; `.amadan/opentofu.sh`'s header has the pins
+ and the rules. OpenTofu before 1.13 cannot load region-host's tests
+ (instance keys in `override_data` targets), so a local 1.12 `tofu test`
+ there fails to load, not to pass. With tofu on PATH in CI, Go tests
+ that shell out to it fail rather than skip when it is missing
+ (`groupGuardBinary`).
- `40-staticcheck` runs `make staticcheck` (v0.8.2, pinned): the `SA`
bug checks, with the families still off listed in `staticcheck.conf`.
It is green only with no output at all, and it is not part of
diff --git a/Makefile b/Makefile
index f419d81df..bfc45d49b 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ LDFLAGS := -s -w -X github.com/carlosframework/platform/internal/version.Build=$
GOOS ?=
GOARCH ?=
-.PHONY: test build build-console fmt staticcheck govulncheck gitleaks race census-card census-propose code-health code-health-record console-mockup-kit parity-doc
+.PHONY: test build build-console fmt staticcheck govulncheck gitleaks race tofu-test census-card census-propose code-health code-health-record console-mockup-kit parity-doc
# The build gate: vet, format, tests. `.amadan/ci.d/10-gate` runs this same
# target, so what CI checks and what you check are one definition.
@@ -128,6 +128,15 @@ gitleaks:
race:
GATE_RACE=1 .amadan/test-gate.sh
+# The OpenTofu module tests, as CI runs them beside `make test` in
+# .amadan/ci.d/10-gate: every *.tftest.hcl under infra/, with the pinned
+# tofu and providers from the CI mirror and no AWS credentials. The
+# header of .amadan/opentofu.sh says what runs and what turns it red.
+# The tofu on your PATH is not used: OpenTofu before 1.13 cannot load
+# region-host's tests.
+tofu-test:
+ .amadan/opentofu.sh
+
# Regenerates docs/console-mockup-kit/shell.html: a signed-in console page
# from the real templates with every stylesheet inlined and an empty
# <main> to draw a mockup in (docs/console-mockup-kit/README.md).
diff --git a/internal/provision/region_group_guards_test.go b/internal/provision/region_group_guards_test.go
index 3d00e35d7..2103b8a6a 100644
--- a/internal/provision/region_group_guards_test.go
+++ b/internal/provision/region_group_guards_test.go
@@ -129,11 +129,12 @@ func groupGuardBinary(t *testing.T, name string) string {
return ""
}
+// TestRegionGroupUserDataOpenTofu renders the group user data with tofu
+// itself. CI's gate puts the pinned tofu on PATH (.amadan/opentofu.sh), so
+// there a missing tofu fails; elsewhere it skips, and the pure-Go
+// TestRegionGroupUserDataSize still holds the 13107 B cap.
func TestRegionGroupUserDataOpenTofu(t *testing.T) {
- tofu, err := exec.LookPath("tofu")
- if err != nil {
- t.Skipf("OpenTofu witness unavailable: %v; the pure-Go TestRegionGroupUserDataSize guard still enforces the 13107 B cap in CI; run locally with tofu on PATH: go test ./internal/provision -run '^TestRegionGroupUserDataOpenTofu$' -count=1 -v", err)
- }
+ tofu := groupGuardBinary(t, "tofu")
config := groupDevConfig(t)
for key, value := range config {
config[key] = "'" + strings.ReplaceAll(value, "'", "'\"'\"'") + "'"