Bicep Assert / Test #11466
Replies: 2 comments 5 replies
-
Getting the same here. Getting the asserts to work and the tests separately, but when referring to the test-resource in the asserts im getting the red squiggly line and error message: This is my code targetScope = 'subscription'
@description('Required. Location of the resources.')
param location string
@description('Required. Unique identifier for the GH actions run or your local deployment')
param uniqueSuffix string
@description('Required. Resource group name for acr components')
param rgBaseName string
var acrRgName = '${rgBaseName}-${uniqueSuffix}'
@minLength(5)
@maxLength(50)
@description('Required. The base name for the Azure Container Registry. Alphanumerical characters only.')
param acrBaseName string
// VARIABLES
// Because of Alphanumerical characters only in combination with the name of acr needs to be global unique we combine the basename with the uniquesuffix set by using {{ github.run_id }}
var acrName = '${acrBaseName}${uniqueSuffix}'
// MODULES
test acrRg '../../CARML/Microsoft.Resources/resourceGroups/deploy.bicep' = {
name: '${deployment().name}-acr-rg'
params: {
name: acrRgName
location: location
}
}
test acr '../../modules/acr/acr.bicep' = {
name: '${deployment().name}-acr'
params: {
location: location
acrName: acrName
acrResourceGroupName: acrRg.outputs.name
}
}
assert locationTest = contains(acrRg.resources.resourceGroup.location, 'westeurope') |
Beta Was this translation helpful? Give feedback.
-
I was trying to validate parameters and provide error messages as appropriate as output parameters before the advent of assert. Beforevar validationError = (!isSharedAcr) && isOtherAcr && isNewAcr
resource .... if(!validationError) {
}
output validationMessage string = validationError ? '''
Only one ACR can be supplied for use.
Shared ACR has 'shrd' in name and created in the RG where you're deploying
Other ACR is ACR in other Resource Groups. You must only specify the resourceId in the configuration
Specify a name other than the shared ACR name to create a new ACR
''' : 'None' Of course, the issue was with skipping deploying the resources after the validation. Nowvar validationError = (!isSharedAcr) && isOtherAcr && isNewAcr
// Only one ACR can be supplied for use.
// Shared ACR has 'shrd' in name and created in the RG where you're deploying
// Other ACR is ACR in other Resource Groups. You must only specify the resourceId in the configuration
// Specify a name other than the shared ACR name to create a new ACR
assert MoreThanOneAcrSpecified = !validationError
// Note no conditions are required.
resource .... {
} Unfortunately, the output variables are no longer visible in the deployment stack due to the exception and hence can't specify it. Future?Perhaps the assert needs a syntax enhancement - an optional message parameter: var validationError = (!isSharedAcr) && isOtherAcr && isNewAcr
var validationErrorMessage = validationError ? '''
Only one ACR can be supplied for use.
Shared ACR has 'shrd' in name and created in the RG where you're deploying
Other ACR is ACR in other Resource Groups. You must only specify the resourceId in the configuration
Specify a name other than the shared ACR name to create a new ACR
''' : 'None'
assert MoreThanOneAcrSpecified = !validationError, validationErrorMessage |
Beta Was this translation helpful? Give feedback.
-
I've been following the latest Bicep Community call and wanted to try the test functionality.
Here's a sample code I used:
keyvault.bicep
test.bicep
I am getting red squiggly lines on my testKeyVault scope in the assert above. How can I test this deployment? The demo did not specify the steps to do so.
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions