Skip to content

Commit

Permalink
fix: Fix regression of skipping identical ARM deployment (#314)
Browse files Browse the repository at this point in the history
- [x] Added enum `ArmParamType` for commonly used parameter types within ARM templates
- [x] Ignoring `identity` property on resources for comparison, since that does not appear in ARM template from previous deployments
- [x] Added `deepEqual` to utility class with optional normalizer
- [x] Moved `AzureKeyVaultConfig` to `serverless.ts` near other config models
- [x] Added `ArmParameter` interface

Resolves issue of not being able to skip previous deployments due to `identity` as well as mismatch in casing of `type` within ARM parameters
  • Loading branch information
tbarlow12 committed Sep 13, 2019
1 parent 2d933dd commit 02d1024
Show file tree
Hide file tree
Showing 17 changed files with 287 additions and 192 deletions.
11 changes: 7 additions & 4 deletions src/armTemplates/compositeArmTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArmResourceTemplate, ArmResourceTemplateGenerator } from "../models/armTemplates";
import { ArmResourceTemplate, ArmResourceTemplateGenerator, ArmParameters, ArmParamType } from "../models/armTemplates";
import { ServerlessAzureConfig } from "../models/serverless";
import { AzureNamingService } from "../services/namingService";
import { Guard } from "../shared/guard";
Expand Down Expand Up @@ -33,14 +33,17 @@ export class CompositeArmTemplate implements ArmResourceTemplateGenerator {
return template;
}

public getParameters(config: ServerlessAzureConfig) {
let parameters = {};
public getParameters(config: ServerlessAzureConfig): ArmParameters {
let parameters: ArmParameters = {};

this.childTemplates.forEach(resource => {
parameters = {
...parameters,
...resource.getParameters(config),
location: AzureNamingService.getNormalizedRegionName(config.provider.region)
location: {
type: ArmParamType.String,
value: AzureNamingService.getNormalizedRegionName(config.provider.region)
}
};
});

Expand Down
41 changes: 28 additions & 13 deletions src/armTemplates/resources/apim.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiManagementConfig } from "../../models/apiManagement";
import { ArmResourceTemplate, ArmResourceTemplateGenerator } from "../../models/armTemplates";
import { ArmResourceTemplate, ArmResourceTemplateGenerator, ArmParamType, ArmParameters } from "../../models/armTemplates";
import { ServerlessAzureConfig } from "../../models/serverless";
import { AzureNamingService, AzureNamingServiceOptions } from "../../services/namingService";

Expand All @@ -20,27 +20,27 @@ export class ApimResource implements ArmResourceTemplateGenerator {
"parameters": {
"apiManagementName": {
"defaultValue": "",
"type": "String"
"type": ArmParamType.String
},
"location": {
"defaultValue": "",
"type": "String"
"type": ArmParamType.String
},
"apimSkuName": {
"defaultValue": "Consumption",
"type": "String"
"type": ArmParamType.String
},
"apimCapacity": {
"defaultValue": 0,
"type": "int"
"type": ArmParamType.Int
},
"apimPublisherEmail": {
"defaultValue": "contact@contoso.com",
"type": "String"
"type": ArmParamType.String
},
"apimPublisherName": {
"defaultValue": "Contoso",
"type": "String"
"type": ArmParamType.String
}
},
"variables": {},
Expand All @@ -66,18 +66,33 @@ export class ApimResource implements ArmResourceTemplateGenerator {
};
}

public getParameters(config: ServerlessAzureConfig) {
public getParameters(config: ServerlessAzureConfig): ArmParameters {
const apimConfig: ApiManagementConfig = {
sku: {},
...config.provider.apim,
};

return {
apiManagementName: ApimResource.getResourceName(config),
apimSkuName: apimConfig.sku.name,
apimSkuCapacity: apimConfig.sku.capacity,
apimPublisherEmail: apimConfig.publisherEmail,
apimPublisherName: apimConfig.publisherName,
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,
}
};
}
}
13 changes: 8 additions & 5 deletions src/armTemplates/resources/appInsights.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArmResourceTemplate, ArmResourceTemplateGenerator } from "../../models/armTemplates";
import { ArmResourceTemplate, ArmResourceTemplateGenerator, ArmParamType, ArmParameters } from "../../models/armTemplates";
import { ServerlessAzureConfig } from "../../models/serverless";
import { AzureNamingService, AzureNamingServiceOptions } from "../../services/namingService";

Expand All @@ -19,11 +19,11 @@ export class AppInsightsResource implements ArmResourceTemplateGenerator {
"parameters": {
"appInsightsName": {
"defaultValue": "",
"type": "String"
"type": ArmParamType.String
},
"location": {
"defaultValue": "",
"type": "String"
"type": ArmParamType.String
}
},
"variables": {},
Expand All @@ -43,9 +43,12 @@ export class AppInsightsResource implements ArmResourceTemplateGenerator {
}
}

public getParameters(config: ServerlessAzureConfig): any {
public getParameters(config: ServerlessAzureConfig): ArmParameters {
return {
appInsightsName: AppInsightsResource.getResourceName(config),
appInsightsName: {
type: ArmParamType.String,
value: AppInsightsResource.getResourceName(config),
}
};
}
}
27 changes: 18 additions & 9 deletions src/armTemplates/resources/appServicePlan.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArmResourceTemplate, ArmResourceTemplateGenerator } from "../../models/armTemplates";
import { ArmResourceTemplate, ArmResourceTemplateGenerator, ArmParamType, ArmParameters } from "../../models/armTemplates";
import { ResourceConfig, ServerlessAzureConfig } from "../../models/serverless";
import { AzureNamingService, AzureNamingServiceOptions } from "../../services/namingService";

Expand All @@ -19,19 +19,19 @@ export class AppServicePlanResource implements ArmResourceTemplateGenerator {
"parameters": {
"appServicePlanName": {
"defaultValue": "",
"type": "String"
"type": ArmParamType.String
},
"location": {
"defaultValue": "",
"type": "String"
"type": ArmParamType.String
},
"appServicePlanSkuName": {
"defaultValue": "EP1",
"type": "String"
"type": ArmParamType.String
},
"appServicePlanSkuTier": {
"defaultValue": "ElasticPremium",
"type": "String"
"type": ArmParamType.String
}
},
"variables": {},
Expand All @@ -57,16 +57,25 @@ export class AppServicePlanResource implements ArmResourceTemplateGenerator {
};
}

public getParameters(config: ServerlessAzureConfig): any {
public getParameters(config: ServerlessAzureConfig): ArmParameters {
const resourceConfig: ResourceConfig = {
sku: {},
...config.provider.storageAccount,
};

return {
appServicePlanName: AppServicePlanResource.getResourceName(config),
appServicePlanSkuName: resourceConfig.sku.name,
appServicePlanSkuTier: resourceConfig.sku.tier,
appServicePlanName: {
type: ArmParamType.String,
value: AppServicePlanResource.getResourceName(config),
},
appServicePlanSkuName: {
type: ArmParamType.String,
value: resourceConfig.sku.name,
},
appServicePlanSkuTier: {
type: ArmParamType.String,
value: resourceConfig.sku.tier,
}
}
}
}
44 changes: 28 additions & 16 deletions src/armTemplates/resources/functionApp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArmResourceTemplate, ArmResourceTemplateGenerator } from "../../models/armTemplates";
import { ArmResourceTemplate, ArmResourceTemplateGenerator, ArmParamType, ArmParameters } from "../../models/armTemplates";
import { FunctionAppConfig, ServerlessAzureConfig } from "../../models/serverless";
import { AzureNamingService, AzureNamingServiceOptions } from "../../services/namingService";

Expand Down Expand Up @@ -26,36 +26,36 @@ export class FunctionAppResource implements ArmResourceTemplateGenerator {
"parameters": {
"functionAppRunFromPackage": {
"defaultValue": "1",
"type": "String"
"type": ArmParamType.String
},
"functionAppName": {
"defaultValue": "",
"type": "String"
"type": ArmParamType.String
},
"functionAppNodeVersion": {
"defaultValue": "",
"type": "String"
"type": ArmParamType.String
},
"functionAppWorkerRuntime": {
"defaultValue": "node",
"type": "String"
"type": ArmParamType.String
},
"functionAppExtensionVersion": {
"defaultValue": "~2",
"type": "String"
"type": ArmParamType.String
},
"storageAccountName": {
"defaultValue": "",
"type": "String"
"type": ArmParamType.String
},
"appInsightsName": {
"defaultValue": "",
"type": "String"
"type": ArmParamType.String
},
"location": {
"defaultValue": "",
"type": "String"
}
"type": ArmParamType.String
},
},
"variables": {},
"resources": [
Expand All @@ -65,7 +65,7 @@ export class FunctionAppResource implements ArmResourceTemplateGenerator {
"name": "[parameters('functionAppName')]",
"location": "[parameters('location')]",
"identity": {
"type": "SystemAssigned"
"type": ArmParamType.SystemAssigned
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]",
Expand Down Expand Up @@ -118,17 +118,29 @@ export class FunctionAppResource implements ArmResourceTemplateGenerator {
};
}

public getParameters(config: ServerlessAzureConfig): any {
public getParameters(config: ServerlessAzureConfig): ArmParameters {
const resourceConfig: FunctionAppConfig = {
...config.provider.functionApp,
nodeVersion: this.getRuntimeVersion(config.provider.runtime)
};

return {
functionAppName: FunctionAppResource.getResourceName(config),
functionAppNodeVersion: resourceConfig.nodeVersion,
functionAppWorkerRuntime: resourceConfig.workerRuntime,
functionAppExtensionVersion: resourceConfig.extensionVersion,
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
15 changes: 9 additions & 6 deletions src/armTemplates/resources/hostingEnvironment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArmResourceTemplate, ArmResourceTemplateGenerator } from "../../models/armTemplates";
import { ArmResourceTemplate, ArmResourceTemplateGenerator, ArmParamType, ArmParameters } from "../../models/armTemplates";
import { ServerlessAzureConfig } from "../../models/serverless";
import { AzureNamingService, AzureNamingServiceOptions } from "../../services/namingService";

Expand All @@ -19,15 +19,15 @@ export class HostingEnvironmentResource implements ArmResourceTemplateGenerator
"parameters": {
"hostingEnvironmentName": {
"defaultValue": "",
"type": "String"
"type": ArmParamType.String
},
"virtualNetworkName": {
"defaultValue": "",
"type": "String"
"type": ArmParamType.String
},
"location": {
"defaultValue": "",
"type": "String"
"type": ArmParamType.String
}
},
"variables": {},
Expand Down Expand Up @@ -65,9 +65,12 @@ export class HostingEnvironmentResource implements ArmResourceTemplateGenerator
};
}

public getParameters(config: ServerlessAzureConfig): any {
public getParameters(config: ServerlessAzureConfig): ArmParameters {
return {
hostingEnvironmentName: HostingEnvironmentResource.getResourceName(config)
hostingEnvironmentName: {
type: ArmParamType.String,
value: HostingEnvironmentResource.getResourceName(config)
}
}
}
}
Expand Down
Loading

0 comments on commit 02d1024

Please sign in to comment.