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

[Feature] Mechanism to create dependency when using existing keyword #9579

Closed
sinedied opened this issue Jan 19, 2023 · 1 comment
Closed
Labels
enhancement New feature or request Needs: Triage 🔍

Comments

@sinedied
Copy link
Member

Is your feature request related to a problem? Please describe.
When referencing resources using existing keyword, there's no way to create an explicit dependency to make it avoid erroring with a "not found" error.

To give some context, my templates are organised as such:

  • a main.bicep file using module to create all resources
  • modules files under modules/<name>.bicep

Inside a module, sometimes I need to access a resource created in other modules.
For that, I'm using the existing keyword, sometimes even with a condition based on parameters. For example, in module/staticwebapp.bicep I have something like this:

resource containerApp 'Microsoft.App/containerApps@2022-03-01' existing = if (linkedBackend && backendType == 'container') {
  name: 'ca-${containerName}-${containerUid}'
}

When referencing that existing container app, if it's not deployed yet I'll get a "Not found" error, which is expected. But it would like to have an option so that when the conditions are met, making that existing reference also creates a dependency to the containerApp resource, to avoid the error.

Adding the dependency explicitly at the module level in my main.bicep file would be possible, but it would mean duplicating all the parameter processing in that file too to determine the dependencies, defeating the purpose of having an isolated module.

Unless I missed something, I don't thing there's currently a way to "wait" for a resource referenced by an existing keyword to be created?

Describe the solution you'd like
I would like a feature so that when referencing resources using existing keyword, an explicit dependency is added to avoid "not found" errors. The dependency of course would be added only if the if condition on the resource is met.

@sinedied sinedied added the enhancement New feature or request label Jan 19, 2023
@ghost ghost added the Needs: Triage 🔍 label Jan 19, 2023
@alex-frankel
Copy link
Collaborator

alex-frankel commented Jan 24, 2023

Closing as dup of #2716.

The workaround is to find where you are using that existing resource and put the dependsOn in that resource to the module that creates the resource. Something like:

module createContainerApp 'createContainerApp.bicep' = { ... }

resource containerApp 'Microsoft.App/containerApps@2022-03-01' existing = ... { ... }

resource useContainerApp '...' = {
  ...
  properties: {
     someProp: containerApp.properties.foo
     ...
  }
  dependsOn: [ createContainerApp ] 
}

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

No branches or pull requests

2 participants