-
Notifications
You must be signed in to change notification settings - Fork 775
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
using module outputs in reference results into errors #2526
Comments
Looking at your output from the output storageAccount object = {
id: stg.id
name: stg.name
apiVersion: stg.apiVersion
} Shouldn't this reference: stgModule.outputs.storageAccount.name.apiVersion instead be: stgModule.outputs.storageAccount.apiVersion As a side note, this would have benefited from the planned improvements to give you the ability to output a resource and then we could have validated this. |
Sorry, my bad when extracting the bicep templates from my original project I've made a typo.
I've removed the error and included the fixed template: |
@bmoore-msft - do we not allow For this line: 'DefaultEndpointsProtocol=https;AccountName=${stgModule.outputs.storageAccount.name};AccountKey=${listKeys(stgModule.outputs.storageAccount.id, stgModule.outputs.storageAccount.apiVersion).keys[0].value}'
...
"siteConfig": {
"appSettings": [
{
"name": "AzureWebJobsStorage",
"value": "[format('DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}', reference(resourceId('Microsoft.Resources/deployments', parameters('functionApp').storageAccount.name), '2019-10-01').outputs.storageAccount.value.name, listKeys(reference(resourceId('Microsoft.Resources/deployments', parameters('functionApp').storageAccount.name), '2019-10-01').outputs.storageAccount.value.id, reference(resourceId('Microsoft.Resources/deployments', parameters('functionApp').storageAccount.name), '2019-10-01').outputs.storageAccount.value.name.apiVersion).keys[0].value)]"
},
... |
You can use in reference() in appSettings but you cannot use reference() within another runtime function - which is what the module output is trying to do... This: value: 'DefaultEndpointsProtocol=https;AccountName=${stgModule.outputs.storageAccount.name};AccountKey=${listKeys(stgModule.outputs.storageAccount.id, stgModule.outputs.storageAccount.name.apiVersion).keys[0].value}'
needs to be: value: 'DefaultEndpointsProtocol=https;AccountName=${functionApp.storage.name};AccountKey=${listKeys(resourceId('Microsoft.Storage/storageAccounts', functionApp.storageAccount.name), '2021-04-01').keys[0].value}' Notes:
|
@bmoore-msft Last night I've extracted the storage account resource from the module and added it to the function app deployment as a resource. When I use the resource outputs as inputs in the value, the deployment works fine. Not exactly what I want but it seems to me that the problem lies in using module outputs instead of regular outputs.
I don't completely agree with you on the expression part of this one. In Bicep the resource Type includes the API Version used. |
I didn't know that |
Looks like @alex-frankel covered the first question... re: apiVersion - the shape of the object returned on listKeys() is determined by that apiVersion - i.e. the properties you reference > keys[0].value. If that apiVersion is an expression that's used in a module elsewhere it requires you to also scrub indirect uses of it to ensure they aren't broken. So you're creating a dependency that doesn't provide any benefit (since it needs to be authored and maintained separately) but creates risk. Another way to look at it - the apiVersion used to create the resource has no effect on accessing that resource via listKeys. They are unrelated/independent api calls. That help? |
I think I understand it now. So if I'm correct, there are two options left (and one nobody should use): 1. Don't use a module in this case, rather use a resource deployment that doesn't give any errors. 2. Use the suggested value by @bmoore-msft A third Bad suggestion could be: Moving the creation of the connection string to the Storage Account Module. Con's:
The last one could be the best option if there was a possibility to secure output variables. What would be your suggested go to option? |
$0.02 #1 - I'm not sure I understand why there would be 2 templates for the storageAccount, but seems like not allowing a module (which is needed for the fix) may be too restrictive... #2 - good catch on the dependsOn, though I'm not sure I understand why that's a con... the dependency is there regardless, just a difference of whether it's visible in bicep. @alex-frankel - a bizzarre idea here would be to look for the use of an expression that uses the name property of another resource in the template - and use that as an indication that we should add an implicit dependency. Definitely needs more thinking, but may help here... #3 - I don't know that we'll ever get to the point where everyone will be satisfied with the use of arbitrary secrets in the deployment engine - they should be in keyvault and reference by the resource (ideally)... TDLR I wouldn't use this one or wait for the ideal handling of it. (oh sorry - and if I had to pick I'd pick #2) |
Bicep version
Bicep CLI version 0.3.255 (589f037)
Describe the bug
When using modules, using the module output results in errors while referencing them in a other Bicep file.
In my case a Function App with App settings. Here I want to reference the Storage Account connection string.
error: The template function 'reference' is not expected at this location.
This bug doesn't occur when using a resource deployment of a storage Account instead of using a module.
Desired solution: the possibility to use module outputs in combination with reference functions
To Reproduce
See provided bicep templates: Bicep issue sample.zip
Additional context
The error occurs when I want to link the outputs in a Azure Function appSetting : AzureWebJobsStorage.
Outputs used:
sample:
'DefaultEndpointsProtocol=https;AccountName=${stgModule.outputs.storageAccount.name};AccountKey=${listKeys(stgModule.outputs.storageAccount.id, stgModule.outputs.storageAccount.name.apiVersion).keys[0].value}'
The text was updated successfully, but these errors were encountered: