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

Commit 1068a4b

Browse files
authored
fix: Exclude ARM params with null values (#325)
- [x] Eliminate explicit `type` from valued paramaters - [x] Remove any parameters whose value is `null` before deployment - [x] Make `type` optional on `ArmParameters`
1 parent 8ae5a48 commit 1068a4b

File tree

11 files changed

+42
-20
lines changed

11 files changed

+42
-20
lines changed

src/armTemplates/compositeArmTemplate.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export class CompositeArmTemplate implements ArmResourceTemplateGenerator {
4141
...parameters,
4242
...resource.getParameters(config),
4343
location: {
44-
type: ArmParamType.String,
4544
value: AzureNamingService.getNormalizedRegionName(config.provider.region)
4645
}
4746
};

src/armTemplates/resources/apim.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,18 @@ export class ApimResource implements ArmResourceTemplateGenerator {
7474

7575
return {
7676
apiManagementName: {
77-
type: ArmParamType.String,
7877
value: ApimResource.getResourceName(config),
7978
},
8079
apimSkuName: {
81-
type: ArmParamType.String,
8280
value: apimConfig.sku.name,
8381
},
8482
apimSkuCapacity: {
85-
type: ArmParamType.Int,
8683
value: apimConfig.sku.capacity,
8784
},
8885
apimPublisherEmail: {
89-
type: ArmParamType.String,
9086
value: apimConfig.publisherEmail,
9187
},
9288
apimPublisherName: {
93-
type: ArmParamType.String,
9489
value: apimConfig.publisherName,
9590
}
9691
};

src/armTemplates/resources/appInsights.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export class AppInsightsResource implements ArmResourceTemplateGenerator {
4646
public getParameters(config: ServerlessAzureConfig): ArmParameters {
4747
return {
4848
appInsightsName: {
49-
type: ArmParamType.String,
5049
value: AppInsightsResource.getResourceName(config),
5150
}
5251
};

src/armTemplates/resources/appServicePlan.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,12 @@ export class AppServicePlanResource implements ArmResourceTemplateGenerator {
6565

6666
return {
6767
appServicePlanName: {
68-
type: ArmParamType.String,
6968
value: AppServicePlanResource.getResourceName(config),
7069
},
7170
appServicePlanSkuName: {
72-
type: ArmParamType.String,
7371
value: resourceConfig.sku.name,
7472
},
7573
appServicePlanSkuTier: {
76-
type: ArmParamType.String,
7774
value: resourceConfig.sku.tier,
7875
}
7976
}

src/armTemplates/resources/functionApp.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,15 @@ export class FunctionAppResource implements ArmResourceTemplateGenerator {
126126

127127
return {
128128
functionAppName: {
129-
type: ArmParamType.String,
130129
value: FunctionAppResource.getResourceName(config),
131130
},
132131
functionAppNodeVersion: {
133-
type: ArmParamType.String,
134132
value: resourceConfig.nodeVersion,
135133
},
136134
functionAppWorkerRuntime: {
137-
type: ArmParamType.String,
138135
value: resourceConfig.workerRuntime,
139136
},
140137
functionAppExtensionVersion: {
141-
type: ArmParamType.String,
142138
value: resourceConfig.extensionVersion,
143139
}
144140
};

src/armTemplates/resources/hostingEnvironment.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export class HostingEnvironmentResource implements ArmResourceTemplateGenerator
6868
public getParameters(config: ServerlessAzureConfig): ArmParameters {
6969
return {
7070
hostingEnvironmentName: {
71-
type: ArmParamType.String,
7271
value: HostingEnvironmentResource.getResourceName(config)
7372
}
7473
}

src/armTemplates/resources/storageAccount.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,12 @@ export class StorageAccountResource implements ArmResourceTemplateGenerator {
6666

6767
return {
6868
storageAccountName: {
69-
type: ArmParamType.String,
7069
value: StorageAccountResource.getResourceName(config),
7170
},
7271
storageAccountSkuName: {
73-
type: ArmParamType.String,
7472
value: resourceConfig.sku.name,
7573
},
7674
storageAccoutSkuTier: {
77-
type: ArmParamType.String,
7875
value: resourceConfig.sku.tier,
7976
}
8077
};

src/armTemplates/resources/virtualNetwork.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export class VirtualNetworkResource implements ArmResourceTemplateGenerator {
8686
public getParameters(config: ServerlessAzureConfig): ArmParameters {
8787
return {
8888
virtualNetworkName: {
89-
type: ArmParamType.String,
9089
value: VirtualNetworkResource.getResourceName(config),
9190
}
9291
}

src/models/armTemplates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export interface ArmResourceTemplate {
4646

4747
export interface ArmParameters {
4848
[key: string]: {
49-
type: ArmParamType;
49+
type?: ArmParamType;
5050
value?: string | number;
5151
defaultValue?: string | number;
5252
};

src/services/armService.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,5 +366,40 @@ describe("Arm Service", () => {
366366
new RegExp(`.*${errorPattern}.*`,"s")
367367
);
368368
});
369+
370+
it("Does not try to include paramaters with a value that is undefined", async () => {
371+
sls.service.provider.runtime = "nodejs10.x";
372+
const deployment = await service.createDeploymentFromType(ArmTemplateType.Consumption);
373+
374+
expect(deployment.parameters.functionAppExtensionVersion).not.toBeUndefined();
375+
expect(deployment.parameters.functionAppExtensionVersion.value).toBeUndefined();
376+
377+
await service.deployTemplate(deployment);
378+
379+
expect(deployment.parameters.functionAppExtensionVersion).toBeUndefined();
380+
381+
const paramKeys = Object.keys(deployment.parameters);
382+
paramKeys.forEach((key) => {
383+
const paramValue = deployment.parameters[key];
384+
if (paramValue) {
385+
expect(paramValue.value).not.toBeUndefined();
386+
}
387+
})
388+
389+
const expectedResourceGroup = sls.service.provider["resourceGroup"];
390+
const expectedDeploymentName = sls.service.provider["deploymentName"] || `${this.resourceGroup}-deployment`;
391+
const expectedDeploymentNameRegex = new RegExp(expectedDeploymentName + "-t([0-9]+)")
392+
const expectedDeployment: Deployment = {
393+
properties: {
394+
mode: "Incremental",
395+
...deployment
396+
},
397+
};
398+
399+
const call = (Deployments.prototype.createOrUpdate as any).mock.calls[0];
400+
expect(call[0]).toEqual(expectedResourceGroup);
401+
expect(call[1]).toMatch(expectedDeploymentNameRegex);
402+
expect(call[2]).toEqual(expectedDeployment);
403+
});
369404
});
370405
});

src/services/armService.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ export class ArmService extends BaseService {
102102
return;
103103
}
104104

105+
for (const key of Object.keys(deployment.parameters)) {
106+
if (!deployment.parameters[key].value) {
107+
delete deployment.parameters[key];
108+
}
109+
}
110+
105111
// Construct deployment object
106112
const armDeployment: Deployment = {
107113
properties: {

0 commit comments

Comments
 (0)