test: rotate Terraform E2E identities to reduce RBAC flakiness - #328
Merged
Mani Bindra (maniSbindra) merged 3 commits intoAug 27, 2026
Conversation
Alternate Linux Terraform E2E tests between two service principals and restore the RBAC de-propagation delay to 15 seconds.
Reduce the post-detachment propagation delay from 15 seconds to 1 second after validating the alternating service principal setup.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces Linux Terraform E2E flakiness caused by stale Azure RBAC state by alternating Terraform E2E tests between a primary and an alternate service principal, and wiring the alternate credentials through provisioning scripts and the GitHub Actions workflow.
Changes:
- Add Terraform E2E identity selection logic (primary/alternate) and update Terraform E2E tests to use it.
- Extend SP provisioning scripts to support a
terraform_linux_alttarget and targeted provisioning safeguards. - Update the E2E workflow to preflight-check both Terraform identities and pass alternate credentials into Linux Terraform E2E runs.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Taskfile.yml | Adds a focused unit test run for the identity selector in the standard test task. |
| scripts/create-e2e-service-principals.sh | Adds --target support, introduces terraform_linux_alt, and prevents targeted runs from overwriting an existing output file. |
| scripts/create-e2e-service-principals.ps1 | Mirrors targeted provisioning and terraform_linux_alt support for PowerShell. |
| pkg/usecase/mpfService.go | Reduces the post-detach RBAC propagation sleep from 45s to 1s. |
| e2eTests/e2eTerraformWithImportAndTargeting_test.go | Switches Terraform E2E tests to use the Terraform identity selector args helper. |
| e2eTests/e2eTerraformInvalid_test.go | Switches Terraform invalid-path E2E tests to use the Terraform identity selector args helper. |
| e2eTests/e2eTerraformIdentity_test.go | Adds identity selection logic + selector unit tests. |
| e2eTests/e2eTerraformAuthPermissionMismatch_test.go | Switches Terraform E2E test to use the Terraform identity selector args helper. |
| e2eTests/e2eTerraformAuthorizationRequestDenied_test.go | Switches Terraform E2E test to use the Terraform identity selector args helper. |
| e2eTests/e2eTerraform_test.go | Switches Terraform E2E tests to use the Terraform identity selector args helper. |
| .github/workflows/e2e-tests.yaml | Adds Terraform credential preflight checks, runs Linux terraform CLI tests first with the primary identity, and passes alternate creds into terraform E2E runs. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Mani Bindra (maniSbindra)
deleted the
feature/terraform-e2e-sp-rotation
branch
August 27, 2026 15:22
This was referenced Aug 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Alternate the Linux Terraform E2E tests between two service principals to reduce stale Azure RBAC state carried between consecutive tests.
This change also:
gotestsumprocess, test order, reporting, and failure aggregation;Motivation
The Terraform E2E suite currently reuses one service principal across all tests. Azure role-assignment removal is eventually consistent, so permissions from one test can remain effective when the next test begins. This can cause permission discovery to depend on residual RBAC state and produce intermittent failures.
Using alternating identities gives each service principal additional recovery time while the other identity runs the next test. It also avoids applying a long fixed delay to every MPF invocation.
This work is related to #231, but does not close it. Azure RBAC propagation remains eventually consistent, and additional stabilization may still be needed for tests with exact permission assertions.
Implementation
mpf-terraform-linux-alt-e2e-spas an alternate Linux Terraform identity.--target terraform_linux_altprovisioning support to the Bash and PowerShell scripts.E2E results
The branch completed successfully with the original 15-second experiment and with the reduced one-second delay.
With the one-second delay:
TestTerraformAuthorizationPermissionMismatchdiscovered the intermittent additionalMicrosoft.Resources/subscriptions/providers/readpermission.The isolated failure indicates that identity rotation reduces adjacent-test contamination but cannot completely eliminate Azure RBAC propagation variability across closely spaced workflow runs.
Related issue
References #231.