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

Ability to specify the shape of object parameters and variables #898

Closed
Va55ago opened this issue Nov 12, 2020 · 11 comments
Closed

Ability to specify the shape of object parameters and variables #898

Va55ago opened this issue Nov 12, 2020 · 11 comments
Labels
enhancement New feature or request

Comments

@Va55ago
Copy link

Va55ago commented Nov 12, 2020

Suggestion: When creating bicep modules, could the "shape" of any object parameters be specified. I.e.

param storageAccount object {
  prefix string,
  skuName string = "Standard_LRS",
  example_sub_object = {
    prop1 string,
    prop2 int = 2
  }
}

This would enable bicep to validate the usage of this parameter in the module and will also mean that VS Code can provide intellisense.

@ghost ghost added the Needs: Triage 🔍 label Nov 12, 2020
@alex-frankel alex-frankel added enhancement New feature or request and removed Needs: Triage 🔍 labels Nov 19, 2020
@alex-frankel
Copy link
Collaborator

It's a good idea, but there is a lot of design work to consider for a feature like this as it can get complex very quickly. We'd love to do it and think it'd be a powerful feature, but not something we will get to quickly.

This is somewhat related, but different from #114

@alex-frankel alex-frankel changed the title Ability to specify the shape of object parameters Ability to specify the shape of object parameters and variables Mar 15, 2021
@alex-frankel
Copy link
Collaborator

Added to title that this would also be useful for variables.

@aelij
Copy link
Member

aelij commented Mar 15, 2021

Adding my suggestion from #1871

Is your feature request related to a problem? Please describe.
Many times when we declare a variable, it represents a part of a larger type's schema. For example:

var agentPoolProfiles = [
  {
    name: 'primary'
    mode: 'System'
    count: nodeCount
    vmSize: vmSize
  }
]

resource aksCluster 'Microsoft.ContainerService/managedClusters@2020-12-01' = {
  name: clusterName
  location: clusterLocation
  properties: {
    agentPoolProfiles: agentPoolProfiles
  }
}

Right now there's no completion or validation for that variable.

Describe the solution you'd like

I would like to be able to specify a schema for a variable, e.g. using the type name from Swagger:

var agentPoolProfiles 'Microsoft.ContainerService/managedClusters@2020-12-01/ManagedClusterAgentPoolProfile[]' = [

@takekazuomi
Copy link
Contributor

Due to the lack of this function, it is difficult to use an object as a parameter. For those who use a template, I'm using the default to suggest a data structure. In that case, allow, secure, etc. cannot be used, which is quite inconvenient.
I'm waiting for this.

@majastrz
Copy link
Member

@takekazuomi Why can't you use secure or allowed with a default value on a parameter? Both the decorator and the deprecated modifier syntax should allow it.

@anthony-c-martin
Copy link
Member

Example of @allowed with default value:

@allowed([
'Always'
'Never'
'OnFailure'
])
param restartPolicy string = 'Always'

@takekazuomi
Copy link
Contributor

I didn't have enough words. I'm currently using the default to suggest a property of type object.

param foo object = {
  restartPolicy : 'Always'
  boo: 'some value'
}

However, in this case, I cannot use @Allowed or @Scure in default object values. It cannot be written as below.

param foo object = {
  @allowed([
    'Always'
    'Never'
    'OnFailure'
  ])
  restartPolicy : 'Always'
 
@secure
  boo: 'some value'
}

The dedicated syntax for defining the structure of an object is useful.

@miqm
Copy link
Collaborator

miqm commented Jul 7, 2021

I think this is related to what was discussed in #622

@Va55ago
Copy link
Author

Va55ago commented Jul 7, 2021

@miqm, #622 is discussing whether it should be possible to define resources without specifying their full resource provider & version. IMHO, that's a separate concern to being able to define the expected structure of custom object parameters and variables.

@miqm
Copy link
Collaborator

miqm commented Jul 7, 2021

I agree however if you look at the last comments we were discussing some approach how to define such types. I've just linked those two issues as they touches same mechanism in compiler.

@alex-frankel
Copy link
Collaborator

Closing and tracking with #4158

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

No branches or pull requests

7 participants