Skip to content

Commit

Permalink
Fix default type definition for 'identity' property (#7489)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-c-martin authored Jul 5, 2022
1 parent 1dcad0c commit 33a8517
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
26 changes: 21 additions & 5 deletions src/Bicep.Core.IntegrationTests/ScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3232,6 +3232,11 @@ public void Test_Issue6423()
public void Test_Issue_3356_Accept_Correct_Type_Definitions()
{
var result = CompilationHelper.Compile(@"
resource msi 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = {
name: 'myIdentity'
location: resourceGroup().location
}
#disable-next-line BCP081
resource foo 'Microsoft.Storage/storageAccounts@2021-09-00' = {
name: 'test'
Expand All @@ -3251,11 +3256,15 @@ public void Test_Issue_3356_Accept_Correct_Type_Definitions()
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
clientId: 'client1'
principalId: 'principal1'
'${msi.id}': {}
}
}
}
output fooIdProps object = {
clientId: foo.identity.userAssignedIdentities[msi.id].clientId
principalId: foo.identity.userAssignedIdentities[msi.id].principalId
}
");
result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics();
}
Expand Down Expand Up @@ -3287,11 +3296,17 @@ public void Test_Issue_3356_Warn_On_Bad_Type_Definitions()
type: 'noType'
tenantId: 3
userAssignedIdentities: {
clientId: 1
principalId: 2
'blah': {
clientId: 1
principalId: 2
}
}
}
}
output fooBadIdProps object = {
clientId: foo.identity.userAssignedIdentities['blah'].hello
}
");
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
{
Expand All @@ -3302,7 +3317,8 @@ public void Test_Issue_3356_Warn_On_Bad_Type_Definitions()
("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."),
("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."),
("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."),
("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.")
("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."),
("BCP053", DiagnosticLevel.Error, "The type \"userAssignedIdentityProperties\" does not contain property \"hello\". Available properties include \"clientId\", \"principalId\"."),
});
}

Expand Down
12 changes: 7 additions & 5 deletions src/Bicep.Core/TypeSystem/Az/AzResourceTypeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,19 @@ public static IEnumerable<TypeProperty> KnownTopLevelResourceProperties()
new StringLiteralType("Actor"),
LanguageConstants.String);

var userAssignedIdentity = new ObjectType("userAssignedIdentityProperties", TypeSymbolValidationFlags.Default, new []
{
new TypeProperty("principalId", LanguageConstants.String),
new TypeProperty("clientId", LanguageConstants.String)
}, null);

yield return new TypeProperty("identity", new ObjectType("identity", TypeSymbolValidationFlags.Default, new[]
{
new TypeProperty("principalId", LanguageConstants.String),
new TypeProperty("tenantId", LanguageConstants.String),
new TypeProperty("type", resourceIdentityType, TypePropertyFlags.Required),
new TypeProperty("identityIds", new TypedArrayType(LanguageConstants.String, TypeSymbolValidationFlags.Default)),
new TypeProperty("userAssignedIdentities", new ObjectType("userAssignedIdentityProperties", TypeSymbolValidationFlags.Default, new []
{
new TypeProperty("principalId", LanguageConstants.String),
new TypeProperty("clientId", LanguageConstants.String)
}, null)),
new TypeProperty("userAssignedIdentities", new ObjectType("userAssignedIdentities", TypeSymbolValidationFlags.Default, Enumerable.Empty<TypeProperty>(), userAssignedIdentity)),
new TypeProperty("delegatedResources", LanguageConstants.Object),
}, null));
}
Expand Down

0 comments on commit 33a8517

Please sign in to comment.