From 65e1d506cc251d3085517dc96e5eaee6be3c9ceb Mon Sep 17 00:00:00 2001 From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com> Date: Wed, 2 Sep 2026 18:15:13 -0400 Subject: [PATCH] ci(compat): fail the build when compat-opentofu drifts from compat-terraform (#2898) Adds a CI job comparing the resource address lists in the two configs' main.tf files, failing on any unlisted one-sided resource. The 11 resources already only in compat-terraform (Application Auto Scaling, RDS, the CloudWatch alarm, the IAM managed-policy-attach path, IAM tag coverage, and the GuardDuty org feature) are recorded as pre-existing gaps in a new tf-only allowlist rather than ported, so the check also flags an allowlist entry once it stops being one-sided. Allowlists are directional (separate tf-only / otf-only files) so a resource that flips sides -- dropped from one config and re-added to the other under the same address -- is still reported as unreviewed drift instead of silently matching a stale entry from the old side. Closes #2263 --- .../ci/compat-opentofu-allowlist-otf-only.txt | 9 ++ .../ci/compat-opentofu-allowlist-tf-only.txt | 21 +++++ .github/ci/compat-opentofu-drift-check.py | 90 +++++++++++++++++++ .github/workflows/compatibility.yml | 17 ++++ compatibility-tests/compat-opentofu/main.tf | 9 +- compatibility-tests/compat-terraform/main.tf | 5 +- 6 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 .github/ci/compat-opentofu-allowlist-otf-only.txt create mode 100644 .github/ci/compat-opentofu-allowlist-tf-only.txt create mode 100755 .github/ci/compat-opentofu-drift-check.py diff --git a/.github/ci/compat-opentofu-allowlist-otf-only.txt b/.github/ci/compat-opentofu-allowlist-otf-only.txt new file mode 100644 index 0000000000..be5a996c5b --- /dev/null +++ b/.github/ci/compat-opentofu-allowlist-otf-only.txt @@ -0,0 +1,9 @@ +# Resource addresses allowed to exist ONLY in compat-opentofu/main.tf (not +# in compat-terraform/main.tf), checked by compat-opentofu-drift-check.py. +# One "type.name" per line; `#` starts a trailing comment. The reverse +# direction -- addresses allowed only in compat-terraform -- lives in +# compat-opentofu-allowlist-tf-only.txt; an address moving from one side to +# the other must move between these files or CI fails it as unreviewed drift. +# +# Empty for now: every currently-accepted gap runs the other way (see +# compat-opentofu-allowlist-tf-only.txt). diff --git a/.github/ci/compat-opentofu-allowlist-tf-only.txt b/.github/ci/compat-opentofu-allowlist-tf-only.txt new file mode 100644 index 0000000000..6a396b6693 --- /dev/null +++ b/.github/ci/compat-opentofu-allowlist-tf-only.txt @@ -0,0 +1,21 @@ +# Resource addresses allowed to exist ONLY in compat-terraform/main.tf (not +# in compat-opentofu/main.tf), checked by compat-opentofu-drift-check.py. +# One "type.name" per line; `#` starts a trailing comment. The reverse +# direction -- addresses allowed only in compat-opentofu -- lives in +# compat-opentofu-allowlist-otf-only.txt; an address moving from one side to +# the other must move between these files or CI fails it as unreviewed drift. +# +# These are pre-existing gaps, not deliberate provider-specific fixtures -- +# see https://github.com/floci-io/floci/issues/2263. Remove an entry once its +# resource (and matching bats coverage) is ported to compat-opentofu. +aws_appautoscaling_policy.ecs_alb_requests # Application Auto Scaling not yet in compat-opentofu +aws_appautoscaling_policy.ecs_cpu # Application Auto Scaling not yet in compat-opentofu +aws_appautoscaling_target.ecs_service # Application Auto Scaling not yet in compat-opentofu +aws_cloudwatch_metric_alarm.cpu # CloudWatch alarm coverage not yet in compat-opentofu +aws_db_instance.app # RDS coverage not yet in compat-opentofu +aws_guardduty_organization_configuration_feature.runtime_monitoring # GuardDuty org feature not yet in compat-opentofu +aws_iam_policy.tagged # IAM tag coverage not yet in compat-opentofu +aws_iam_role.managed_policy_attach # IAM managed-policy attach path not yet in compat-opentofu +aws_iam_role_policy_attachment.ec2_read_only # IAM managed-policy attach path not yet in compat-opentofu +aws_iam_role_policy_attachment.emr_service_role # IAM managed-policy attach path not yet in compat-opentofu +aws_iam_role.tagged # IAM tag coverage not yet in compat-opentofu diff --git a/.github/ci/compat-opentofu-drift-check.py b/.github/ci/compat-opentofu-drift-check.py new file mode 100755 index 0000000000..8e1647fd2d --- /dev/null +++ b/.github/ci/compat-opentofu-drift-check.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 +"""Fail if compat-terraform and compat-opentofu resource lists diverge unexpectedly. + +Usage: compat-opentofu-drift-check.py + +Parses the top-level `resource "TYPE" "NAME" {` blocks out of both +compatibility-tests/compat-terraform/main.tf and +compatibility-tests/compat-opentofu/main.tf and fails if either config +declares a resource address the other doesn't, unless that address is listed +in the matching direction's allowlist: + .github/ci/compat-opentofu-allowlist-tf-only.txt (terraform-only) + .github/ci/compat-opentofu-allowlist-otf-only.txt (opentofu-only) +(one "type.name" per line, `#`-comments and blank lines ignored). Allowlists +are directional so a resource that flips sides -- dropped from one config and +added to the other under the same address -- is still reported as unreviewed +drift rather than silently matching a stale entry from the old direction. + +Also fails if an allowlist contains an address that is no longer one-sided +in its direction, so accepted gaps get removed once they're closed instead +of accumulating. +""" +import re +import sys +from pathlib import Path + +REPO_ROOT = Path(__file__).resolve().parents[2] +TF_MAIN = REPO_ROOT / 'compatibility-tests/compat-terraform/main.tf' +OTF_MAIN = REPO_ROOT / 'compatibility-tests/compat-opentofu/main.tf' +ALLOWLIST_TF_ONLY = REPO_ROOT / '.github/ci/compat-opentofu-allowlist-tf-only.txt' +ALLOWLIST_OTF_ONLY = REPO_ROOT / '.github/ci/compat-opentofu-allowlist-otf-only.txt' + +RESOURCE_RE = re.compile(r'^resource\s+"([A-Za-z0-9_]+)"\s+"([A-Za-z0-9_]+)"', re.MULTILINE) + + +def resource_addresses(path): + return {f'{t}.{n}' for t, n in RESOURCE_RE.findall(path.read_text())} + + +def load_allowlist(path): + if not path.exists(): + return set() + addrs = set() + for line in path.read_text().splitlines(): + addr = line.split('#', 1)[0].strip() + if addr: + addrs.add(addr) + return addrs + + +def check_direction(label, only_in, allowlist_path): + """Report unexpected and stale entries for one direction. Returns True if clean.""" + allowed = load_allowlist(allowlist_path) + unexpected = sorted(only_in - allowed) + stale = sorted(allowed - only_in) + ok = True + if unexpected: + ok = False + print(f'::error::resources in {label} not allowlisted in ' + f'{allowlist_path.relative_to(REPO_ROOT)}:') + for a in unexpected: + print(f' {a}') + if stale: + ok = False + print(f'::error::stale entries in {allowlist_path.relative_to(REPO_ROOT)} ' + f'(no longer one-sided in this direction, remove them):') + for a in stale: + print(f' {a}') + return ok, allowed + + +def main(): + tf = resource_addresses(TF_MAIN) + otf = resource_addresses(OTF_MAIN) + + tf_ok, tf_allowed = check_direction('compat-terraform/main.tf but not compat-opentofu/main.tf', + tf - otf, ALLOWLIST_TF_ONLY) + otf_ok, otf_allowed = check_direction('compat-opentofu/main.tf but not compat-terraform/main.tf', + otf - tf, ALLOWLIST_OTF_ONLY) + + if not (tf_ok and otf_ok): + print('\nPort the resource to the other config, or add it to the matching-direction ' + 'allowlist if the gap is intentional.') + sys.exit(1) + print(f'compat-terraform and compat-opentofu resource lists match ' + f'({len(tf & otf)} shared, {len(tf_allowed)} tf-only allowlisted, ' + f'{len(otf_allowed)} otf-only allowlisted).') + + +if __name__ == '__main__': + main() diff --git a/.github/workflows/compatibility.yml b/.github/workflows/compatibility.yml index 00388d7950..5439837293 100644 --- a/.github/workflows/compatibility.yml +++ b/.github/workflows/compatibility.yml @@ -11,6 +11,9 @@ on: - 'docker/localstack-parity.sh' - 'compatibility-tests/**' - '.github/ci/compat-timing-report.py' + - '.github/ci/compat-opentofu-drift-check.py' + - '.github/ci/compat-opentofu-allowlist-tf-only.txt' + - '.github/ci/compat-opentofu-allowlist-otf-only.txt' - '.github/workflows/compatibility.yml' permissions: @@ -85,6 +88,20 @@ jobs: echo "$out" | grep -q "other.example.com" \ || { echo "::error::post-subcommand --endpoint-url flag was not honored over AWS_ENDPOINT_URL"; exit 1; } + compat-opentofu-drift-check: + name: compat / opentofu resource parity + runs-on: ubuntu-24.04-arm + timeout-minutes: 5 + steps: + - uses: actions/checkout@v7.0.1 + with: + sparse-checkout: | + compatibility-tests + .github/ci + + - name: Compare compat-terraform and compat-opentofu resource lists + run: python3 .github/ci/compat-opentofu-drift-check.py + build-native: name: Build native floci image runs-on: ubuntu-24.04-arm diff --git a/compatibility-tests/compat-opentofu/main.tf b/compatibility-tests/compat-opentofu/main.tf index 8b2fdc24d3..44a071333e 100644 --- a/compatibility-tests/compat-opentofu/main.tf +++ b/compatibility-tests/compat-opentofu/main.tf @@ -1,4 +1,11 @@ -# NOTE: Keep resource definitions in sync with ../compat-terraform/main.tf +# NOTE: Keep resource definitions in sync with ../compat-terraform/main.tf. +# Enforced by .github/ci/compat-opentofu-drift-check.py -- a resource added +# here and not there (or vice versa) fails CI unless listed in +# .github/ci/compat-opentofu-allowlist-tf-only.txt (or -otf-only.txt for the +# reverse direction) as a deliberate gap. Currently allowlisted: Application +# Auto Scaling, RDS, the CloudWatch alarm, the IAM managed-policy-attach +# path, IAM tag coverage, and the GuardDuty org feature -- see the allowlist +# files and https://github.com/floci-io/floci/issues/2263 for status. # ── S3 Bucket ────────────────────────────────────────────────────────────── resource "aws_s3_bucket" "app" { diff --git a/compatibility-tests/compat-terraform/main.tf b/compatibility-tests/compat-terraform/main.tf index be975a880e..457d9abb7b 100644 --- a/compatibility-tests/compat-terraform/main.tf +++ b/compatibility-tests/compat-terraform/main.tf @@ -1,4 +1,7 @@ -# NOTE: Keep resource definitions in sync with ../compat-opentofu/main.tf +# NOTE: Keep resource definitions in sync with ../compat-opentofu/main.tf. +# Enforced by .github/ci/compat-opentofu-drift-check.py -- a resource added +# here and not there (or vice versa) fails CI unless listed in +# .github/ci/compat-opentofu-allowlist-tf-only.txt as a deliberate gap. # -- S3 Bucket ------------------------------------------------------------------ resource "aws_s3_bucket" "app" {