Skip to content

A better way to reference resources? #16324

Answered by johnlokerse
jachin84 asked this question in Q&A
Discussion options

You must be logged in to vote

I use the same approach as @slavizh. But if you don't want that (or like that) approach you can use User-Defined Functions to avoid repetition (= cleaner Bicep code):

func getResourceInformation(resourceId string) resourceInformationType => {
  subscriptionId: split(resourceId, '/')[2]
  resourceGroupName: split(resourceId, '/')[4]
  resourceName: last(split(resourceId, '/'))
}

type resourceInformationType = {
  subscriptionId: string
  resourceGroupName: string
  resourceName: string
}

To use it call the functions like this in your Bicep:

var varPrivateDnsZone = getResourceInformation('my-resource-id-here')

resource resDnsZone 'Microsoft.Network/privateDnsZones@2024-06-01' existing = {
  

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jachin84
Comment options

Answer selected by jachin84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants