Skip to content

Commit

Permalink
Use fully qualified symbolic name to refer to copy loop in dependsOn
Browse files Browse the repository at this point in the history
  • Loading branch information
jeskew committed Jan 28, 2025
1 parent 263d045 commit 7ffa2f4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/Bicep.Core.IntegrationTests/ScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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\"]");
}
}
4 changes: 2 additions & 2 deletions src/Bicep.Core/Emit/TemplateWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 7ffa2f4

Please sign in to comment.