Skip to content

Latest commit

 

History

History
582 lines (461 loc) · 18.3 KB

Invoke-AvmTestE2e.md

File metadata and controls

582 lines (461 loc) · 18.3 KB

Invoke-AvmTestE2e

Synopsis

Run Bicep or Terraform deployment tests with ordinary cleanup.

Description

Bicep discovers tests/e2e/**/main.test.bicep and compiles temporary ARM templates without editing source. Existing Azure PowerShell and Azure CLI sign-ins must identify the same account, tenant, cloud and selected subscription. Azure CLI remains required for independent identity checks and deployment/resource discovery used by safe cleanup; deployments use Az.Resources. Required individual Az modules are resolved from verified pins on demand. Existing compatible installed modules remain usable, while offline and no-auto-install settings prevent implicit downloads. Missing Bicep target IDs use opted-in CI values first, then the authenticated Azure PowerShell context when no pool selects the subscription. Native ARM validation and deployment support resource-group, subscription, management-group and tenant scope, including nested and cross-scope module deployments. Select authorized test targets: resources created or updated by the test can be removed afterwards.

Bicep registry modules read repository-root .required-features.json and .required-resource-providers.json maps using the exact module Path. Validate each whole map before dependency preparation or Azure calls. After compilation and identity verification, register features and propagate their providers, then register required provider namespaces, before token replacement, validation or deployment. Missing, empty or unrelated maps skip registration. WhatIf validates configuration without Azure access. Complete and cleanup never register prerequisites, and registrations are never undone. No additional caller input is needed.

Packaged Resources/bicep/retry-policy.json selects bounded retries from complete structured failure evidence. InPlace reuses the exact deployment, template and parameters. Fresh generates a new external naming context and deployment identity, using another eligible region by default. Fixed caller inputs and names authored inside Bicep are not rewritten, so Fresh does not guarantee all resource names differ. No resources are deleted between attempts. Resource evidence is saved before another attempt can overwrite deployment-operation history. Status recovery shares one configured four-hour deadline across all attempts in a case; it never starts a read or accepts a terminal result at or after that deadline.

Successful deployments run their case-local Pester assertions, then post.ps1, then native cleanup adapted from the registry workflow. Assertions and hooks run in the same PowerShell process to retain process-only sign-ins. Caller or workflow cancellation applies; no separate-process timeout or credential transfer is used. A failed assertion or hook still runs ordinary cleanup. An authored assertion suite must have passing tests and no failed, skipped, filtered, inconclusive or setup-failed tests. Absent suites are 'not-present'.

Cleanup follows recorded Create deployment operations recursively, not Read references or a subscription-wide inventory. Resource-group cases use unique groups and verified ownership tags. All attempt IDs and required post-removal metadata are saved in an atomic local JSON file before submission or removal. The state contains no credentials, parameters or outputs, and survives temporary-template removal. Final cleanup covers every attempt, including failed attempts. Incomplete cleanup warns, reports pending IDs and allows later cases to run. The reaper is a fallback, not the normal cleanup mechanism.

All runs the complete lifecycle. Deploy retains all attempts and state for a separate Complete call after caller-owned sign-in renewal. Complete requires matching direct case/module source, assertion files and post hook, plus a matching explicit, CI or context-derived subscription/tenant. It rereads outputs by exact deployment ID and never submits a deployment. The source check does not fingerprint every imported helper or dependency. Interrupted completion must use avm test cleanup rather than replaying authored scripts. Actions callers may upload state as an artifact; recovery requires that the upload finished before runner loss.

KeepResources runs assertions but deliberately skips post.ps1 and cleanup for every attempt. This is an explicit debugging exception. The saved file can later be passed to avm test cleanup, which does not need the checkout and never runs assertions or hooks.

Terraform runs init, apply, idempotency plan and destroy for runnable examples/. MaxRetry controls Terraform transient apply retries, including errors containing both "request" and "quota" in one error block. Fresh retries destroy the example first; fixed locations are not changed. Configured in-place retries reuse the existing state without a destroy. After pre.ps1 and .env loading, the shared Terraform authentication preflight checks ARM_* inputs or an enabled Azure CLI subscription. It passes CLI subscription/tenant IDs only to child processes and never signs in or changes the selected account. An authentication failure skips Terraform operations, reports an error and still runs post.ps1. Providers still validate credentials and resource permissions. No deployment tests belong in avm pr-check or the local build gate. Listing does not resolve tools or credentials. An absent tier is 'skipped', not a pass; .e2eignore excludes a case.

CLI commands

  • avm test e2e

Syntax

Invoke-AvmTestE2e [[-Path] <string>] [-Ecosystem <string>] [-AllowPathFallback] [-Example <string[]>] [-List] [-MaxRetry <int>] [-Recurse] [-SubscriptionId <string>] [-TenantId <string>] [-ManagementGroupId <string>] [-SubscriptionCleanupManagementGroupId <string>] [-Location <string>] [-ResourceLocation <string>] [-ResourceGroupPrefix <string>] [-TokenFile <string>] [-Tokens <IDictionary>] [-ParameterFile <string>] [-Parameters <IDictionary>] [-UseCiInputs] [-TestSubscriptionIds <string>] [-SubscriptionSelectionSeed <int>] [-SubscriptionJobIndex <int>] [-Phase <string>] [-CleanupStatePath <string>] [-KeepResources] [-RequireResourceIsolation] [-DeploymentRetryLimit <int>] [-ValidationRetryLimit <int>] [-SkipModuleVersionCheck] [-WhatIf] [-Confirm] [<CommonParameters>]

Parameters

-AllowPathFallback

Accept a PATH tool only when it reports the lock-pinned version.

Property Value
Type Switch
Required false
Position named
Default value False
Accept pipeline input false
Accept wildcard characters false

-CleanupStatePath

Optional new state file for one selected case. Complete requires an existing file and the matching resolved subscription and tenant.

Property Value
Type String
Required false
Position named
Default value
Accept pipeline input false
Accept wildcard characters false

-DeploymentRetryLimit

Bicep total submission attempts, one to three, capped by packaged policy. Only exact Failed deployments with complete eligible evidence can retry; unknown outcomes and preflight rejection alone never authorize resubmission.

Property Value
Type Int32
Required false
Position named
Default value 3
Accept pipeline input false
Accept wildcard characters false

-Ecosystem

Explicit ecosystem, or auto-detection.

Property Value
Type String
Required false
Position named
Default value auto
Accept pipeline input false
Accept wildcard characters false

-Example

Select case names or root-relative Bicep paths. Explicit ignored, absent or ambiguous selections are errors.

Property Value
Type String[]
Required false
Position named
Default value @()
Accept pipeline input false
Accept wildcard characters false

-KeepResources

Bicep-only: run assertions but retain every attempt, skipping post and cleanup.

Property Value
Type Switch
Required false
Position named
Default value False
Accept pipeline input false
Accept wildcard characters false

-List

Return a JSON array of runnable example names without cloud access.

Property Value
Type Switch
Required false
Position named
Default value False
Accept pipeline input false
Accept wildcard characters false

-Location

Bicep deployment-metadata location, selected from the existing e2e region policy when omitted and fixed across regional retries. Also the placement fallback for explicitly global resource types.

Property Value
Type String
Required false
Position named
Default value
Accept pipeline input false
Accept wildcard characters false

-ManagementGroupId

Bicep-only: existing target management-group name for that scope. With UseCiInputs, omitting this parameter uses the configured CI target. An explicitly supplied value always takes precedence and is validated; an invalid or empty explicit value is never replaced by a CI fallback.

Property Value
Type String
Required false
Position named
Default value
Accept pipeline input false
Accept wildcard characters false

-MaxRetry

Terraform-only transient apply retry budget, default two retries.

Property Value
Type Int32
Required false
Position named
Default value 2
Accept pipeline input false
Accept wildcard characters false

-ParameterFile

ARM JSON parameter file, preserving values and vault references. Mutually exclusive with Parameters; source is not changed.

Property Value
Type String
Required false
Position named
Default value
Accept pipeline input false
Accept wildcard characters false

-Parameters

Bicep parameter values. SecureString values remain in memory. Explicit values or files take precedence over CI inputs.

Property Value
Type IDictionary
Required false
Position named
Default value @{}
Accept pipeline input false
Accept wildcard characters false

-Path

Module directory, or an enclosing context. Defaults to the current location. Required provider declarations use only the exact Bicep registry module key in the root .required-resource-providers.json, without inheritance.

Property Value
Type String
Required false
Position 1
Default value $PWD.Path
Accept pipeline input false
Accept wildcard characters false

-Phase

Bicep All (default), Deploy, or Complete for caller-owned sign-in renewal.

Property Value
Type String
Required false
Position named
Default value All
Accept pipeline input false
Accept wildcard characters false

-Recurse

Bicep-only: include child-module test cases.

Property Value
Type Switch
Required false
Position named
Default value False
Accept pipeline input false
Accept wildcard characters false

-RequireResourceIsolation

Bicep-only: require an inspectable, contained storage-resource template in a fresh native-owned group, or an empty template at any scope. Refuse unproved scope escapes, scripts, hooks and provider-managed infrastructure. Recheck group ownership before submission and constrain recursive cleanup/recovery to the persisted ownership boundary.

Property Value
Type Switch
Required false
Position named
Default value False
Accept pipeline input false
Accept wildcard characters false

-ResourceGroupPrefix

Bicep-only: resource-group name prefix, defaulting to avmtest when omitted; up to 57 safe name characters.

Property Value
Type String
Required false
Position named
Default value avmtest
Accept pipeline input false
Accept wildcard characters false

-ResourceLocation

Pin Bicep resource placement. Must agree with parameter/token locations.

Property Value
Type String
Required false
Position named
Default value
Accept pipeline input false
Accept wildcard characters false

-SkipModuleVersionCheck

Skip the advisory module-version check.

Property Value
Type Switch
Required false
Position named
Default value False
Accept pipeline input false
Accept wildcard characters false

-SubscriptionCleanupManagementGroupId

Bicep-only: explicit isolated management group for subscription-alias cleanup. It is persisted before deployment and cannot be supplied to Complete, which uses the recorded target.

Property Value
Type String
Required false
Position named
Default value
Accept pipeline input false
Accept wildcard characters false

-SubscriptionId

Bicep-only: explicit test subscription GUID. When omitted without a subscription pool, use the opted-in CI value or active Az context.

Property Value
Type String
Required false
Position named
Default value
Accept pipeline input false
Accept wildcard characters false

-SubscriptionJobIndex

Nonnegative initial case index for round-robin subscription selection.

Property Value
Type Int32
Required false
Position named
Default value 0
Accept pipeline input false
Accept wildcard characters false

-SubscriptionSelectionSeed

Shared nonnegative seed for deterministic subscription ordering.

Property Value
Type Int32
Required false
Position named
Default value 0
Accept pipeline input false
Accept wildcard characters false

-TenantId

Bicep-only: explicit tenant GUID. When omitted, use the opted-in CI value or active Az context for every deployment scope.

Property Value
Type String
Required false
Position named
Default value
Accept pipeline input false
Accept wildcard characters false

-TestSubscriptionIds

Optional Bicep JSON array of id/name objects with an optional tag. Missing tags mean General. Cases use only General subscriptions in a stable seeded ordering, independent of JSON ordering. Registry-layout modules require the exact root .reserved-test-subscriptions.json map. Non-General reservations fail closed before authentication because native whole-lifecycle locking is not yet implemented; no registry fallback runs.

Property Value
Type String
Required false
Position named
Default value
Accept pipeline input false
Accept wildcard characters false

-TokenFile

JSON string-valued tokens, relative to the module root or absolute. Mutually exclusive with Tokens. Explicit scope parameters own scope tokens.

Property Value
Type String
Required false
Position named
Default value
Accept pipeline input false
Accept wildcard characters false

-Tokens

Bicep token dictionary instead of TokenFile. Generated avmE2eRunId and avmE2eSuffix tokens provide a unique default namePrefix per fresh context. In-place retries preserve these values; explicit caller values stay fixed.

Property Value
Type IDictionary
Required false
Position named
Default value @{}
Accept pipeline input false
Accept wildcard characters false
Aliases AdditionalTokens

-UseCiInputs

Opt into AVM_CI_VARIABLES and AVM_CI_SECRETS JSON, localToken_*, TOKEN_NAMEPREFIX and deprecated CI_KEY_VAULT_NAME inputs. CI secrets beat variables; CI_ aliases beat CI__ aliases within a source. Missing explicit IDs may use VALIDATE_SUBSCRIPTION_ID and VALIDATE_TENANT_ID. Unresolved IDs then use the active Az context. Pools resolve VALIDATE_SUBSCRIPTION_IDS then TEST_SUBSCRIPTION_IDS from variables, then secrets, then environment. When ManagementGroupId is omitted, the same source order resolves VALIDATE_MANAGEMENT_GROUP_ID before ARM_MGMTGROUP_ID within each source. Management-group cases still require a valid resolved target. Nothing logs in.

Property Value
Type Switch
Required false
Position named
Default value False
Accept pipeline input false
Accept wildcard characters false

-ValidationRetryLimit

Bicep regional validation budget, one to three, capped by packaged policy. Only wholly regional validation failures move an unpinned, non-global, non-resource-group case. Fresh deployment retries share the region budget and validate their new context; in-place retries reuse prior validation.

Property Value
Type Int32
Required false
Position named
Default value 3
Accept pipeline input false
Accept wildcard characters false

Examples

EXAMPLE 1

avm test e2e --list

EXAMPLE 2

avm test e2e

EXAMPLE 3

avm test e2e --subscription-id $testSubscriptionId --tenant-id $testTenantId --location eastus --resource-group-prefix avm-e2e

EXAMPLE 4

avm test e2e --example defaults --subscription-id $testSubscriptionId --tenant-id $testTenantId --location eastus --phase Deploy --cleanup-state-path cleanup.json

EXAMPLE 5

avm test e2e --phase Complete --cleanup-state-path cleanup.json --subscription-id $testSubscriptionId --tenant-id $testTenantId

EXAMPLE 6

avm test e2e --max-retry 0 --ecosystem terraform

EXAMPLE 7

Invoke-AvmTestE2e -Path . -Ecosystem bicep -RequireResourceIsolation -SubscriptionId $testSubscriptionId -TenantId $testTenantId -Location eastus -ResourceGroupPrefix avm-e2e

Outputs

  • Engine result with Status, Issues and run counts. Bicep also returns Phase, AssertionResults, PostResults, CleanupPending, CleanupDeferred and CleanupStatePaths. Cleanup failures are warnings and retain state for recovery; later cases continue. Deployment and assertion failures remain errors. Outputs and parameters are not returned.