Skip to content

Commit 8ec4d38

Browse files
authored
Allow injecting available hosting plans into FunctionAppHostingPlanStep. Update DTS plans to include Flex Consumption (#4863)
1 parent bccde31 commit 8ec4d38

File tree

2 files changed

+55
-31
lines changed

2 files changed

+55
-31
lines changed

src/commands/createFunctionApp/FunctionAppHostingPlanStep.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,41 @@ import { createHttpHeaders, createPipelineRequest } from '@azure/core-rest-pipel
88
import { setLocationsTask, WebsiteOS, type IAppServiceWizardContext } from '@microsoft/vscode-azext-azureappservice';
99
import { createGenericClient, LocationListStep, type AzExtPipelineResponse, type AzExtRequestPrepareOptions } from '@microsoft/vscode-azext-azureutils';
1010
import { AzureWizardPromptStep, type IAzureQuickPickItem } from '@microsoft/vscode-azext-utils';
11-
import { DurableBackend } from '../../constants';
1211
import { localize } from '../../localize';
1312
import { getRandomHexString } from '../../utils/fs';
1413
import { nonNullProp } from '../../utils/nonNull';
1514
import { type IFunctionAppWizardContext } from './IFunctionAppWizardContext';
1615

17-
const premiumSkuFilter = /^EP$/i;
16+
export enum FunctionAppHostingPlans {
17+
Flex,
18+
Consumption,
19+
Premium,
20+
AppService,
21+
}
22+
23+
export const allAvailableFunctionAppHostingPlans = new Set([FunctionAppHostingPlans.Flex, FunctionAppHostingPlans.Consumption, FunctionAppHostingPlans.Premium, FunctionAppHostingPlans.AppService]);
24+
1825
export class FunctionAppHostingPlanStep extends AzureWizardPromptStep<IFunctionAppWizardContext> {
26+
constructor(private readonly availablePlans: Set<FunctionAppHostingPlans>) {
27+
super();
28+
}
29+
1930
public async prompt(context: IFunctionAppWizardContext): Promise<void> {
20-
const placeHolder: string = localize('selectHostingPlan', 'Select a hosting plan.');
21-
const picks: IAzureQuickPickItem<[boolean, boolean, RegExp | undefined]>[] = [
22-
{ label: localize('flexConsumption', 'Flex Consumption'), data: [false, true, undefined] },
23-
{ label: localize('consumption', 'Consumption'), description: localize('legacy', 'Legacy'), data: [true, false, undefined] },
24-
{ label: localize('premium', 'Premium'), data: [false, false, premiumSkuFilter] },
25-
{ label: localize('dedicated', 'App Service Plan'), data: [false, false, /^((?!EP|Y|FC).)*$/i] }
26-
];
31+
const picks: IAzureQuickPickItem<[boolean, boolean, RegExp | undefined]>[] = [];
32+
if (this.availablePlans.has(FunctionAppHostingPlans.Flex)) {
33+
picks.push({ label: localize('flexConsumption', 'Flex Consumption'), data: [false, true, undefined] });
34+
}
35+
if (this.availablePlans.has(FunctionAppHostingPlans.Consumption)) {
36+
picks.push({ label: localize('consumption', 'Consumption'), description: localize('legacy', 'Legacy'), data: [true, false, undefined] });
37+
}
38+
if (this.availablePlans.has(FunctionAppHostingPlans.Premium)) {
39+
picks.push({ label: localize('premium', 'Premium'), data: [false, false, /^EP$/i] });
40+
}
41+
if (this.availablePlans.has(FunctionAppHostingPlans.AppService)) {
42+
picks.push({ label: localize('dedicated', 'App Service Plan'), data: [false, false, /^((?!EP|Y|FC).)*$/i] });
43+
}
2744

45+
const placeHolder: string = localize('selectHostingPlan', 'Select a hosting plan.');
2846
[context.useConsumptionPlan, context.useFlexConsumptionPlan, context.planSkuFamilyFilter] = (await context.ui.showQuickPick(picks, { placeHolder, learnMoreLink: 'aka.ms/flexconsumption' })).data;
2947
await setLocationsTask(context);
3048
if (context.useConsumptionPlan) {
@@ -39,15 +57,7 @@ export class FunctionAppHostingPlanStep extends AzureWizardPromptStep<IFunctionA
3957
}
4058

4159
public configureBeforePrompt(context: IFunctionAppWizardContext): void | Promise<void> {
42-
if (context.durableStorageType === DurableBackend.DTS) {
43-
// premium is required for DTS
44-
if (context.advancedCreation) {
45-
// allows users to select/create a Elastic Premium plan
46-
context.planSkuFamilyFilter = premiumSkuFilter;
47-
} else {
48-
setPremiumPlanProperties(context);
49-
}
50-
} else if (context.useFlexConsumptionPlan) {
60+
if (context.useFlexConsumptionPlan) {
5161
setFlexConsumptionPlanProperties(context);
5262
}
5363
}
@@ -66,16 +76,6 @@ function setFlexConsumptionPlanProperties(context: IAppServiceWizardContext): vo
6676
LocationListStep.setLocationSubset(context, getFlexLocations(context), 'Microsoft.WebFlex');
6777
}
6878

69-
function setPremiumPlanProperties(context: IAppServiceWizardContext): void {
70-
context.newPlanName = `PREMIUM-${nonNullProp(context, 'newSiteName')}-${getRandomHexString(4)}`;
71-
context.newPlanSku = {
72-
name: 'P1v2',
73-
tier: 'Premium V2',
74-
size: 'P1v2',
75-
family: 'Pv2'
76-
};
77-
}
78-
7979
async function getFlexLocations(context: IAppServiceWizardContext): Promise<string[]> {
8080
const headers = createHttpHeaders({
8181
'Content-Type': 'application/json',

src/commands/createFunctionApp/createCreateFunctionAppComponents.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import { AppInsightsCreateStep, AppInsightsListStep, AppKind, AppServicePlanCrea
77
import { CommonRoleDefinitions, createRoleId, LocationListStep, ResourceGroupCreateStep, ResourceGroupListStep, RoleAssignmentExecuteStep, StorageAccountCreateStep, StorageAccountKind, StorageAccountListStep, StorageAccountPerformance, StorageAccountReplication, type INewStorageAccountDefaults, type Role } from "@microsoft/vscode-azext-azureutils";
88
import { type AzureWizardExecuteStep, type AzureWizardPromptStep, type ISubscriptionContext } from "@microsoft/vscode-azext-utils";
99
import { FuncVersion, latestGAVersion, tryParseFuncVersion } from "../../FuncVersion";
10-
import { funcVersionSetting } from "../../constants";
10+
import { DurableBackend, funcVersionSetting } from "../../constants";
1111
import { tryGetLocalFuncVersion } from "../../funcCoreTools/tryGetLocalFuncVersion";
1212
import { type ICreateFunctionAppContext } from "../../tree/SubscriptionTreeItem";
1313
import { createActivityContext } from "../../utils/activityUtils";
1414
import { durableUtils } from "../../utils/durableUtils";
1515
import { getRootFunctionsWorkerRuntime, getWorkspaceSetting, getWorkspaceSettingFromAnyFolder } from "../../vsCodeConfig/settings";
1616
import { AuthenticationPromptStep } from "./AuthenticationPromptStep";
1717
import { FunctionAppCreateStep } from "./FunctionAppCreateStep";
18-
import { FunctionAppHostingPlanStep } from "./FunctionAppHostingPlanStep";
18+
import { allAvailableFunctionAppHostingPlans, FunctionAppHostingPlans, FunctionAppHostingPlanStep } from "./FunctionAppHostingPlanStep";
1919
import { type IFunctionAppWizardContext } from "./IFunctionAppWizardContext";
2020
import { ConfigureCommonNamesStep } from "./UniqueNamePromptStep";
2121
import { ContainerizedFunctionAppCreateStep } from "./containerImage/ContainerizedFunctionAppCreateStep";
@@ -150,7 +150,9 @@ async function createFunctionAppWizard(wizardContext: IFunctionAppWizardContext)
150150
const promptSteps: AzureWizardPromptStep<IAppServiceWizardContext>[] = [];
151151
const executeSteps: AzureWizardExecuteStep<IAppServiceWizardContext>[] = [];
152152

153-
promptSteps.push(new FunctionAppHostingPlanStep());
153+
promptSteps.push(new FunctionAppHostingPlanStep(
154+
getAvailableFunctionAppHostingPlans(wizardContext) /** availablePlans */,
155+
));
154156
CustomLocationListStep.addStep(wizardContext, promptSteps);
155157

156158
promptSteps.push(new FunctionAppStackStep());
@@ -177,3 +179,25 @@ async function createContainerizedFunctionAppWizard(): Promise<{ promptSteps: Az
177179

178180
return { promptSteps, executeSteps };
179181
}
182+
183+
function getAvailableFunctionAppHostingPlans(context: IFunctionAppWizardContext): Set<FunctionAppHostingPlans> {
184+
const availablePlans: Set<FunctionAppHostingPlans> = new Set();
185+
186+
switch (true) {
187+
case context.useFlexConsumptionPlan:
188+
availablePlans.add(FunctionAppHostingPlans.Flex);
189+
break;
190+
191+
case context.durableStorageType === DurableBackend.DTS:
192+
if (context.advancedCreation) {
193+
availablePlans.add(FunctionAppHostingPlans.Premium);
194+
}
195+
availablePlans.add(FunctionAppHostingPlans.Flex);
196+
break;
197+
198+
default:
199+
return allAvailableFunctionAppHostingPlans;
200+
}
201+
202+
return availablePlans;
203+
}

0 commit comments

Comments
 (0)