Skip to content

Commit 09e7629

Browse files
Fix for incorrect error diagnostic on MSGraph existing resource usage (#18160)
Quick fix for #18158 I think the root cause of the issue is that [ResourceTypeComponents](https://github.com/Azure/bicep/blob/2b1a61d6d6dbba88fb6f9dd798be7d2af5cfd90a/src/Bicep.Core/TypeSystem/Types/ResourceType.cs#L11) has a property named "ValidParentScopes", which is intended to capture both writable and readable scopes, but the type loading code was updated to be more precise about differentiating readable + writable scopes, and misinterpreted this field to just mean "writable scopes" (see [here](https://github.com/Azure/bicep/blob/2b1a61d6d6dbba88fb6f9dd798be7d2af5cfd90a/src/Bicep.Core/TypeSystem/Providers/Extensibility/ExtensionResourceTypeFactory.cs#L42))
1 parent 2b1a61d commit 09e7629

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

src/Bicep.Core.IntegrationTests/ExtensionRegistryTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,4 +946,28 @@ extension bar
946946
}
947947
""");
948948
}
949+
950+
[TestMethod]
951+
public async Task MSGraph_extension_1_0_0_is_valid()
952+
{
953+
// https://github.com/Azure/bicep/issues/18158
954+
var registry = "mcr.microsoft.com";
955+
var repository = "bicep/extensions/microsoftgraph/v1.0";
956+
957+
var services = ExtensionTestHelper.GetServiceBuilder(new MockFileSystem(), registry, repository, AllFeaturesEnabled);
958+
var typesTgz = new EmbeddedFile(typeof(ExtensionRegistryTests).Assembly, "Files/ExtensionTypes/msgraph-1.0.0-types.tgz");
959+
await RegistryHelper.PublishExtensionToRegistryAsync(services.Build(), $"br:{registry}/{repository}:1.0.0", typesTgz.BinaryData);
960+
961+
var result = await CompilationHelper.RestoreAndCompile(services, """
962+
param application object
963+
964+
extension 'br:mcr.microsoft.com/bicep/extensions/microsoftgraph/v1.0:1.0.0' as microsoftGraphV1_0
965+
966+
resource ownerUsers 'Microsoft.Graph/[email protected]' existing = [for (owner, i) in application.owners: {
967+
userPrincipalName: owner.upn
968+
}]
969+
""");
970+
971+
result.Should().NotHaveAnyCompilationBlockingDiagnostics();
972+
}
949973
}
Binary file not shown.

src/Bicep.Core.UnitTests/Baselines/EmbeddedFile.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ public record EmbeddedFile(
1111
Assembly Assembly,
1212
string StreamPath)
1313
{
14-
private readonly Lazy<string> contentsLazy = new(() =>
15-
{
16-
var stream = Assembly.GetManifestResourceStream(StreamPath);
17-
18-
return new StreamReader(stream!).ReadToEnd();
19-
});
14+
private readonly Lazy<BinaryData> binaryDataLazy = new(() => BinaryData.FromStream(Assembly.GetManifestResourceStream(StreamPath)!));
15+
private readonly Lazy<string> contentsLazy = new(() => new StreamReader(Assembly.GetManifestResourceStream(StreamPath)!).ReadToEnd());
2016

2117
public string Contents => contentsLazy.Value;
2218

19+
public BinaryData BinaryData => binaryDataLazy.Value;
20+
2321
public string FileName => Path.GetFileName(StreamPath);
2422

2523
public string RelativeSourcePath => Path.Combine("src", Assembly.GetName().Name!, StreamPath);

src/Bicep.Core/TypeSystem/Providers/Extensibility/ExtensionResourceTypeFactory.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ public ResourceTypeComponents GetResourceType(Azure.Bicep.Types.Concrete.Resourc
3939
var (readableScopes, writableScopes) = GetScopeInfo(resourceType);
4040
var readOnlyScopes = readableScopes & ~writableScopes;
4141

42-
return new ResourceTypeComponents(resourceTypeReference, writableScopes, readOnlyScopes, ToResourceFlags(resourceType), bodyType);
42+
// Temporary fix for https://github.com/Azure/bicep/issues/18158
43+
var validParentScopes = readableScopes | writableScopes;
44+
45+
return new ResourceTypeComponents(resourceTypeReference, validParentScopes, readOnlyScopes, ToResourceFlags(resourceType), bodyType);
4346
}
4447

4548
public TypeSymbol GetConfigurationType(Azure.Bicep.Types.Concrete.TypeBase configurationType)

0 commit comments

Comments
 (0)