Azure / PSRule.Rules.Azure

Rules to validate Azure resources and infrastructure as code (IaC) using PSRule.
https://azure.github.io/PSRule.Rules.Azure/
MIT License
387 stars 84 forks source link

[BUG] Failed to expand with .outputs #2935

Closed BernieWhite closed 2 months ago

BernieWhite commented 3 months ago

Existing rule

No response

Description of the issue

Expansion may fail when referencing the .outputs property from a module instead of a specific output such as .outputs.id.

Error messages

Error: Failed to expand bicep source '/home/runner/work/cosmosdb-chatgpt/cosmosdb-chatgpt/infra/main.test.bicep'. Exception calling "GetBicepResources" with "2" argument(s): "Unable to expand resources because the source file '/home/runner/work/cosmosdb-chatgpt/cosmosdb-chatgpt/infra/main.test.bicep' was not valid. An error occurred evaluating expression '[union(if(not(empty(parameters('appPrincipalId'))), createArray(reference(resourceId('Microsoft.Resources/deployments', 'nosql-role-assignment-app'), '2022-09-01').outputs.id.value, reference(resourceId('Microsoft.Resources/deployments', 'openai-role-assignment-read-app'), '2022-09-01').outputs), createArray()), if(not(empty(parameters('userPrincipalId'))), createArray(reference(resourceId('Microsoft.Resources/deployments', 'nosql-role-assignment-user'), '2022-09-01').outputs.id.value, reference(resourceId('Microsoft.Resources/deployments', 'container-registry-role-assignment-push-user'), '2022-09-01').outputs.id.value, reference(resourceId('Microsoft.Resources/deployments', 'openai-role-assignment-read-user'), '2022-09-01').outputs), createArray()))]' line 2400. Could not determine JSON object type for type PSRule.Rules.Azure.Data.Template.DeploymentValue+DeploymentOutputs."

Reproduction

output roleAssignments array = union(
  !empty(appPrincipalId) ? [ nosqlAppAssignment.outputs.id, openaiAppAssignment.outputs ] : [],
  !empty(userPrincipalId) ? [ nosqlUserAssignment.outputs.id, registryUserAssignment.outputs.id, openaiUserAssignment.outputs ] : []
)

Version of PSRule

2.9.0

Version of PSRule for Azure

1.37.0

Additional context

No response