-
Notifications
You must be signed in to change notification settings - Fork 767
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
remove apiVersion requirement from list* functions when resource is defined in the template #3561
Comments
we have a mechanism to have instance methods on resources (developed for |
@bmoore-msft, @miqm - this has actually just been checked in under #3430. The API version is optional; by default we'll use the API version of the resource that is being referenced. Also note, we don't yet have type availability for list* functions; but it's something I'm hoping to get to soon. Here's an example of the syntax; we'll publicly document it for the next Bicep release: resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' = {
name: accountName
...
}
// use the resource's API version
output pkMethod string = stg.listKeys().keys[0].value
// use a custom API version
output pkMethod string = stg.listKeys('2020-01-01').keys[0].value |
Sweet:) |
@anthony-c-martin - a couple questions:
|
Only on a symbolic reference. There's no way to accurately obtain an API version for the standalone (string-based) equivalent AFAIK.
Currently only in the same template, but my plan is to leverage #2245 & #2246 to provide better options between modules. Of course with modules, you can always obtain a new symbolic reference using |
For for first one, we would know by the resourceId reference.... e.g. https://github.com/Azure/azure-quickstart-templates/blob/master/quickstarts/microsoft.web/function-premium-vnet-integration/main.bicep#L116 Since the first arg is a symbolic ref, we can grab the apiVersion from there... Though a better option might be to lint the use of listkeys with the type of arg since we might prefer |
So the request is to support a function signature like so? resource stg '...' = { ... }
output keys string = listKeys(stg).keys[0].value Is that right? If so, I'd prefer to not build support for a new function signature like that. Instead, just like you mention, we should push them to the new functionality that Anthony implemented via the linter. Thoughts? |
I think the spirit we're after is to minimize the places where I have to worry about apiVersions, when bicep already has one to use... In the case where things are all in the same deployment, linting this:
to be this:
seems like the right bicep sln. The next scenario would be when the stg account is in a different deployment (i.e. module)... can we simplify that case case to have the new sig you suggested (as the output). It's worth poking how we could but seems like a prereq to that is being able to say |
Isn't this what the |
yes, but as @anthony-c-martin mentioned it's a little tedious, and... we already know the information since it's in a module... if we require the existing syntax, it's easier just to use the independent function of listKeys(). |
Agreed - today. However I'm planning this with #2245 & #2246 in mind (to simplify the Some examples (and keep in mind that type safety, hovers, completions will work in all parts of the following): // resource reference
var accountKey = resource('Microsoft.Storage/storageAccounts@2019-06-01', accountName).listKeys().keys[0].value // param
param stg resource<'Microsoft.Storage/storageAccounts@2019-06-01'>
var accountkey = stg.listKeys().keys[0].value |
@bmoore-msft does this address your concerns? |
yep - the param route is golden - what would I pass in to a deployment for that though? |
Do you mean a module? If so, you would pass in the resource symbol directly. So if you had a resource like: resource stg '...' = { ... } Then you have a module that expects a storage resource: module thingThatNeedsStorage 'thingThatNeedsStorage.bicep' = {
name: 'foo'
params: {
storageAccount: stg
}
} If that looks good, should we close this issue? |
Not for the module but for the top level deployment... e.g. if I have this declaration in main.bicep param stg resource<'Microsoft.Storage/storageAccounts@2019-06-01'> What [string?] value is in my parameter file? a resourceId? |
Yep - a resource ID. I don't think it is 100% closed, but that's the plan unless we have a good reason to change it. |
Got it... it's probably worth thinking through a scenario where the constituent parts of the resource ID are used instead of a full uri (which are unwieldy to deal with as a human)... not sure common it will be but I suspect as the pattern catches on, moreso... |
Like reference, when we can assert and apiVersion for the function, don't require the user to supply it. More reasonable now that we have type info and can help with authoring.
A bonus would be to not require it when it's in a module (as I think this will probably be more common in bicep).
The text was updated successfully, but these errors were encountered: