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

Fix null 'name' property for resource to cause an error. #6348

Merged
merged 2 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/Bicep.Core.IntegrationTests/ScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2964,5 +2964,46 @@ param storageName string
});
}

/// <summary>
/// https://github.com/Azure/bicep/issues/5530
/// </summary>
[TestMethod]
public void Test_Issue_5530()
{
var result = CompilationHelper.Compile(@"
targetScope = 'subscription'

resource foo 'Microsoft.AAD/domainServices@2021-05-01' existing = {
scope: resourceGroup
name: 'foo'
}

resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01'
");
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[] {
("BCP018", DiagnosticLevel.Error, "Expected the \"=\" character at this location.")
});
}

/// <summary>
/// https://github.com/Azure/bicep/issues/5530
/// </summary>
[TestMethod]
public void Test_Issue_5530_2()
{
var result = CompilationHelper.Compile(@"
targetScope = 'tenant'

resource foo 'Microsoft.Authorization/policyAssignments@2021-06-01' existing = {
scope: managementGroup
name: 'foo'
}

resource managementGroup 'Microsoft.Management/managementGroups@2021-04-01'
");
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[] {
("BCP018", DiagnosticLevel.Error, "Expected the \"=\" character at this location.")
});
}
}
}
4 changes: 2 additions & 2 deletions src/Bicep.Core/Emit/ScopeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public class ScopeData
return null;
}

return new ScopeData { RequestedScope = ResourceScope.ResourceGroup, SubscriptionIdProperty = rgScopeData?.SubscriptionIdProperty, ResourceGroupProperty = targetResource.NameSyntax, IndexExpression = indexExpression };
return new ScopeData { RequestedScope = ResourceScope.ResourceGroup, SubscriptionIdProperty = rgScopeData?.SubscriptionIdProperty, ResourceGroupProperty = targetResource.TryGetNameSyntax(), IndexExpression = indexExpression };
}
}

Expand All @@ -173,7 +173,7 @@ public class ScopeData
return null;
}

return new ScopeData { RequestedScope = ResourceScope.ManagementGroup, ManagementGroupNameProperty = targetResource.NameSyntax, IndexExpression = indexExpression };
return new ScopeData { RequestedScope = ResourceScope.ManagementGroup, ManagementGroupNameProperty = targetResource.TryGetNameSyntax(), IndexExpression = indexExpression };
}
}

Expand Down