diff --git a/src/Bicep.Core.IntegrationTests/ScenarioTests.cs b/src/Bicep.Core.IntegrationTests/ScenarioTests.cs index dc82de7cec2..df1ec4fa5ba 100644 --- a/src/Bicep.Core.IntegrationTests/ScenarioTests.cs +++ b/src/Bicep.Core.IntegrationTests/ScenarioTests.cs @@ -6747,4 +6747,30 @@ param descriptionParam string ("BCP265", DiagnosticLevel.Error, "The name \"description\" is not a function. Did you mean \"sys.description\"?"), }); } + + [TestMethod] + public void Test_Issue16230() + { + var result = CompilationHelper.Compile(""" + resource identity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = { + name: 'foo' + + resource federation 'federatedIdentityCredentials' = [for i in range(0, 10): { + name: 'fed_${i}' + }] + } + + resource otherIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = { + name: 'bar' + location: resourceGroup().location + dependsOn: [ + identity::federation + ] + } + """); + + result.Should().NotHaveAnyCompilationBlockingDiagnostics(); + result.Template.Should().NotBeNull(); + result.Template.Should().HaveJsonAtPath("$.resources[?(@.name == 'bar')].dependsOn", "[\"identity::federation\"]"); + } } diff --git a/src/Bicep.Core/Emit/TemplateWriter.cs b/src/Bicep.Core/Emit/TemplateWriter.cs index 77eb2cd7ac5..afdba68f91b 100644 --- a/src/Bicep.Core/Emit/TemplateWriter.cs +++ b/src/Bicep.Core/Emit/TemplateWriter.cs @@ -1565,8 +1565,8 @@ private static void EmitClassicDependsOnEntry(ExpressionEmitter emitter, Resourc if (resource.Symbol.IsCollection && reference.IndexContext?.Index is null) { // dependency is on the entire resource collection - // write the name of the resource collection as the dependency - emitter.EmitExpression(new StringLiteralExpression(null, resource.Symbol.DeclaringResource.Name.IdentifierName)); + // write the fully qualified name of the resource collection (this is the name of the copy loop) as the dependency + emitter.EmitSymbolReference(resource); break; }