This repository was archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 160
feat: Dynamically generate ARM templates #174
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1ece5ed
getting region value
mydiemho da3e48f
fix: Standardized on 'region' vs 'location'
wbreza 2a84590
fix: Nomalized location to region
wbreza 599e128
fix: Dynamically find scm domain within enabledHostNames
wbreza 2e00683
fix: Removed unused references
wbreza de26bdb
test: Verify region and state have valid Azure defaults
wbreza faccfea
Started to split out arm templates into smaller resource specific tem…
wbreza d7619f0
test: Verify ARM templates are constructed with correct resources
wbreza f94b119
fix: Applied composite arm template builder pattern
wbreza db59819
set resource template defaults
wbreza c49b66c
test: Verify ARM deployments
wbreza 3791227
fix: Moved models out into seperate module
wbreza 651a0bb
Resolved import statements for ARM models
wbreza 5dfb50e
Updated baseService tests to use public methods
wbreza c17d2a8
Added additional configuration properties for function app
wbreza 4c1d61c
Added compiste arm template and addressed PR feedback
wbreza 2e7e235
Added publisher settings to APIM resource template
wbreza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { FunctionAppResource } from "./resources/functionApp"; | ||
| import { AppInsightsResource } from "./resources/appInsights"; | ||
| import { StorageAccountResource } from "./resources/storageAccount"; | ||
| import { AppServicePlanResource } from "./resources/appServicePlan"; | ||
| import { HostingEnvironmentResource } from "./resources/hostingEnvironment"; | ||
| import { VirtualNetworkResource } from "./resources/virtualNetwork"; | ||
| import { CompositeArmTemplate } from "./compositeArmTemplate"; | ||
| import { ArmResourceTemplate } from "../models/armTemplates"; | ||
|
|
||
| class AppServiceEnvironmentTemplate extends CompositeArmTemplate { | ||
| public constructor() { | ||
| super([ | ||
| new FunctionAppResource(), | ||
| new AppInsightsResource(), | ||
| new StorageAccountResource(), | ||
| new AppServicePlanResource(), | ||
| new HostingEnvironmentResource(), | ||
| new VirtualNetworkResource(), | ||
| ]) | ||
| } | ||
|
|
||
| public getTemplate(): ArmResourceTemplate { | ||
| const template = super.getTemplate(); | ||
|
|
||
| template.parameters.appServicePlanSkuName.defaultValue = "I1"; | ||
| template.parameters.appServicePlanSkuTier.defaultValue = "Isolated"; | ||
|
|
||
| // Update the app service plan to point to the hosting environment | ||
| const appServicePlan: any = template.resources.find((resource: any) => resource.type === "Microsoft.Web/serverfarms"); | ||
| if (appServicePlan) { | ||
| appServicePlan.dependsOn = [...(appServicePlan.dependsOn || []), "[resourceId('Microsoft.Web/hostingEnvironments', parameters('hostingEnvironmentName'))]"]; | ||
| appServicePlan.properties.hostingEnvironmentProfile = { | ||
| ...appServicePlan.properties.hostingEnvironmentProfile, | ||
| id: "[resourceId('Microsoft.Web/hostingEnvironments', parameters('hostingEnvironmentName'))]", | ||
| } | ||
| } | ||
|
|
||
| // Update the functionApp resource to include the app service plan references | ||
| const app: any = template.resources.find((resource: any) => resource.type === "Microsoft.Web/sites"); | ||
| if (app) { | ||
| app.dependsOn = [...(app.dependsOn || []), "[concat('Microsoft.Web/serverfarms/', parameters('appServicePlanName'))]"]; | ||
| app.properties.serverFarmId = "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"; | ||
| app.properties.hostingEnvironmentProfile = { | ||
| ...app.properties.hostingEnvironmentProfile, | ||
| id: "[resourceId('Microsoft.Web/hostingEnvironments', parameters('hostingEnvironmentName'))]", | ||
| } | ||
| } | ||
|
|
||
| return template; | ||
| } | ||
| } | ||
|
|
||
| export default new AppServiceEnvironmentTemplate(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { ArmResourceTemplateGenerator, ArmResourceTemplate } from "../models/armTemplates"; | ||
| import { Guard } from "../shared/guard"; | ||
| import { ServerlessAzureConfig } from "../models/serverless"; | ||
|
|
||
| export class CompositeArmTemplate implements ArmResourceTemplateGenerator { | ||
| public constructor(private childTemplates: ArmResourceTemplateGenerator[]) { | ||
| Guard.null(childTemplates); | ||
| } | ||
|
|
||
| public getTemplate(): ArmResourceTemplate { | ||
| const template: ArmResourceTemplate = { | ||
| "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | ||
| "contentVersion": "1.0.0.0", | ||
| "parameters": {}, | ||
| "resources": [], | ||
| }; | ||
|
|
||
| this.childTemplates.forEach((resource) => { | ||
| const resourceTemplate = resource.getTemplate(); | ||
| template.parameters = { | ||
| ...template.parameters, | ||
| ...resourceTemplate.parameters, | ||
| }; | ||
|
|
||
| template.resources = [ | ||
| ...template.resources, | ||
| ...resourceTemplate.resources, | ||
| ]; | ||
| }); | ||
|
|
||
| return template; | ||
| } | ||
|
|
||
| public getParameters(config: ServerlessAzureConfig) { | ||
| let parameters = {}; | ||
|
|
||
| this.childTemplates.forEach((resource) => { | ||
| parameters = { | ||
| ...parameters, | ||
| ...resource.getParameters(config), | ||
| location: config.provider.region, | ||
| } | ||
| }); | ||
|
|
||
| return parameters; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { FunctionAppResource } from "./resources/functionApp"; | ||
| import { AppInsightsResource } from "./resources/appInsights"; | ||
| import { StorageAccountResource } from "./resources/storageAccount"; | ||
| import { CompositeArmTemplate } from "./compositeArmTemplate"; | ||
|
|
||
| class ConsumptionPlanTemplate extends CompositeArmTemplate { | ||
| public constructor() { | ||
| super([ | ||
| new FunctionAppResource(), | ||
| new AppInsightsResource(), | ||
| new StorageAccountResource(), | ||
| ]) | ||
| } | ||
| } | ||
|
|
||
| export default new ConsumptionPlanTemplate(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { FunctionAppResource } from "./resources/functionApp"; | ||
| import { AppInsightsResource } from "./resources/appInsights"; | ||
| import { StorageAccountResource } from "./resources/storageAccount"; | ||
| import { AppServicePlanResource } from "./resources/appServicePlan"; | ||
| import { ArmResourceTemplate } from "../models/armTemplates"; | ||
| import { CompositeArmTemplate } from "./compositeArmTemplate"; | ||
|
|
||
| class PremiumPlanTemplate extends CompositeArmTemplate { | ||
| public constructor() { | ||
| super([ | ||
| new FunctionAppResource(), | ||
| new AppInsightsResource(), | ||
| new StorageAccountResource(), | ||
| new AppServicePlanResource(), | ||
| ]) | ||
| } | ||
|
|
||
| public getTemplate(): ArmResourceTemplate { | ||
| const template = super.getTemplate(); | ||
|
|
||
| template.parameters.appServicePlanSkuName.defaultValue = "EP1"; | ||
| template.parameters.appServicePlanSkuTier.defaultValue = "ElasticPremium"; | ||
|
|
||
| // Update the functionApp resource to include the app service plan references | ||
| const app: any = template.resources.find((resource: any) => resource.type === "Microsoft.Web/sites"); | ||
| if (app) { | ||
| app.properties.serverFarmId = "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"; | ||
| app.dependsOn = [...(app.dependsOn || []), "[concat('Microsoft.Web/serverfarms/', parameters('appServicePlanName'))]"] | ||
| } | ||
|
|
||
| return template; | ||
| } | ||
| } | ||
|
|
||
| export default new PremiumPlanTemplate(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { ServerlessAzureConfig } from "../../models/serverless"; | ||
| import { ArmResourceTemplateGenerator, ArmResourceTemplate } from "../../models/armTemplates"; | ||
| import { ApiManagementConfig } from "../../models/apiManagement"; | ||
|
|
||
| export class ApimResource implements ArmResourceTemplateGenerator { | ||
| public static getResourceName(config: ServerlessAzureConfig) { | ||
| return config.provider.apim && config.provider.apim.name | ||
| ? config.provider.apim.name | ||
| : `${config.provider.prefix}-${config.provider.region}-${config.provider.stage}-apim`; | ||
| } | ||
|
|
||
| public getTemplate(): ArmResourceTemplate { | ||
| return { | ||
| "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | ||
| "contentVersion": "1.0.0.0", | ||
| "parameters": { | ||
| "apiManagementName": { | ||
| "defaultValue": "", | ||
| "type": "String" | ||
| }, | ||
| "location": { | ||
| "defaultValue": "", | ||
| "type": "String" | ||
| }, | ||
| "apimSkuName": { | ||
| "defaultValue": "Consumption", | ||
| "type": "String" | ||
| }, | ||
| "apimCapacity": { | ||
| "defaultValue": 0, | ||
| "type": "int" | ||
| }, | ||
| "apimPublisherEmail": { | ||
| "defaultValue": "contact@contoso.com", | ||
| "type": "String" | ||
| }, | ||
| "apimPublisherName": { | ||
| "defaultValue": "Contoso", | ||
| "type": "String" | ||
| } | ||
| }, | ||
| "variables": {}, | ||
| "resources": [ | ||
| { | ||
| "type": "Microsoft.ApiManagement/service", | ||
| "apiVersion": "2018-06-01-preview", | ||
| "name": "[parameters('apiManagementName')]", | ||
| "location": "[parameters('location')]", | ||
| "sku": { | ||
| "name": "[parameters('apimSkuName')]", | ||
| "capacity": "[parameters('apimCapacity')]" | ||
| }, | ||
| "properties": { | ||
| "publisherEmail": "[parameters('apimPublisherEmail')]", | ||
| "publisherName": "[parameters('apimPublisherName')]", | ||
| "notificationSenderEmail": "apimgmt-noreply@mail.windowsazure.com", | ||
| "hostnameConfigurations": [], | ||
| "virtualNetworkType": "None" | ||
| } | ||
| } | ||
| ] | ||
| }; | ||
| } | ||
|
|
||
| public getParameters(config: ServerlessAzureConfig) { | ||
| 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, | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { ArmResourceTemplateGenerator, ArmResourceTemplate } from "../../models/armTemplates"; | ||
| import { ServerlessAzureConfig, ResourceConfig } from "../../models/serverless"; | ||
|
|
||
| export class AppInsightsResource implements ArmResourceTemplateGenerator { | ||
| public static getResourceName(config: ServerlessAzureConfig) { | ||
| return config.provider.appInsights && config.provider.appInsights.name | ||
| ? config.provider.appInsights.name | ||
| : `${config.provider.prefix}-${config.provider.region}-${config.provider.stage}-appinsights`; | ||
| } | ||
|
|
||
| public getTemplate(): ArmResourceTemplate { | ||
| return { | ||
| "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | ||
| "contentVersion": "1.0.0.0", | ||
| "parameters": { | ||
| "appInsightsName": { | ||
| "defaultValue": "", | ||
| "type": "String" | ||
| }, | ||
| "location": { | ||
| "defaultValue": "", | ||
| "type": "String" | ||
| } | ||
| }, | ||
| "variables": {}, | ||
| "resources": [ | ||
| { | ||
| "apiVersion": "2015-05-01", | ||
| "name": "[parameters('appInsightsName')]", | ||
| "type": "microsoft.insights/components", | ||
| "location": "[parameters('location')]", | ||
| "properties": { | ||
| "Application_Type": "web", | ||
| "ApplicationId": "[parameters('appInsightsName')]", | ||
| "Request_Source": "IbizaWebAppExtensionCreate" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| public getParameters(config: ServerlessAzureConfig): any { | ||
| return { | ||
| appInsightsName: AppInsightsResource.getResourceName(config), | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { ArmResourceTemplateGenerator, ArmResourceTemplate } from "../../models/armTemplates"; | ||
| import { ServerlessAzureConfig, ResourceConfig } from "../../models/serverless"; | ||
|
|
||
| export class AppServicePlanResource implements ArmResourceTemplateGenerator { | ||
| public static getResourceName(config: ServerlessAzureConfig) { | ||
| return config.provider.appServicePlan && config.provider.appServicePlan.name | ||
| ? config.provider.appServicePlan.name | ||
| : `${config.provider.prefix}-${config.provider.region}-${config.provider.stage}-asp`; | ||
| } | ||
|
|
||
| public getTemplate(): ArmResourceTemplate { | ||
| return { | ||
| "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | ||
wbreza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "contentVersion": "1.0.0.0", | ||
| "parameters": { | ||
| "appServicePlanName": { | ||
| "defaultValue": "", | ||
| "type": "String" | ||
| }, | ||
| "location": { | ||
| "defaultValue": "", | ||
| "type": "String" | ||
| }, | ||
| "appServicePlanSkuName": { | ||
| "defaultValue": "EP1", | ||
| "type": "String" | ||
| }, | ||
| "appServicePlanSkuTier": { | ||
| "defaultValue": "ElasticPremium", | ||
| "type": "String" | ||
| } | ||
| }, | ||
| "variables": {}, | ||
| "resources": [ | ||
| { | ||
| "apiVersion": "2016-09-01", | ||
| "name": "[parameters('appServicePlanName')]", | ||
| "type": "Microsoft.Web/serverfarms", | ||
| "location": "[parameters('location')]", | ||
| "properties": { | ||
| "name": "[parameters('appServicePlanName')]", | ||
| "workerSizeId": "3", | ||
| "numberOfWorkers": "1", | ||
| "maximumElasticWorkerCount": "10", | ||
| "hostingEnvironment": "" | ||
| }, | ||
| "sku": { | ||
| "name": "[parameters('appServicePlanSkuName')]", | ||
| "tier": "[parameters('appServicePlanSkuTier')]" | ||
| } | ||
| } | ||
| ] | ||
| }; | ||
| } | ||
|
|
||
| public getParameters(config: ServerlessAzureConfig): any { | ||
| const resourceConfig: ResourceConfig = { | ||
| sku: {}, | ||
| ...config.provider.storageAccount, | ||
| }; | ||
|
|
||
| return { | ||
| appServicePlanName: AppServicePlanResource.getResourceName(config), | ||
| appServicePlanSkuName: resourceConfig.sku.name, | ||
| appServicePlanSkuTier: resourceConfig.sku.tier, | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.