Description
Summary
avm pre-commit and avm pr-check fail in the transform step on Azure/terraform-azurerm-avm-res-keyvault-vault:
step 5/7: transform -> error
transform: Exception calling "ContainsKey" with "1" argument(s): "Value cannot be null. (Parameter 'key')"
The module is unchanged: it reproduces on main at 65a67d849089550af55b4b30b6c5eade2a54be3b (feat!: manage private endpoints with AzAPI (#387)).
Environment
- Avm.Authoring 0.33.0 (also 0.31.0 with
-SkipModuleVersionCheck) - Windows 11, PowerShell 7.5
- Ubuntu on WSL 2, PowerShell 7.5.2
Repro
git clone https://github.com/Azure/terraform-azurerm-avm-res-keyvault-vault.git
cd terraform-azurerm-avm-res-keyvault-vault
git checkout 65a67d849089550af55b4b30b6c5eade2a54be3b
pwsh -NoProfile -c "Import-Module Avm.Authoring; avm pre-commit"Stack trace
Exception calling "ContainsKey" with "1" argument(s): "Value cannot be null. (Parameter 'key')"
At Engines/Terraform/Invoke-AvmTerraformUtilityMigration.ps1:391 char:17
+ if (-not $sources.ContainsKey($dependency)) { continue }
at Invoke-AvmTerraformUtilityProviderCleanup, Engines/Terraform/Invoke-AvmTerraformUtilityMigration.ps1: line 391
at Invoke-AvmTerraformTransform, Engines/Terraform/Invoke-AvmTerraformTransform.ps1: line 1320
at Invoke-AvmTransform, Public/Invoke-AvmTransform.ps1: line 146
at <ScriptBlock>, Public/Invoke-AvmPrCheck.ps1: line 293
What I found
I added a debug line before the loop at line 390 that prints every entry of $scope.Dependencies:
scope=<repo> key=[<repo>/modules/key] value=[]
scope=<repo>/examples/access-policies key=[keyvault] value=[<repo>]
scope=<repo>/examples/create-key key=[key_vault] value=[<repo>]
...
The example scopes look as expected (module call name -> module path). The root scope does not: it has a single entry whose key is the absolute path of ./modules/key and whose value is $null. The root calls both ./modules/key (module "keys") and ./modules/secret (module "secrets"), and neither call name appears. Get-AvmTerraformUtilityMigrationPlan (line 104) writes Dependencies[<call name>] = <path>, so I suspect the entry is replaced somewhere between that function and Invoke-AvmTerraformUtilityProviderCleanup, but I did not find where.
The same $scope.Dependencies[$name] pattern is used without a null check in Sync-AvmTerraformLocalProviderMapping (line 340), where a $null value just falls through -cnotin.
Workaround
Skipping null entries at line 391 lets the run finish:
if ($null -eq $dependency) { continue }
if (-not $sources.ContainsKey($dependency)) { continue }With that guard, avm pre-commit passes and avm pr-check passes transform and lint. This only hides the symptom; the root module's modules/secret dependency is also missing from the map, so the cleanup may skip work it should do.
Side effect
After the crash, the working tree is left half-transformed, including modules/key/main.telemetry.tf.mptfnew and modules/secret/main.telemetry.tf.mptfnew. A clean rerun needs git clean and git checkout.
Activity