44 *--------------------------------------------------------------------------------------------*/
55
66import { type NameValuePair , type Site , type SiteConfig , type WebSiteManagementClient } from '@azure/arm-appservice' ;
7- import { AuthorizationManagementClient } from '@azure/arm-authorization-profile-2020-09-01-hybrid ' ;
7+ import { type Identity } from '@azure/arm-resources ' ;
88import { BlobServiceClient } from '@azure/storage-blob' ;
99import { ParsedSite , WebsiteOS , type CustomLocation , type IAppServiceWizardContext } from '@microsoft/vscode-azext-azureappservice' ;
1010import { LocationListStep } from '@microsoft/vscode-azext-azureutils' ;
@@ -57,16 +57,6 @@ export class FunctionAppCreateStep extends AzureWizardExecuteStep<IFunctionAppWi
5757 context . telemetry . properties . fileLoggingError = parseError ( error ) . message ;
5858 }
5959 }
60- const principalId = nonNullProp ( nonNullProp ( context . site , 'identity' ) , 'principalId' ) ;
61- // this is the same apiVersion being used by the portal
62- const apiVersion = '2020-06-01' ;
63- const amClient = new AuthorizationManagementClient ( context . credentials , context . subscriptionId , { apiVersion } ) ;
64-
65- const scope = nonNullProp ( nonNullProp ( context , 'storageAccount' ) , 'id' ) ;
66- const guid = crypto . randomUUID ( ) ;
67- // this roleDefintionId cooresponds to the "Storage Blob Data Contributor" role
68- const roleDefinitionId = '/providers/Microsoft.Authorization/roleDefinitions/ba92f5b4-2d11-453d-a403-e96b0029c9fe' ;
69- await amClient . roleAssignments . create ( scope , guid , { properties : { roleDefinitionId, principalId } } ) ;
7060 showSiteCreated ( site , context ) ;
7161 }
7262
@@ -76,6 +66,14 @@ export class FunctionAppCreateStep extends AzureWizardExecuteStep<IFunctionAppWi
7666
7767 private async getNewSite ( context : IFunctionAppWizardContext , stack : FullFunctionAppStack ) : Promise < Site > {
7868 const location = await LocationListStep . getLocation ( context , webProvider ) ;
69+ let identity : Identity | undefined = undefined ;
70+ if ( context . managedIdentity ) {
71+ const userAssignedIdentities = { } ;
72+ userAssignedIdentities [ nonNullProp ( context . managedIdentity , 'id' ) ] =
73+ { principalId : context . managedIdentity ?. principalId , clientId : context . managedIdentity ?. clientId } ;
74+ identity = { type : 'UserAssigned' , userAssignedIdentities }
75+ }
76+
7977 const site : Site = {
8078 name : context . newSiteName ,
8179 kind : getSiteKind ( context ) ,
@@ -84,7 +82,7 @@ export class FunctionAppCreateStep extends AzureWizardExecuteStep<IFunctionAppWi
8482 clientAffinityEnabled : false ,
8583 siteConfig : await this . getNewSiteConfig ( context , stack ) ,
8684 reserved : context . newSiteOS === WebsiteOS . linux , // The secret property - must be set to true to make it a Linux plan. Confirmed by the team who owns this API.
87- identity : { type : 'SystemAssigned' }
85+ identity
8886 } ;
8987
9088 if ( context . customLocation ) {
0 commit comments