Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions src/commands/createFunctionApp/FunctionAppHostingPlanStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,41 @@ import { createHttpHeaders, createPipelineRequest } from '@azure/core-rest-pipel
import { setLocationsTask, WebsiteOS, type IAppServiceWizardContext } from '@microsoft/vscode-azext-azureappservice';
import { createGenericClient, LocationListStep, type AzExtPipelineResponse, type AzExtRequestPrepareOptions } from '@microsoft/vscode-azext-azureutils';
import { AzureWizardPromptStep, type IAzureQuickPickItem } from '@microsoft/vscode-azext-utils';
import { DurableBackend } from '../../constants';
import { localize } from '../../localize';
import { getRandomHexString } from '../../utils/fs';
import { nonNullProp } from '../../utils/nonNull';
import { type IFunctionAppWizardContext } from './IFunctionAppWizardContext';

const premiumSkuFilter = /^EP$/i;
export enum FunctionAppHostingPlans {
Flex,
Consumption,
Premium,
AppService,
}

export const allAvailableFunctionAppHostingPlans = new Set([FunctionAppHostingPlans.Flex, FunctionAppHostingPlans.Consumption, FunctionAppHostingPlans.Premium, FunctionAppHostingPlans.AppService]);

export class FunctionAppHostingPlanStep extends AzureWizardPromptStep<IFunctionAppWizardContext> {
constructor(private readonly availablePlans: Set<FunctionAppHostingPlans>) {
super();
}

public async prompt(context: IFunctionAppWizardContext): Promise<void> {
const placeHolder: string = localize('selectHostingPlan', 'Select a hosting plan.');
const picks: IAzureQuickPickItem<[boolean, boolean, RegExp | undefined]>[] = [
{ label: localize('flexConsumption', 'Flex Consumption'), data: [false, true, undefined] },
{ label: localize('consumption', 'Consumption'), description: localize('legacy', 'Legacy'), data: [true, false, undefined] },
{ label: localize('premium', 'Premium'), data: [false, false, premiumSkuFilter] },
{ label: localize('dedicated', 'App Service Plan'), data: [false, false, /^((?!EP|Y|FC).)*$/i] }
];
const picks: IAzureQuickPickItem<[boolean, boolean, RegExp | undefined]>[] = [];
if (this.availablePlans.has(FunctionAppHostingPlans.Flex)) {
picks.push({ label: localize('flexConsumption', 'Flex Consumption'), data: [false, true, undefined] });
}
if (this.availablePlans.has(FunctionAppHostingPlans.Consumption)) {
picks.push({ label: localize('consumption', 'Consumption'), description: localize('legacy', 'Legacy'), data: [true, false, undefined] });
}
if (this.availablePlans.has(FunctionAppHostingPlans.Premium)) {
picks.push({ label: localize('premium', 'Premium'), data: [false, false, /^EP$/i] });
}
if (this.availablePlans.has(FunctionAppHostingPlans.AppService)) {
picks.push({ label: localize('dedicated', 'App Service Plan'), data: [false, false, /^((?!EP|Y|FC).)*$/i] });
}

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

public configureBeforePrompt(context: IFunctionAppWizardContext): void | Promise<void> {
if (context.durableStorageType === DurableBackend.DTS) {
// premium is required for DTS
if (context.advancedCreation) {
// allows users to select/create a Elastic Premium plan
context.planSkuFamilyFilter = premiumSkuFilter;
} else {
setPremiumPlanProperties(context);
}
} else if (context.useFlexConsumptionPlan) {
if (context.useFlexConsumptionPlan) {
Copy link
Contributor Author

@MicroFish91 MicroFish91 Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there could be a better way to handle this now but I don't want to explore that in this PR. Basically, I think it would be better if we removed this and relied on the injected available plans to only show flex. Then we can auto-select if the pick was just the one pick. Prompt logic would then handle setting the related plan properties.

setFlexConsumptionPlanProperties(context);
}
}
Expand All @@ -66,16 +76,6 @@ function setFlexConsumptionPlanProperties(context: IAppServiceWizardContext): vo
LocationListStep.setLocationSubset(context, getFlexLocations(context), 'Microsoft.WebFlex');
}

function setPremiumPlanProperties(context: IAppServiceWizardContext): void {
context.newPlanName = `PREMIUM-${nonNullProp(context, 'newSiteName')}-${getRandomHexString(4)}`;
context.newPlanSku = {
name: 'P1v2',
tier: 'Premium V2',
size: 'P1v2',
family: 'Pv2'
};
}

async function getFlexLocations(context: IAppServiceWizardContext): Promise<string[]> {
const headers = createHttpHeaders({
'Content-Type': 'application/json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { AppInsightsCreateStep, AppInsightsListStep, AppKind, AppServicePlanCrea
import { CommonRoleDefinitions, createRoleId, LocationListStep, ResourceGroupCreateStep, ResourceGroupListStep, RoleAssignmentExecuteStep, StorageAccountCreateStep, StorageAccountKind, StorageAccountListStep, StorageAccountPerformance, StorageAccountReplication, type INewStorageAccountDefaults, type Role } from "@microsoft/vscode-azext-azureutils";
import { type AzureWizardExecuteStep, type AzureWizardPromptStep, type ISubscriptionContext } from "@microsoft/vscode-azext-utils";
import { FuncVersion, latestGAVersion, tryParseFuncVersion } from "../../FuncVersion";
import { funcVersionSetting } from "../../constants";
import { DurableBackend, funcVersionSetting } from "../../constants";
import { tryGetLocalFuncVersion } from "../../funcCoreTools/tryGetLocalFuncVersion";
import { type ICreateFunctionAppContext } from "../../tree/SubscriptionTreeItem";
import { createActivityContext } from "../../utils/activityUtils";
import { durableUtils } from "../../utils/durableUtils";
import { getRootFunctionsWorkerRuntime, getWorkspaceSetting, getWorkspaceSettingFromAnyFolder } from "../../vsCodeConfig/settings";
import { AuthenticationPromptStep } from "./AuthenticationPromptStep";
import { FunctionAppCreateStep } from "./FunctionAppCreateStep";
import { FunctionAppHostingPlanStep } from "./FunctionAppHostingPlanStep";
import { allAvailableFunctionAppHostingPlans, FunctionAppHostingPlans, FunctionAppHostingPlanStep } from "./FunctionAppHostingPlanStep";
import { type IFunctionAppWizardContext } from "./IFunctionAppWizardContext";
import { ConfigureCommonNamesStep } from "./UniqueNamePromptStep";
import { ContainerizedFunctionAppCreateStep } from "./containerImage/ContainerizedFunctionAppCreateStep";
Expand Down Expand Up @@ -150,7 +150,9 @@ async function createFunctionAppWizard(wizardContext: IFunctionAppWizardContext)
const promptSteps: AzureWizardPromptStep<IAppServiceWizardContext>[] = [];
const executeSteps: AzureWizardExecuteStep<IAppServiceWizardContext>[] = [];

promptSteps.push(new FunctionAppHostingPlanStep());
promptSteps.push(new FunctionAppHostingPlanStep(
getAvailableFunctionAppHostingPlans(wizardContext) /** availablePlans */,
));
CustomLocationListStep.addStep(wizardContext, promptSteps);

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

return { promptSteps, executeSteps };
}

function getAvailableFunctionAppHostingPlans(context: IFunctionAppWizardContext): Set<FunctionAppHostingPlans> {
const availablePlans: Set<FunctionAppHostingPlans> = new Set();

switch (true) {
case context.useFlexConsumptionPlan:
availablePlans.add(FunctionAppHostingPlans.Flex);
break;

case context.durableStorageType === DurableBackend.DTS:
if (context.advancedCreation) {
availablePlans.add(FunctionAppHostingPlans.Premium);
}
availablePlans.add(FunctionAppHostingPlans.Flex);
break;

default:
return allAvailableFunctionAppHostingPlans;
}

return availablePlans;
}