Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
fix: Move reserved prop to App Service Plan (#443)
Browse files Browse the repository at this point in the history
* fix: Move reserved prop to App Service Plan

* Re-remove function app reserved in function app resource
  • Loading branch information
tbarlow12 authored Apr 24, 2020
1 parent efafe9a commit 68ac06c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 21 deletions.
36 changes: 34 additions & 2 deletions src/armTemplates/resources/appServicePlan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,45 @@ describe("App Service Plan Resource", () => {
const appServicePlanResource = new AppServicePlanResource();
const params = appServicePlanResource.getParameters(config);

expect(Object.keys(params)).toHaveLength(8);
expect(Object.keys(params)).toHaveLength(9);
expect(params.appServicePlanName.value).toEqual(AppServicePlanResource.getResourceName(config));
expect(params.appServicePlanSkuName.value).toBeUndefined();
expect(params.appServicePlanSkuTier.value).toBeUndefined();
expect(params.appServicePlanWorkerSizeId.value).toBeUndefined();
expect(params.appServicePlanMinWorkerCount.value).toBeUndefined();
expect(params.appServicePlanMaxWorkerCount.value).toBeUndefined();
expect(params.appServicePlanHostingEnvironment.value).toBeUndefined();
expect(params.appServicePlanReserved.value).toBeUndefined();
});

it("generates correct default parameters with linux function app", () => {
const config: ServerlessAzureConfig = {
provider: {
name: "azure",
prefix,
region,
stage,
resourceGroup: resourceGroupName,
runtime: Runtime.NODE10,
os: FunctionAppOS.LINUX,
},
plugins: [],
functions: {},
service: "myapp",
};

const appServicePlanResource = new AppServicePlanResource();
const params = appServicePlanResource.getParameters(config);

expect(Object.keys(params)).toHaveLength(9);
expect(params.appServicePlanName.value).toEqual(AppServicePlanResource.getResourceName(config));
expect(params.appServicePlanSkuName.value).toBeUndefined();
expect(params.appServicePlanSkuTier.value).toBeUndefined();
expect(params.appServicePlanWorkerSizeId.value).toBeUndefined();
expect(params.appServicePlanMinWorkerCount.value).toBeUndefined();
expect(params.appServicePlanMaxWorkerCount.value).toBeUndefined();
expect(params.appServicePlanHostingEnvironment.value).toBeUndefined();
expect(params.appServicePlanReserved.value).toBe(true);
});

it("generates correct specified parameters", () => {
Expand Down Expand Up @@ -112,14 +143,15 @@ describe("App Service Plan Resource", () => {
const appServicePlanResource = new AppServicePlanResource();
const params = appServicePlanResource.getParameters(config);

expect(Object.keys(params)).toHaveLength(8);
expect(Object.keys(params)).toHaveLength(9);
expect(params.appServicePlanName.value).toEqual(config.provider.appServicePlan.name);
expect(params.appServicePlanSkuName.value).toEqual(config.provider.appServicePlan.sku.name);
expect(params.appServicePlanSkuTier.value).toEqual(config.provider.appServicePlan.sku.tier);
expect(params.appServicePlanWorkerSizeId.value).toEqual(config.provider.appServicePlan.scale.workerSizeId);
expect(params.appServicePlanMinWorkerCount.value).toEqual(config.provider.appServicePlan.scale.minWorkerCount);
expect(params.appServicePlanMaxWorkerCount.value).toEqual(config.provider.appServicePlan.scale.maxWorkerCount);
expect(params.appServicePlanHostingEnvironment.value).toEqual(config.provider.appServicePlan.hostingEnvironment);
expect(params.appServicePlanReserved.value).toBeUndefined();
});

it("generates the expected template", () => {
Expand Down
17 changes: 14 additions & 3 deletions src/armTemplates/resources/appServicePlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ interface AppServicePlanParams extends DefaultArmParams {
appServicePlanMinWorkerCount: ArmParameter;
appServicePlanMaxWorkerCount: ArmParameter;
appServicePlanHostingEnvironment: ArmParameter;
/** Needs to be true for Linux App Service Plans */
appServicePlanReserved: ArmParameter;
}

export class AppServicePlanResource implements ArmResourceTemplateGenerator {
Expand Down Expand Up @@ -61,7 +63,11 @@ export class AppServicePlanResource implements ArmResourceTemplateGenerator {
appServicePlanHostingEnvironment: {
defaultValue: "",
type: ArmParamType.String
}
},
appServicePlanReserved: {
defaultValue: false,
type: ArmParamType.Bool,
},
};

return {
Expand All @@ -81,7 +87,8 @@ export class AppServicePlanResource implements ArmResourceTemplateGenerator {
"workerSizeId": "[parameters('appServicePlanWorkerSizeId')]",
"numberOfWorkers": "[parameters('appServicePlanMinWorkerCount')]",
"maximumElasticWorkerCount": "[parameters('appServicePlanMaxWorkerCount')]",
"hostingEnvironment": "[parameters('appServicePlanHostingEnvironment')]"
"hostingEnvironment": "[parameters('appServicePlanHostingEnvironment')]",
"reserved": "[parameters('appServicePlanReserved')]",
},
"sku": {
"name": "[parameters('appServicePlanSkuName')]",
Expand All @@ -100,6 +107,7 @@ export class AppServicePlanResource implements ArmResourceTemplateGenerator {
};

const { os } = config.provider;
const linux = os === FunctionAppOS.LINUX;

const params: AppServicePlanParams = {
appServicePlanName: {
Expand All @@ -111,7 +119,7 @@ export class AppServicePlanResource implements ArmResourceTemplateGenerator {
* before deployment
*/
kind: {
value: (os === FunctionAppOS.LINUX) ? "Linux" : undefined,
value: (linux) ? "Linux" : undefined,
},
appServicePlanSkuName: {
value: resourceConfig.sku.name,
Expand All @@ -130,6 +138,9 @@ export class AppServicePlanResource implements ArmResourceTemplateGenerator {
},
appServicePlanHostingEnvironment: {
value: resourceConfig.hostingEnvironment
},
appServicePlanReserved: {
value: (linux) ? true : undefined
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/armTemplates/resources/functionApp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,10 @@ describe("Function App Resource", () => {
function assertLinuxParams(parameters: ArmParameters) {
const {
functionAppKind,
functionAppReserved,
functionAppEnableRemoteBuild,
} = parameters;

expect(functionAppKind.value).toEqual("functionapp,linux");
expect(functionAppReserved.value).toBe(true)
expect(functionAppEnableRemoteBuild.value).toBe(true);
}
});
Expand Down Expand Up @@ -285,12 +283,10 @@ describe("Function App Resource", () => {
const {
linuxFxVersion,
functionAppKind,
functionAppReserved,
} = parameters;

expect(functionAppKind.value).toBeUndefined();
expect(linuxFxVersion.value).toBeUndefined();
expect(functionAppReserved.value).toBeUndefined();
}
});
});
Expand Down
12 changes: 0 additions & 12 deletions src/armTemplates/resources/functionApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ interface FunctionAppParams extends DefaultArmParams {
* `functionapp,linux` for Linux function app
*/
functionAppKind: ArmParameter;
/**
* Needs to be `true` for Linux function apps
*/
functionAppReserved: ArmParameter;
/**
* Docker image for Linux function app
*/
Expand Down Expand Up @@ -98,7 +94,6 @@ export class FunctionAppResource implements ArmResourceTemplateGenerator {
appSettings: this.getFunctionAppSettings(config),
"linuxFxVersion": "[parameters('linuxFxVersion')]",
},
"reserved": "[parameters('functionAppReserved')]",
name: "[parameters('functionAppName')]",
"clientAffinityEnabled": false,
"hostingEnvironment": ""
Expand Down Expand Up @@ -132,9 +127,6 @@ export class FunctionAppResource implements ArmResourceTemplateGenerator {
functionAppKind: {
value: (isLinuxRuntime) ? "functionapp,linux" : undefined,
},
functionAppReserved: {
value: (isLinuxRuntime) ? true : undefined,
},
linuxFxVersion: {
value: (isLinuxRuntime) ? this.getLinuxFxVersion(config) : undefined,
},
Expand Down Expand Up @@ -170,10 +162,6 @@ export class FunctionAppResource implements ArmResourceTemplateGenerator {
defaultValue: "functionapp",
type: ArmParamType.String,
},
functionAppReserved: {
defaultValue: false,
type: ArmParamType.Bool
},
linuxFxVersion: {
defaultValue: "",
type: ArmParamType.String,
Expand Down

0 comments on commit 68ac06c

Please sign in to comment.