Azure / bicep

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

[Feature Suggestion] Deployment Parameters: Allow unused paramaters in deployment #5771

Open mfeyx opened 2 years ago

mfeyx commented 2 years ago

Is your feature request related to a problem? Please describe

I want to deploy resources based on a params.json file. If unused parameters are present the deployment currently fails:

InvalidTemplate - Deployment template validation failed: 'The template parameters 'rg_tags' in the parameters file are not valid; they are not present in the original template and can therefore not be provided at deployment time. The only supported parameters for this template are 'name, tags'.

main.bicep

param name string
param tags object

resource storage 'Microsoft.Storage/storageAccounts@2021-06-01' = {
  name: name
  location: resourceGroup().location
  kind: 'StorageV2'
  sku: {
    name: 'Standard_ZRS'
  }
  properties: {
    accessTier: 'Cool'
  }

  tags: tags
}

params.json

{
  "id": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "title": "Parameters",
  "description": "An Azure deployment parameter file",
  "type": "object",
  "parameters": {
    "name": {
      "value": "mystoragename"
    },
    "rg_tags": {
      "value": {
        "businessowner": "tba",
        "project": "tba"
      }
    },
    "tags": {
      "value": {
        "application": "XYZ",
        "version": "0.0.1"
      }
    }
  }
}

Describe the solution you'd like

Basically, I want to deploy resources without having to delete parameters in the parameters file. I want to be able to define parameters even though they might not be used in a deployment. When I deploy a resource group, for instance, I will use my rg_tags values from the parameters, but not the normal tags that might be used in other deployments.

Edit: Sorry, I forget the command I use.

az deployment group what-if --resource-group "MY_RESOURCE_GROUP" -f "main.bicep" --parameters "params.json"

Hope this is the right place for the suggestion.

Kind regards :)

wsmelton commented 2 years ago

Duplicate #5742

mfeyx commented 2 years ago

hi @wsmelton,

I found that issue you mention above (#5742), but I thought it is not the same request as mine, even though it is similar. My suggestion is to not throw an error, like InvalidTemplate, if a parameter is unused. There is no conditional logic behind my request. I hope I could make myself clear :)

Kind regards

wsmelton commented 2 years ago

Oh, the param file itself. I would believe that has to be addressed upstream since validating the param to the template is done at the deployment PUT endpoint.

mfeyx commented 2 years ago

Oh, the param file itself. I would believe that has to be addressed upstream since validating the param to the template is done at the deployment PUT endpoint.

Thanks for your quick response @wsmelton! When you say "upstream" you mean I have to file this request somewhere else?

Kind regards

mfeyx commented 2 years ago

Opened the issue elsewhere, so I will close it here.

jikuja commented 1 year ago

Would it be possible to re-open this?

#5742 is not really a dupe of this at all.

Also this feature request should be handled on https://github.com/Azure/bicep/issues/7301 and tickets describing .bicepparams usage.

alex-frankel commented 1 year ago

@jikuja agreed this is not a dupe and agreed we could (not necessarily should) feasibly address this with .bicepparams support. I will re-open.

alex-frankel commented 1 year ago

Curious to understand what the potential negative implications would be for starting to allow this. We could emit a warning in the language service and as part of emitting ARM parameters and ARM template. When would a warning not be sufficient? cc @bmoore-mstf who may know more about this.

jikuja commented 1 year ago

One option might be adding option for tooling to


What would be correct level to implement this check?


API: How does PUT https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Resources/deployments/{deploymentName}?api-version=2021-04-01 and others handle deployments if properties.parameters or properties.parametersLink has unused parameters.

jikuja commented 1 year ago

BCP259(1) is now making more client-side assumptions about failing when unused paramters are being passed.

(1) bicep build-params => $"The parameter \"{identifier}\" is assigned in the params file without being declared in the Bicep file."

darren-mair commented 1 year ago

+1 for this, would also help with Yaml templates for multiple deployments using same template

r0b3rtk commented 1 year ago

+1 for this issue. Our use case is that we want to split one large Bicep file that is describing all resources of a spoke into multiple smaller bicep files. This spoke is deployed multiple times (e.g. one for Dev environment, one for Test and so on), so having a single parameter file per environment would be ideal.

alex-frankel commented 1 year ago

@darren-mair / @r0b3rtk - can you provide example bicepparam file and 2+ bicep files that demonstrate this? I am having trouble visualizing what this structure would look like

Rasmus715 commented 1 year ago

+1

Rasmus715 commented 1 year ago

@darren-mair / @r0b3rtk - can you provide example bicepparam file and 2+ bicep files that demonstrate this? I am having trouble visualizing what this structure would look like

Please look at the OP issue. Imagine a second bicep file that'll use both "rg_tags", "tags" and "name" parameters. That's exactly the case that you're looking for and what I'm facing right now.

mfeyx commented 1 year ago

In the meantime, I wrote a little helper script that can be found here: https://github.com/Azure/azure-cli/issues/21149#issuecomment-1256639995

darren-mair commented 1 year ago

@darren-mair / @r0b3rtk - can you provide example bicepparam file and 2+ bicep files that demonstrate this? I am having trouble visualizing what this structure would look like.

@alex-frankel Apologies for delay, i'll explain as best i can. We use YAML templates with CLI task and it uses parameters so we can use different bicep files with the same template as below.

image

Problem being we can only do this for bicep files that expect the same parameter inputs from Yaml, otherwise we have to create another template. Say for example 1 bicep file is expecting DNSSubscriptionID, but the second isn't. We then get error saying unexpected parameter.

if we could have the ability for bicep to ignore any parameters passed that are not declared, it would mean we could use the same YAML template file with all the Param overrides for all bicep main files. This would be unbelievable good.

lilGrim commented 7 months ago

+1

ryancolley commented 6 months ago

@alex-frankel Is this something that is being worked on by chance?

We have scenario where the vast majority of our bicep modules are using a central bicep module file for some key parameters etc, and having the ability to assign parameters up the chain using the .bicepparam file would be extremely useful to us.

Or perhaps there is a way to suppress error BCP259?

Screenshot 2024-03-14 at 10 58 49

kind regards

Saulopv commented 6 months ago

+1

GregorieCalderon commented 1 month ago

+1 This should be allowed. We use 1 BICEP params file for multiple deployments but due to this 'warning', we are unable to complete this the way we'd like. Its been 2 years (going on 3), i wonder if anyone cares about this issue.

@alex-frankel any update?