Skip to content

Commit

Permalink
fix: Exclude ARM params with null values (#325)
Browse files Browse the repository at this point in the history
- [x] Eliminate explicit `type` from valued paramaters
- [x] Remove any parameters whose value is `null` before deployment
- [x] Make `type` optional on `ArmParameters`
  • Loading branch information
tbarlow12 authored Sep 9, 2019
1 parent 8ae5a48 commit 1068a4b
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 20 deletions.
1 change: 0 additions & 1 deletion src/armTemplates/compositeArmTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class CompositeArmTemplate implements ArmResourceTemplateGenerator {
...parameters,
...resource.getParameters(config),
location: {
type: ArmParamType.String,
value: AzureNamingService.getNormalizedRegionName(config.provider.region)
}
};
Expand Down
5 changes: 0 additions & 5 deletions src/armTemplates/resources/apim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,18 @@ export class ApimResource implements ArmResourceTemplateGenerator {

return {
apiManagementName: {
type: ArmParamType.String,
value: ApimResource.getResourceName(config),
},
apimSkuName: {
type: ArmParamType.String,
value: apimConfig.sku.name,
},
apimSkuCapacity: {
type: ArmParamType.Int,
value: apimConfig.sku.capacity,
},
apimPublisherEmail: {
type: ArmParamType.String,
value: apimConfig.publisherEmail,
},
apimPublisherName: {
type: ArmParamType.String,
value: apimConfig.publisherName,
}
};
Expand Down
1 change: 0 additions & 1 deletion src/armTemplates/resources/appInsights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export class AppInsightsResource implements ArmResourceTemplateGenerator {
public getParameters(config: ServerlessAzureConfig): ArmParameters {
return {
appInsightsName: {
type: ArmParamType.String,
value: AppInsightsResource.getResourceName(config),
}
};
Expand Down
3 changes: 0 additions & 3 deletions src/armTemplates/resources/appServicePlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,12 @@ export class AppServicePlanResource implements ArmResourceTemplateGenerator {

return {
appServicePlanName: {
type: ArmParamType.String,
value: AppServicePlanResource.getResourceName(config),
},
appServicePlanSkuName: {
type: ArmParamType.String,
value: resourceConfig.sku.name,
},
appServicePlanSkuTier: {
type: ArmParamType.String,
value: resourceConfig.sku.tier,
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/armTemplates/resources/functionApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,15 @@ export class FunctionAppResource implements ArmResourceTemplateGenerator {

return {
functionAppName: {
type: ArmParamType.String,
value: FunctionAppResource.getResourceName(config),
},
functionAppNodeVersion: {
type: ArmParamType.String,
value: resourceConfig.nodeVersion,
},
functionAppWorkerRuntime: {
type: ArmParamType.String,
value: resourceConfig.workerRuntime,
},
functionAppExtensionVersion: {
type: ArmParamType.String,
value: resourceConfig.extensionVersion,
}
};
Expand Down
1 change: 0 additions & 1 deletion src/armTemplates/resources/hostingEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export class HostingEnvironmentResource implements ArmResourceTemplateGenerator
public getParameters(config: ServerlessAzureConfig): ArmParameters {
return {
hostingEnvironmentName: {
type: ArmParamType.String,
value: HostingEnvironmentResource.getResourceName(config)
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/armTemplates/resources/storageAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,12 @@ export class StorageAccountResource implements ArmResourceTemplateGenerator {

return {
storageAccountName: {
type: ArmParamType.String,
value: StorageAccountResource.getResourceName(config),
},
storageAccountSkuName: {
type: ArmParamType.String,
value: resourceConfig.sku.name,
},
storageAccoutSkuTier: {
type: ArmParamType.String,
value: resourceConfig.sku.tier,
}
};
Expand Down
1 change: 0 additions & 1 deletion src/armTemplates/resources/virtualNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export class VirtualNetworkResource implements ArmResourceTemplateGenerator {
public getParameters(config: ServerlessAzureConfig): ArmParameters {
return {
virtualNetworkName: {
type: ArmParamType.String,
value: VirtualNetworkResource.getResourceName(config),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/armTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface ArmResourceTemplate {

export interface ArmParameters {
[key: string]: {
type: ArmParamType;
type?: ArmParamType;
value?: string | number;
defaultValue?: string | number;
};
Expand Down
35 changes: 35 additions & 0 deletions src/services/armService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,5 +366,40 @@ describe("Arm Service", () => {
new RegExp(`.*${errorPattern}.*`,"s")
);
});

it("Does not try to include paramaters with a value that is undefined", async () => {
sls.service.provider.runtime = "nodejs10.x";
const deployment = await service.createDeploymentFromType(ArmTemplateType.Consumption);

expect(deployment.parameters.functionAppExtensionVersion).not.toBeUndefined();
expect(deployment.parameters.functionAppExtensionVersion.value).toBeUndefined();

await service.deployTemplate(deployment);

expect(deployment.parameters.functionAppExtensionVersion).toBeUndefined();

const paramKeys = Object.keys(deployment.parameters);
paramKeys.forEach((key) => {
const paramValue = deployment.parameters[key];
if (paramValue) {
expect(paramValue.value).not.toBeUndefined();
}
})

const expectedResourceGroup = sls.service.provider["resourceGroup"];
const expectedDeploymentName = sls.service.provider["deploymentName"] || `${this.resourceGroup}-deployment`;
const expectedDeploymentNameRegex = new RegExp(expectedDeploymentName + "-t([0-9]+)")
const expectedDeployment: Deployment = {
properties: {
mode: "Incremental",
...deployment
},
};

const call = (Deployments.prototype.createOrUpdate as any).mock.calls[0];
expect(call[0]).toEqual(expectedResourceGroup);
expect(call[1]).toMatch(expectedDeploymentNameRegex);
expect(call[2]).toEqual(expectedDeployment);
});
});
});
6 changes: 6 additions & 0 deletions src/services/armService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ export class ArmService extends BaseService {
return;
}

for (const key of Object.keys(deployment.parameters)) {
if (!deployment.parameters[key].value) {
delete deployment.parameters[key];
}
}

// Construct deployment object
const armDeployment: Deployment = {
properties: {
Expand Down

0 comments on commit 1068a4b

Please sign in to comment.