Azure / bicep

Bicep is a declarative language for describing and deploying Azure resources
MIT License
3.17k stars 730 forks source link

Improve types for variables, suggest types or typing URL on decompile warning #5311

Closed asears closed 2 years ago

asears commented 2 years ago

In decompiling an AzureML ARM template to Bicep, a couple of variables are not getting typed properly.

There are 3 Error BCP014 in the process.

      "privateEndpointSettings": {
            "name": "[concat(parameters('workspaceName'), '-PrivateEndpoint')]",
            "properties": {
                "privateLinkServiceId": "[resourceId('Microsoft.MachineLearningServices/workspaces', parameters('workspaceName'))]",
                "groupIds": [
                    "amlworkspace"
                ]
            }
        },
        "defaultPEConnections": "[array(variables('privateEndpointSettings'))]",
        "subnet": "[resourceId(parameters('vnetResourceGroupName'), 'Microsoft.Network/virtualNetworks/subnets', parameters('vnetName'), parameters('subnetName'))]",
        "subnetPolicyForPE": {
            "privateEndpointNetworkPolicies": "Disabled",
            "privateLinkServiceNetworkPolicies": "Enabled"
        },

It generates a couple nested templates with these variable types missing.

param variables_defaultPEConnections ? /* TODO: fill in correct type */
param variables_subnet ? /* TODO: fill in correct type */
param variables_subnetPolicyForPE ? /* TODO: fill in correct type */

Is there a hint to the correct types for these? Seems variables_defaultPEConnections = array. I'm not clear on the other two.

Is there some way we could adjust ARM template to fix these issues, or is it known Bicep issue?

In VSCode, this message is shown, however I don't see the means of setting a default value for the variable.

Nested template "[variables('privateEndpointDeploymentName')]" will not have validation or parameter completion. To enable, either add default values to all top-level parameters or add a parameter file ("Select/Create Parameter File" command).
Nested template "[concat('UpdateSubnetPolicy-', uniqueString(parameters('vnetName'), parameters('subnetName')))]" will not have validation or parameter completion. To enable, either add default values to all top-level parameters or add a parameter file ("Select/Create Parameter File" command).
alex-frankel commented 2 years ago

Can you share the full ARM template?

asears commented 2 years ago

Unfortunately I can't share full template. I will see if I can create a minimal repro and reopen if req'd. Likely there's some cases where decompilation cannot determine the typing because underlying parameters or variables are different types concatenated.