Skip to content

Commit 33a8517

Browse files
Fix default type definition for 'identity' property (#7489)
1 parent 1dcad0c commit 33a8517

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/Bicep.Core.IntegrationTests/ScenarioTests.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,6 +3232,11 @@ public void Test_Issue6423()
32323232
public void Test_Issue_3356_Accept_Correct_Type_Definitions()
32333233
{
32343234
var result = CompilationHelper.Compile(@"
3235+
resource msi 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = {
3236+
name: 'myIdentity'
3237+
location: resourceGroup().location
3238+
}
3239+
32353240
#disable-next-line BCP081
32363241
resource foo 'Microsoft.Storage/storageAccounts@2021-09-00' = {
32373242
name: 'test'
@@ -3251,11 +3256,15 @@ public void Test_Issue_3356_Accept_Correct_Type_Definitions()
32513256
identity: {
32523257
type: 'UserAssigned'
32533258
userAssignedIdentities: {
3254-
clientId: 'client1'
3255-
principalId: 'principal1'
3259+
'${msi.id}': {}
32563260
}
32573261
}
32583262
}
3263+
3264+
output fooIdProps object = {
3265+
clientId: foo.identity.userAssignedIdentities[msi.id].clientId
3266+
principalId: foo.identity.userAssignedIdentities[msi.id].principalId
3267+
}
32593268
");
32603269
result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics();
32613270
}
@@ -3287,11 +3296,17 @@ public void Test_Issue_3356_Warn_On_Bad_Type_Definitions()
32873296
type: 'noType'
32883297
tenantId: 3
32893298
userAssignedIdentities: {
3290-
clientId: 1
3291-
principalId: 2
3299+
'blah': {
3300+
clientId: 1
3301+
principalId: 2
3302+
}
32923303
}
32933304
}
32943305
}
3306+
3307+
output fooBadIdProps object = {
3308+
clientId: foo.identity.userAssignedIdentities['blah'].hello
3309+
}
32953310
");
32963311
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
32973312
{
@@ -3302,7 +3317,8 @@ public void Test_Issue_3356_Warn_On_Bad_Type_Definitions()
33023317
("BCP036", DiagnosticLevel.Warning, "The property \"capacity\" expected a value of type \"int\" but the provided value is of type \"'2'\". If this is an inaccuracy in the documentation, please report it to the Bicep Team."),
33033318
("BCP036", DiagnosticLevel.Warning, "The property \"tenantId\" expected a value of type \"string\" but the provided value is of type \"int\". If this is an inaccuracy in the documentation, please report it to the Bicep Team."),
33043319
("BCP036", DiagnosticLevel.Warning, "The property \"clientId\" expected a value of type \"string\" but the provided value is of type \"int\". If this is an inaccuracy in the documentation, please report it to the Bicep Team."),
3305-
("BCP036", DiagnosticLevel.Warning, "The property \"principalId\" expected a value of type \"string\" but the provided value is of type \"int\". If this is an inaccuracy in the documentation, please report it to the Bicep Team.")
3320+
("BCP036", DiagnosticLevel.Warning, "The property \"principalId\" expected a value of type \"string\" but the provided value is of type \"int\". If this is an inaccuracy in the documentation, please report it to the Bicep Team."),
3321+
("BCP053", DiagnosticLevel.Error, "The type \"userAssignedIdentityProperties\" does not contain property \"hello\". Available properties include \"clientId\", \"principalId\"."),
33063322
});
33073323
}
33083324

src/Bicep.Core/TypeSystem/Az/AzResourceTypeProvider.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,19 @@ public static IEnumerable<TypeProperty> KnownTopLevelResourceProperties()
196196
new StringLiteralType("Actor"),
197197
LanguageConstants.String);
198198

199+
var userAssignedIdentity = new ObjectType("userAssignedIdentityProperties", TypeSymbolValidationFlags.Default, new []
200+
{
201+
new TypeProperty("principalId", LanguageConstants.String),
202+
new TypeProperty("clientId", LanguageConstants.String)
203+
}, null);
204+
199205
yield return new TypeProperty("identity", new ObjectType("identity", TypeSymbolValidationFlags.Default, new[]
200206
{
201207
new TypeProperty("principalId", LanguageConstants.String),
202208
new TypeProperty("tenantId", LanguageConstants.String),
203209
new TypeProperty("type", resourceIdentityType, TypePropertyFlags.Required),
204210
new TypeProperty("identityIds", new TypedArrayType(LanguageConstants.String, TypeSymbolValidationFlags.Default)),
205-
new TypeProperty("userAssignedIdentities", new ObjectType("userAssignedIdentityProperties", TypeSymbolValidationFlags.Default, new []
206-
{
207-
new TypeProperty("principalId", LanguageConstants.String),
208-
new TypeProperty("clientId", LanguageConstants.String)
209-
}, null)),
211+
new TypeProperty("userAssignedIdentities", new ObjectType("userAssignedIdentities", TypeSymbolValidationFlags.Default, Enumerable.Empty<TypeProperty>(), userAssignedIdentity)),
210212
new TypeProperty("delegatedResources", LanguageConstants.Object),
211213
}, null));
212214
}

0 commit comments

Comments
 (0)