-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcreateManagedEnvironment.ts
More file actions
59 lines (51 loc) · 3.17 KB
/
createManagedEnvironment.ts
File metadata and controls
59 lines (51 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { type ManagedEnvironment } from "@azure/arm-appcontainers";
import { LocationListStep, ResourceGroupCreateStep } from "@microsoft/vscode-azext-azureutils";
import { AzureWizard, createSubscriptionContext, nonNullProp, subscriptionExperience, type AzureWizardExecuteStep, type AzureWizardPromptStep, type IActionContext } from "@microsoft/vscode-azext-utils";
import { type AzureSubscription } from "@microsoft/vscode-azureresources-api";
import { appProvider, managedEnvironmentsId } from "../../constants";
import { ext } from "../../extensionVariables";
import { createActivityContext } from "../../utils/activityUtils";
import { getVerifyProvidersStep } from "../../utils/getVerifyProvidersStep";
import { localize } from "../../utils/localize";
import { LogAnalyticsCreateStep } from "./LogAnalyticsCreateStep";
import { type ManagedEnvironmentCreateContext } from "./ManagedEnvironmentCreateContext";
import { ManagedEnvironmentCreateStep } from "./ManagedEnvironmentCreateStep";
import { ManagedEnvironmentNameStep } from "./ManagedEnvironmentNameStep";
export async function createManagedEnvironment(context: IActionContext, node?: { subscription: AzureSubscription }): Promise<ManagedEnvironment> {
const subscription = node?.subscription ?? await subscriptionExperience(context, ext.rgApiV2.resources.azureResourceTreeDataProvider);
const wizardContext: ManagedEnvironmentCreateContext = {
...context,
...createSubscriptionContext(subscription),
...await createActivityContext(),
subscription
};
const title: string = localize('createManagedEnv', 'Create container apps environment');
const promptSteps: AzureWizardPromptStep<ManagedEnvironmentCreateContext>[] = [];
const executeSteps: AzureWizardExecuteStep<ManagedEnvironmentCreateContext>[] = [];
promptSteps.push(new ManagedEnvironmentNameStep());
executeSteps.push(
getVerifyProvidersStep<ManagedEnvironmentCreateContext>(),
new ResourceGroupCreateStep(),
new LogAnalyticsCreateStep(),
new ManagedEnvironmentCreateStep()
);
LocationListStep.addProviderForFiltering(wizardContext, appProvider, managedEnvironmentsId);
LocationListStep.addStep(wizardContext, promptSteps);
const wizard: AzureWizard<ManagedEnvironmentCreateContext> = new AzureWizard(wizardContext, {
title,
promptSteps,
executeSteps,
showLoadingPrompt: true
});
await wizard.prompt();
const newManagedEnvName = nonNullProp(wizardContext, 'newManagedEnvironmentName');
wizardContext.newResourceGroupName = newManagedEnvName;
wizardContext.activityTitle = localize('createNamedManagedEnv', 'Create container apps environment "{0}"', newManagedEnvName);
await wizard.execute();
ext.branchDataProvider.refresh();
return nonNullProp(wizardContext, 'managedEnvironment');
}