Skip to content

How to reference resource created with loop in another looped resource? #4817

Answered by alex-frankel
uky2019 asked this question in Q&A
Discussion options

You must be logged in to vote

Adding above solution as a new comment so I can mark this as the answer.


Ok, I just had to re-learn how the range() function works :) Thanks to the helpful bicep function signatures, I realized that I misunderstood what the second argument of the function is doing. It is responsible for the amount of items in the returned array. I thought it was the upper bound of the array, which is not right.

And if we look at the return value of output stuff array = range(1,2):

That results in trying to access nic[2] in the VM loop, which does not exist and we get this error.

If the goal is to make sure the NIC names and the VM names are the following:
test-nic1
test-nic2
test-vm1
test-vm2

Then this…

Replies: 8 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@brwilkinson
Comment options

@uky2019
Comment options

@alex-frankel
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@alex-frankel
Comment options

Comment options

You must be logged in to vote
1 reply
@alex-frankel
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by alex-frankel
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