Exception calling "GetBicepResources" with "3" argument(s): "Unable to expand resources because the source file #1581
-
Github Actions workflows fail to expand and use bicep template with error: Steps to reproduce the issue: Expected behaviour No error, expand the bicep file.
Module in use and version:
Captured output from
Additional context |
Beta Was this translation helpful? Give feedback.
Replies: 15 comments 2 replies
-
main.bicep: param resourcegroupNames array main.parma.bicep.json:
|
Beta Was this translation helpful? Give feedback.
-
@oxbo-andre Thanks for reporting the issue. Expansion requires a parameter file or other bicep deployment referencing the module to provide required parameters. If you have a parameter file as the post from @aavdberg may suggest then try this:
Details here: https://azure.github.io/PSRule.Rules.Azure/using-bicep/#configuringpathexclusions
See: https://azure.github.io/PSRule.Rules.Azure/setup/configuring-expansion/#requiredparameterdefaults Things to note, PSRule will automatically find the .bicep file from the parameter file only if:
You can also enforce the metadata link be setting the https://azure.github.io/PSRule.Rules.Azure/setup/configuring-expansion/#requiretemplatemetadatalink Parameter file expansion needs to be enabled via https://azure.github.io/PSRule.Rules.Azure/setup/configuring-expansion/#parameterfileexpansion I hope that helps. If not, then let me know and we might need to debug it further by collecting some additional information. |
Beta Was this translation helpful? Give feedback.
-
Hi @BernieWhite i opened the issue with my working account and commented with my own account. Linking the parameter file to the template file is not mentioned in the documentatie for Bicep. my main bicep file is: main.bicep |
Beta Was this translation helpful? Give feedback.
-
@aavdberg Thanks for the feedback. Here are the links:
But based on your feedback we still have work to do to make it clearer :) thanks. |
Beta Was this translation helpful? Give feedback.
-
This is my ps.rule.yaml file: include:
module:
- PSRule.Rules.Azure
output:
culture:
- "en-US"
input:
pathIgnore:
# Ignore other files in the repository.
- ".vscode/"
- ".github/"
- "*.md"
- "*.yaml"
- "bicepconfig.json"
- "*.azcli"
# Exclude modules but not tests.
#- 'bicep/modules/**/*.bicep'
#- '!bicep/modules/**/*.tests.bicep'
execution:
notProcessedWarning: false
configuration:
# Enable automatic expansion of Azure parameter files.
AZURE_PARAMETER_FILE_EXPANSION: true
# Enable automatic expansion of Azure Bicep source files.
AZURE_BICEP_FILE_EXPANSION: true
# Configures the number of seconds to wait for build Bicep files.
AZURE_BICEP_FILE_EXPANSION_TIMEOUT: 20
|
Beta Was this translation helpful? Give feedback.
-
@aavdberg Nice! Looks mostly good just uncomment: To metadata link your parameter file it might look something like this if the file {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"template": "./main.bicep"
},
"parameters": {
"resourcegroupNames": {
"value": [
{
"name": "acr",
"environmentType": "prod"
},
{
"name": "kv",
"environmentType": "prod"
}
]
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
With modules you mean that i use in my main.bicep file? The modules are in an Azure Container Registry. |
Beta Was this translation helpful? Give feedback.
-
include:
module:
- PSRule.Rules.Azure
output:
culture:
- "en-US"
input:
pathIgnore:
# Ignore other files in the repository.
- ".vscode/"
- ".github/"
- "*.md"
- "*.yaml"
- "bicepconfig.json"
- "*.azcli"
# Exclude modules but not tests.
# - 'bicep/modules/**/*.bicep'
# - '!bicep/modules/**/*.tests.bicep'
execution:
notProcessedWarning: false
configuration:
# Enable automatic expansion of Azure parameter files.
AZURE_PARAMETER_FILE_EXPANSION: true
# Enable automatic expansion of Azure Bicep source files.
AZURE_BICEP_FILE_EXPANSION: false
# Configures the number of seconds to wait for build Bicep files.
AZURE_BICEP_FILE_EXPANSION_TIMEOUT: 20
|
Beta Was this translation helpful? Give feedback.
-
@aavdberg You can use Bicep code with PSRule in the following ways:
Also you can also: Bicep deployment/ parameter file -> Bicep module -> Bicep module .... If you are using the PSRule integration with GitHub Actions or Azure Pipelines then see the following to make sure that the context PSRule runs under has an authenticated connection to be able to complete the restore. https://azure.github.io/PSRule.Rules.Azure/using-bicep/#restoringmodulesfromaprivateregistry Alternatively if the modules are already directly restored prior to calling PSRule with a |
Beta Was this translation helpful? Give feedback.
-
@aavdberg Nice! |
Beta Was this translation helpful? Give feedback.
-
Thanks @BernieWhite jobs:
validate:
name: Analyze templates
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
# Display PowerShell version
- name: PowerShell version
run: |
$PSVersionTable
shell: pwsh
# Login to Azure for access to Azure Container Registry
- name: OIDC Login to Azure Public Cloud with AzPowershell (enableAzPSSession true)
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_IDENTITY_SUBSCRIPTION_ID }}
enable-AzPSSession: true
# Analyze Azure resources using PSRule for Azure
- name: Analyze Azure template files
uses: microsoft/[email protected]
with:
modules: "PSRule.Rules.Azure" Using GitHub Actions workflows |
Beta Was this translation helpful? Give feedback.
-
@aavdberg Are you fine for me to convert this to a discussion if there is no longer a bug so that this can help others? I'll log a separate issue for the bicep naming convention issue. |
Beta Was this translation helpful? Give feedback.
-
This also helped me a lot: https://docs.microsoft.com/en-us/learn/modules/test-bicep-code-using-github-actions |
Beta Was this translation helpful? Give feedback.
@oxbo-andre Thanks for reporting the issue.
Expansion requires a parameter file or other bicep deployment referencing the module to provide required parameters.
If you have a parameter file as the post from @aavdberg may suggest then try this:
main.bicep
is excluded. You can do this by setting theInput.PathIgnore
option. This is because expansion occurs from the parameter file or other bicep file, so the referenced module needs to be excluded.Details here: https://azure.github.io/PSRule.Rules.Azure/using-bicep/#configuringpathexclusions
AZURE_PARAMETER_DEFAULTS
) for testing, but that is mos…