-
Notifications
You must be signed in to change notification settings - Fork 756
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
dependsOn not allowed on existing resources #2716
Comments
|
targetScope = 'subscription'
param rgName string
module createRg 'createRg.bicep' = {
name: 'foo'
params: {
rgName: rgName
}
}
resource rg 'Microsoft.Resources/resourceGroups@2021-01-01' existing = {
name: rgName
dependsOn: [
createRg
]
}
module srch 'search.template.bicep' = {
name: '${deployment().name}-1'
scope: rg
params: {
search_name: 'foo'
search_location: 'westus'
}
}
targetScope = 'subscription'
param rgName string
resource rg 'Microsoft.Resources/resourceGroups@2021-01-01' = {
name: rgName
location: 'westus'
}
param search_name string
param search_location string
resource search 'Microsoft.Search/searchServices@2020-08-01' = {
name: search_name
location: search_location
properties: {
replicaCount: 1
partitionCount: 1
}
sku: {
name: 'standard'
}
}
|
What I want to understand is what you plan to do with the existing |
I've updated the previous reply to have a coherent story. The idea is to create resources within the newly-created resource group.
targetScope = 'subscription'
param rgName string
resource rg 'Microsoft.Resources/resourceGroups@2021-01-01' = {
name: rgName
location: 'westus'
}
output resourceGroup object = rg * targetScope = 'subscription'
param rgName string
module createRg 'createRg.bicep' = {
name: 'foo'
params: {
rgName: rgName
}
}
module srch 'search.template.bicep' = {
name: '${deployment().name}-1'
scope: createRg.outputs.resourceGroup
params: {
search_name: 'foo'
search_location: 'westus'
}
} yield:
|
Looks like the #622 output types could be a step toward helping in solving the dependsOn problem. |
Gotcha - I think the problem will be solved once #2245 is done, as you'll be able to output the rg resource as a "resource" type. Then you could do: createRg.bicep ...
output rg resource = rg then azuredeploy.bicep module srch 'search.template.bicep' = {
name: '${deployment().name}-1'
scope: createRg.outputs.rg
params: {
search_name: 'foo'
search_location: 'westus'
}
} In the meantime, you can avoid the targetScope = 'subscription'
param rgName string
module createRg 'createRg.bicep' = {
name: 'foo'
params: {
rgName: rgName
}
}
module srch 'search.template.bicep' = {
name: '${deployment().name}-1'
scope: resourceGroup(rgName)
params: {
search_name: 'foo'
search_location: 'westus'
}
dependsOn: [
createRg
]
} If you want to avoid the explicit dependsOn, it might work if you output the |
Hi, I have the same issue with storage account keys. I want to use the listKeys(), but this is not working with modules. error: This expression is being used in an argument of the function "listKeys", which requires a value that can be calculated at the start of the deployment. Properties of stg which can be calculated at the start include "name".bicep(BCP181) resource auditingSettings 'Microsoft.Sql/servers/auditingSettings@2021-05-01-Preview' = {
parent: sqlServer
name: 'default'
properties: {
state: auditingSettingsState
storageEndpoint: '${stg.outputs.primaryEndpointsBlob}'
storageAccountAccessKey: listKeys(stg.outputs.resourceId, providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value
retentionDays: auditRententionInDays
auditActionsAndGroups: null
storageAccountSubscriptionId: subscription().subscriptionId
isStorageSecondaryKeyInUse: false
}
} do we have a solution for this as well? |
@DylanPrinsITScripts -- can you instead re-establish the reference to the existing resource? If the storage account is in a different scope than the current module, it may get a little tricky though. resource existingStorage 'Microsoft.Storage/storageAccounts@2021-06-01' existing = {
name: ...
}
...
resource auditingSettings 'Microsoft.Sql/servers/auditingSettings@2021-05-01-Preview' = {
parent: sqlServer
name: 'default'
properties: {
state: auditingSettingsState
storageEndpoint: stg.outputs.primaryEndpointsBlob
storageAccountAccessKey: existingStorage.listKeys.keys[0].value
retentionDays: auditRententionInDays
auditActionsAndGroups: null
storageAccountSubscriptionId: subscription().subscriptionId
isStorageSecondaryKeyInUse: false
}
} BTW, I got rid of some unnecessary interpolation in the |
Hi Alex, Thanks for your reply.
|
Sorry it should be |
This is a major bug where especially with key vault deployments. |
@alex-frankel per you response above for the original issue : Whist I get where you are going with this, say an organization has a naming/tagging policy for resource group creation, and that wants to encapsulate that in a module. In your example above the name the resource group is not know before the module is invoked, so one really does want to use the output of the module to get to the created resource group and specifically its name to pas into the subsequent modules Generally one would assume that if one get up a matching Any help greatly appreciated!
|
Currently, it's a limitation in what bicep is able to comprehend at "compile-time". When a resource is created in a module, it's outputs are considered "run-time" properties that we can't calculate upfront. @SPSCS-Simon -- personally, for the reasons you are describing, I think creating a resource group in a module is an anti-pattern. Resource groups are simple enough that it shouldn't be too onerous to ask users to maintain the "raw" resource definition. I recognize this makes it harder to enforce naming conventions though. I'm hoping that #2245/#2246 should open the door to enable the scenario you are describing. I know there are a lot of others wanting/doing similar things. |
I'm having a similar problem, but with SQL Servers. The desired functionality is to create SQL Server inside the module, then reference it in the parent template to create SQL DBs. However:
The solution I found was to forget about refencing the SQL Server on the parent template. Just create all databases, with |
Fixed in #15459 |
Bicep version
0.3.539
Describe the bug
To Reproduce
See the file above
Additional context
The idea is to create a resource group in a module and trying to solve the issue from #1431, where an existing resource group resource would depend on that module.
The text was updated successfully, but these errors were encountered: