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

Best mechanism for converting a resource ID into name/resourceGroup/subscription? #10872

Closed
adrianhall opened this issue Jun 1, 2023 · 1 comment

Comments

@adrianhall
Copy link
Member

I want to use resources created outside of my bicep template - for example, using a database server or API Management instance, but allowing my bicep template to create the database or API. To do this, I want to pass the ID of the resource as a parameter and then decode it to get the reference to the resource.

targetScope = 'resourceGroup'

@description('ID of the database service')
param databaseServiceId string

resource databaseService 'Microsoft.Network/sqlServers@2022-08-01' existing = {
  name: reference(databaseServiceId).name
  scope: reference(databaseServiceId).resourceGroup
}

Obviously, the reference function exists, but the resourceGroup, etc. don't.

What's the best way to get a reference to a resource based on the ID, so that it can be used for resource creation in the rest of the bicep script?

@alex-frankel
Copy link
Collaborator

The best way to do this is with the split() function. There's an example provided here:
#1722 (comment)

But #2245/#2246 will address this more completely, so going to close this.

@github-project-automation github-project-automation bot moved this from Todo to Done in Bicep Jun 1, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jul 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

2 participants