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

Nested templates and Parameters Without Default Must Exist In CreateUIDefinition #681

Closed
adrianmo opened this issue Sep 8, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@adrianmo
Copy link
Member

adrianmo commented Sep 8, 2022

Hello, we are in the process of certifying a managed application and we are getting the validation error in the issue title that is forcing us to add default values to all nested templates. Since they are nested templates, we understand that they are not directly connected to the CreateUIDefinition file and they should not be taken into account by that check.

I've built a minimal example to demonstrate the issue. I hope that can help better understand it, but happy to provide more details if needed.

createUiDefinition.json:

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {}
    ],
    "outputs": {
      "mainParameter": "value-from-ui"
    }
  }
}

main.bicep:

param mainParameter string = 'default-value'

module module 'module.bicep' = {
  name: 'Module'
  params: {
    moduleParameter: mainParameter
  }
}

module.bicep:

param moduleParameter string

When built, the Bicep files produce the following ARM template:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.9.1.41621",
      "templateHash": "4551264275492999207"
    }
  },
  "parameters": {
    "mainParameter": {
      "type": "string",
      "defaultValue": "default-value"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2020-10-01",
      "name": "Module",
      "properties": {
        "expressionEvaluationOptions": {
          "scope": "inner"
        },
        "mode": "Incremental",
        "parameters": {
          "moduleParameter": {
            "value": "[parameters('mainParameter')]"
          }
        },
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "metadata": {
            "_generator": {
              "name": "bicep",
              "version": "0.9.1.41621",
              "templateHash": "15490559216858461434"
            }
          },
          "parameters": {
            "moduleParameter": {
              "type": "string"
            }
          },
          "resources": []
        }
      }
    }
  ]
}

The Parameters-Without-Default-Must-Exist-In-CreateUIDefinition check fails as follows.

$ Test-AzTemplate . -Tests @('Parameters-Without-Default-Must-Exist-In-CreateUIDefinition')"

Validating validation\createUiDefinition.json
  Parameters Without Default Must Exist In CreateUIDefinition
    [-] Parameters Without Default Must Exist In CreateUIDefinition (20 ms)
        moduleParameter does not have a default value, and is not defined in CreateUIDefinition.outputs

If we add a default value to the module parameter, the validation passes. However, that forces us to set default values for hundreds of parameters across multiple modules, which doesn't look right at all.

param moduleParameter string = ''
$ Test-AzTemplate . -Tests @('Parameters-Without-Default-Must-Exist-In-CreateUIDefinition')"

Validating validation\createUiDefinition.json
  Parameters Without Default Must Exist In CreateUIDefinition
    [+] Parameters Without Default Must Exist In CreateUIDefinition (16 ms)
@ghost ghost added the Needs: triage 🔍 label Sep 8, 2022
@dciborow
Copy link
Contributor

dciborow commented Sep 14, 2022

@adrianmo , just want to offer that something does seem strange here. You should be able to do what you want and the marketplace should go and accept the ARM template that you showed. This is actually what you have to do for a location parameter, which I have gone and submitted successfully myself.

Are you seeing this issue when you upload to the partner center, or just locally? it may be that the partner center does not check this rule.

You can find the exact arm-ttk setup for ARM-TTK that the partner center uses here, https://aka.ms/arm-ttk-marketplace
Try running this over your code and see if the error still pops?

I have an example of an Azure DevOps pipeline where I run this version of ARM-TTK on my template before I submit to partner center, just in case that helps you too. https://github.com/microsoft/azure-gaming-devops/blob/main/marketplace/stage_arm_ttk.yml

Also before making hundreds of changes anywhere, the Partner Center team may be able to give an exception for some of the failing rules. When making your submission for review, include in the notes that you except this ARM-TTK warning to fail, and explain why it is a false-positive.

@NickSpag
Copy link

@dciborow we've recreated this issue in #680 as well, and have seen the problem with nested templates since we started (1yr+). and yea it occurs in the partner center, as well as locally.

@bmoore-msft bmoore-msft added bug Something isn't working and removed Needs: triage 🔍 labels Sep 16, 2022
@StartAutomating
Copy link
Collaborator

@bmoore-msft This looks related to #680, please assign it to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants