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

Add validation for object-based parameters #6932

Closed
SSKLCP opened this issue May 23, 2022 · 1 comment
Closed

Add validation for object-based parameters #6932

SSKLCP opened this issue May 23, 2022 · 1 comment
Labels
enhancement New feature or request Needs: Triage 🔍

Comments

@SSKLCP
Copy link

SSKLCP commented May 23, 2022

Is your feature request related to a problem? Please describe.
I like the idea of passing in objects as parameters into my Bicep, I feel like it can make the parameter files nicer to write and can give the ability to logically separate the parameter file up into sections.

For example, instead of:


"sql_ServerName": {
    "value": "SQL_Server"
},
"sql_subscriptionID": {
    "value": "xxxxxx-xxxxxxxx-xxxxxxxx"
},
"sql_resourceGroup":{
    "value": "SQL-RG"
}

I can instead do:


"sqlSettings": {
  "value": {
      "serverName": "SQL_Server",
      "subscriptionID": "xxxxxx-xxxxxxxx-xxxxxxxx",
      "resourceGroup": "SQL-RG"
  }
}

But the problem that I get with this is that whilst the individual parameters can be set to be required / have required values, when passing in an object there seems to be very limited validation on what is passed in.

In the above example, the Bicep file won't run without me passing in sql_ServerName, sql_subscriptionID and sql_resourceGroup.
But I could pass in any object, even if the properties are wrong and the Bicep will at least try to run (and then likely fail down the line)

Ideally, I'd like for there to be a validation on the child properties of an object that gets passed in. This could also be very helpful for tagging resources, as in when you pass in a parameter like:

"Tags": {
  "value": {
      "Deployedby": "Bicep",
      "Owner": "Platforms Team",
      "Purpose": "Demo"
  }
}

Describe the solution you'd like
Add a new decorator for object parameters which evaluates whether an object has all of its "Required Properties"

for example:

@Properties([
  'Deployedby'
  'Owner'
  'Purpose'
])
param Tags Object

This would throw an error whenever an object is passed in without the required properties.

E.g. this would pass:


"Tags": {
    "value": {
        "Deployedby": "Bicep",
        "Owner": "Platforms Team",
        "Purpose": "Demo"
    }
}

This would fail:


"Tags": {
    "value": {
        "Deployedby": "Bicep",
        "Owner": "Platforms Team"
    }
}

A further improvement could be made (though this isn't a priority for me) by then allowing decorators on those properties, such as:

@Properties([
  @allowed([
      'Bicep'
   ])
  'Deployedby'
  @allowed([
      'Platforms Team'
      'Dev Team'
  ])
  'Owner'
  'Purpose'
])
param Tags Object

This is just my thoughts from the way that I'm used to working. If anyone does have a suggestion on how I should be using Bicep better to achieve the above then do let me know! Very interested to learn more :)

Let me know if you have any questions.

@SSKLCP SSKLCP added the enhancement New feature or request label May 23, 2022
@ghost ghost added the Needs: Triage 🔍 label May 23, 2022
@alex-frankel
Copy link
Collaborator

Closing as dup of #4158

@ghost ghost locked as resolved and limited conversation to collaborators May 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request Needs: Triage 🔍
Projects
None yet
Development

No branches or pull requests

2 participants