diff --git a/azure/templates/pact-broker.bicep b/azure/templates/pact-broker.bicep new file mode 100644 index 00000000..471976ce --- /dev/null +++ b/azure/templates/pact-broker.bicep @@ -0,0 +1,195 @@ +targetScope = 'subscription' + +@description('Function to help automatically concatenate a deployment name with a character limit of 65.') +func deploymentName(baseName string) string => take('${baseName}-${uniqueString(string(deployment()))}', 64) + +@description('Name of environment') +param environment string + +@description('Resource/Resource Group location') +param location string + +@description('The tags attached to the resource') +param envTags object = {} + +@description('Administrator login for PostgreSQL') +param administratorLogin string + +@secure() +@description('Administrator password for PostgreSQL') +param postgresPassword string + +@description('PostgreSQL server edition') +param serverEdition string + +@description('PostgreSQL instance type') +param dbInstanceType string + +@description('PostgreSQL version') +param version string + +@description('PostgreSQL SKU size in GB') +param skuSizeGB int + +@description('Docker image for Pact Broker') +param pactBrokerImageVersion string + +// Joins the standard tags for your context with any custom tags passed in via the parameter file. +var tags = union(envTags, { + Owner: '{Inser Owner Here}' + Environment: environment +}) + +var resourceGroupName = '${environment}-pactbroker-rg' +//An Azure App service is a public facing resource and must be unique. +//Update the name as needed if you recieve an error that the name is already in use! +var pactBrokerAppName = '${environment}-pactbroker-app-01' +var pactBrokerAspName = '${environment}-pactbroker-asp-01' +var postgresName = '${environment}-pactbroker-postgres-01' +var urlHostName = '{Insert Custom URL here}' + +// Creates the Resource Group for resources +module rg 'br:mcr.microsoft.com/bicep/avm/res/resources/resource-group:0.4.0' = { + name: deploymentName('rg-${resourceGroupName}') + scope: subscription() + params: { + name: resourceGroupName + location: location + tags: tags + } +} + +// Deploy PostgreSQL Server +module postgres 'br:mcr.microsoft.com/bicep/avm/res/db-for-postgre-sql/flexible-server:0.3.0' = { + name: take('${postgresName}-${uniqueString(string(deployment()))}', 64) + scope: resourceGroup(resourceGroupName) + params: { + location: location + name: postgresName + administratorLogin: administratorLogin + administratorLoginPassword: postgresPassword + tier: serverEdition + skuName: dbInstanceType + version: version + storageSizeGB: skuSizeGB + passwordAuth: 'Enabled' + firewallRules: [ + // Added to allows Access from Azure resources and services + { + name: 'AllowAllAzureServicesAndResourcesWithinAzureIps' + startIpAddress: '0.0.0.0' + endIpAddress: '0.0.0.0' + } + ] + } + dependsOn: [ + rg + ] +} + +//Deploy App Service Plan +module asp 'br:mcr.microsoft.com/bicep/avm/res/web/serverfarm:0.2.2' = { + name: take('${pactBrokerAspName}-${uniqueString(string(deployment()))}', 64) + scope: resourceGroup(resourceGroupName) + params: { + name: pactBrokerAspName + location: location + skuCapacity: 2 + skuName: 'B1' + kind: 'Linux' + } + dependsOn: [ + rg + ] +} + +//Deploy Linux Web App running PAct-Broker Container +module app 'br:mcr.microsoft.com/bicep/avm/res/web/site:0.9.0' = { + name: take('${pactBrokerAppName}-${uniqueString(string(deployment()))}', 64) + scope: resourceGroup(resourceGroupName) + params: { + name: pactBrokerAppName + location: location + kind: 'app,linux,container' + serverFarmResourceId: asp.outputs.resourceId + managedIdentities: { + systemAssigned: true + } + siteConfig: { + linuxFxVersion: 'DOCKER|pactfoundation/pact-broker:${pactBrokerImageVersion}' + appSettings: [ + { + name: 'DOCKER_REGISTRY_SERVER_PASSWORD' + value: '' + } + { + name: 'DOCKER_REGISTRY_SERVER_URL' + value: 'https://index.docker.io' + } + { + name: 'DOCKER_REGISTRY_SERVER_USERNAME' + value: '' + } + { + name: 'PACT_BROKER_BASE_URL' + value: urlHostName + } + { + name: 'PACT_BROKER_DATABASE_ADAPTER' + value: 'postgres' + } + { + name: 'PACT_BROKER_DATABASE_HOST' + value: postgres.outputs.fqdn + } + { + name: 'PACT_BROKER_DATABASE_NAME' + value: 'postgres' + } + { + name: 'PACT_BROKER_DATABASE_PORT' + value: 5432 + } + { + name: 'PACT_BROKER_DATABASE_USERNAME' + value: administratorLogin + } + { + name: 'PACT_BROKER_DATABASE_PASSWORD' + value: postgresPassword + } + { + name: 'PACT_BROKER_ENABLE_DIAGNOSTIC_ENDPOINTS' + value: true + } + { + name: 'PACT_BROKER_PORT' + value: 9292 + } + { + name: 'PACT_BROKER_PUBLIC_HEARTBEAT' + value: true + } + { + name: 'WEBSITE_HEALTHCHECK_MAXPINGFAILURES' + value: 2 + } + { + name: 'WEBSITE_HTTPLOGGING_RETENTION_DAYS' + value: 2 + } + { + name: 'WEBSITES_ENABLE_APP_SERVICE_STORAGE' + value: false + } + { + name: 'WEBSITES_PORT' + value: 9292 + } + ] + } + } + dependsOn: [ + rg + ] +} diff --git a/azure/templates/parameters/pact-broker.bicepparam b/azure/templates/parameters/pact-broker.bicepparam new file mode 100644 index 00000000..4bf2ec7d --- /dev/null +++ b/azure/templates/parameters/pact-broker.bicepparam @@ -0,0 +1,14 @@ +using '../pact-broker.bicep' + +param environment = 'dev' +param location = 'eastus2' +param envTags = { + 'Date Created': '20240926' +} +param postgresPassword = 'Password' +param serverEdition = 'GeneralPurpose' +param dbInstanceType = 'Standard_D4ds_v4' +param version = '13' +param skuSizeGB = 128 +param pactBrokerImageVersion = '2.107.0.1' +param administratorLogin = 'pactbroker' diff --git a/azure/templates/readme.md b/azure/templates/readme.md new file mode 100644 index 00000000..872bafbe --- /dev/null +++ b/azure/templates/readme.md @@ -0,0 +1,11 @@ +This folder containes a bicep template with the following resources. +``` +1. Resource Group to hold all resource +2. Postgres SQL Database +3. App Service Plan for the Web App +4. Web App runing linux +``` + +Each module block in the template poing to the Microsoft Bicep Module Repo, and uses Azure Verified Modules. + +In the script folder, the azcli.ps1 file will contain azcli commands to perform a What-if and Create deployment. \ No newline at end of file diff --git a/azure/templates/scripts/azcli.ps1 b/azure/templates/scripts/azcli.ps1 new file mode 100644 index 00000000..5c5df782 --- /dev/null +++ b/azure/templates/scripts/azcli.ps1 @@ -0,0 +1,18 @@ +## Command to connect to your azure subscription +az login + +## Command to set your subscription +#### NOTE, this is needed only if you have +#### more than one subscription available to your account. +az account set --subscription '{Insert subscription name or ID here}' + +## Command to run a What-If deployment at the scope of the bicep template +#### NOTE, the templates are as a subscription level, which is why +#### the commands above are needed. +az deployment sub what-if --location '{Insert deployment locations here}' --template-file .\pact-broker.bicep --parmeters .\parameters\pact-broker.bicepparam + +## Command to run a Create deployment at the scope of the bicep template +#### NOTE, the templates are as a subscription level, which is why +#### the commands above are needed. + +az deployment sub create --location '{Insert deployment locations here}' --template-file .\pact-broker.bicep --parmeters .\parameters\pact-broker.bicepparam \ No newline at end of file