Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$IsMainTemplate not properly passed down to scripts, resulting in false positives #766

Open
chgeuer opened this issue Feb 28, 2024 · 0 comments

Comments

@chgeuer
Copy link
Member

chgeuer commented Feb 28, 2024

I created a repro for the problem about a false positive triggering The _artifactsLocation and _artifactsLocationSasToken parameters must not have a defaultValue in a nested template problem

Repro: https://github.com/chgeuer/repro_arm_ttk_artifactslocationproblem

The ARM TTK is used by Azure Marketplace for manual validation of submitted managed applications. Unfortunately, ARM TTK complains about a problem related to the _artifactsLocation and _artifactsLocationSasToken parameters.

In this repro, we compile a set of Bicep sources into an ARM JSON, which we validate using ARM TTK.

In mainTemplate.bicep, these 2 parameters either have default values,

param _artifactsLocation string = deployment().properties.templateLink.uri

@secure()
param _artifactsLocationSasToken string = ''

or don't:

param _artifactsLocation string

@secure()
param _artifactsLocationSasToken string

Subsequently, we passe these values down to a nested template (please note that I renamed the receiving parameters to avoid confusion):

module nestedModule './nestedtemplates/meteredBillingDependencies.bicep' = {
  name: '...'
  params: {
    artifactsLocation: _artifactsLocation
    artifactsLocationSasToken: _artifactsLocationSasToken
  }
}

Note that in the nested template, the artifactsLocation and artifactsLocationSasToken parameters have no default values at all.

When using default values in the main template

When supplying default values in the main template,

param _artifactsLocation string = deployment().properties.templateLink.uri

@secure()
param _artifactsLocationSasToken string = ''

we're getting a confusing error message, which says that in a nested template, there must be no default values. However, the nested template has no default values:

Validating ARM-JSON\mainTemplate.json
  artifacts parameter
    [-] artifacts parameter (86 ms)
        The _artifactsLocation and _artifactsLocationSasToken parameters in "mainTemplate.json" 
        must not have a defaulValue in a nested template.

However, looking at the samples (https://github.com/Azure/azure-quickstart-templates/blob/master/1-CONTRIBUTION-GUIDE/best-practices.md#deployment-artifacts-nested-templates-scripts), this seems to be the correct way.

But ARM TTK artifacts-parameter.test.ps1 triggers the error. It seems the $IsMainTemplate isn't properly being passed down to the artifacts-parameter.test.ps1 script; it's false for the mainTemplate.json file...

When removing the defaults in the main template

When removing the defaults for _artifactsLocation and _artifactsLocationSasToken in the main template, ARM TTK stops complaining about mainTemplate.json and starts complaining about createUiDefinition.json...

Validating ARM-JSON\createUiDefinition.json
  Parameters Without Default Must Exist In CreateUIDefinition
    [-] Parameters Without Default Must Exist In CreateUIDefinition (67 ms)
        _artifactsLocation does not have a default value, and is not defined in CreateUIDefinition.outputs
        _artifactsLocationSasToken does not have a default value, and is not defined in CreateUIDefinition.outputs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant