bicep module object output incomplete #4292
-
Hello Following scenario. param location string
param InstanceID string
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-04-01' = {
name: 'stbc${InstanceID}${uniqueString(resourceGroup().id)}'
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'Storage'
properties: {
supportsHttpsTrafficOnly: true
encryption: {
services: {
file: {
keyType: 'Account'
enabled: true
}
blob: {
keyType: 'Account'
enabled: true
}
}
keySource: 'Microsoft.Storage'
}
}
}
output outStorageAccount object = storageAccount If I use this object in an other module and / or main.bicep, I run in to an error.
_New-AzResourceGroupDeployment: 13:03:09 - The deployment 'bcdepl01' failed with error(s). Showing 2 out of 2 error(s). The error does not make a lot of sense to me, especially as the storage account clearly exist and if I do everything in the same bicep file, it works just fine. Also to read some other properties out of this object worked just fine. I was able to solve the problem now, by creating an output for every property of the storage account directly in the storageaccount.bicep file as a string. Instead of just a single object output and use the object like output outStorageAccountID string = storageAccount.id
output outStorageAccountName string = storageAccount.name
output storageAccountConnectionString string = 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(storageAccount.id, storageAccount.apiVersion).keys[0].value}' Is this expected and recommended to work with outputs for every property needed, or is it a bug? Any thoughts on this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
This is the expected behavior, in order to use a property from a resource declared in a module you need to make sure it's defined as an output in the module file. Your suggestion above to use all properties from the resources in modules has been discussed before in #923. I agree with you that the most natural way when authoring templates and consuming modules would be to be able to access all properties from the resources defined in the modules. Defining outputs for every possible scenario makes the authoring experience a bit clunky sometimes. I believe that this will be even more frustrating for user when we start to consume modules from the Bicep registry or template specs where the author might not even have permissions to publish an updated version of the module if another property is needed. |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for your answer. Highly appreciated.
I think my topic is slightly different than the one you posted.
I can see that it is expected behavior, that the output does not contain by default the whole resource. But what I did is, I declared the explicitly the whole resource as an object output with `output outStorageAccount object = storageAccount`. The fun thing is that my deployment works if I declare the following value as a string output already in the module with
```
output outStorageAccountConnectionString string = 'DefaultEndpointsProtocol=https;AccountName=${outStorageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(outStorageAccountID, outStorageAccount.apiVersion).keys[0].value}
```
But not if I use the object output properties in other bicep files as following.
```
'name': 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
'value':
DefaultEndpointsProtocol=https;AccountName=${outStorageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(outStorageAccountID, outStorageAccount.apiVersion).keys[0].value}'
```
I think it does make sense that not by default the whole object can be read, but it should be possible if I explicitly define the whole object as an output.
But maybe it’s just me who thinks that declare a whole object as output would be very handy instead of manually configure every single output string.
Cheers
|
Beta Was this translation helpful? Give feedback.
-
I don't believe we got to the bottom of your requirements here? Perhaps take a look at this PR and review if it meets some of your needs? Otherwise, feel free to provide some extra info in order resolve your query. |
Beta Was this translation helpful? Give feedback.
I don't believe we got to the bottom of your requirements here?
Perhaps take a look at this PR and review if it meets some of your needs?
#4971
Otherwise, feel free to provide some extra info in order resolve your query.