From 9ca032f07f5d5d3c329c977c9746aa3caeefeef7 Mon Sep 17 00:00:00 2001 From: Pieter de Bruin Date: Mon, 8 Apr 2024 11:55:37 +0200 Subject: [PATCH] with web --- 5azd/infra/app/apim-api.bicep | 240 +++++++++++++++++----------------- 5azd/infra/app/db.bicep | 72 +++++----- 5azd/infra/main.bicep | 28 ++-- 3 files changed, 170 insertions(+), 170 deletions(-) diff --git a/5azd/infra/app/apim-api.bicep b/5azd/infra/app/apim-api.bicep index 051e4b0..17b8577 100644 --- a/5azd/infra/app/apim-api.bicep +++ b/5azd/infra/app/apim-api.bicep @@ -1,120 +1,120 @@ -param name string - -@description('Resource name to uniquely identify this API within the API Management service instance') -@minLength(1) -param apiName string - -@description('The Display Name of the API') -@minLength(1) -@maxLength(300) -param apiDisplayName string - -@description('Description of the API. May include HTML formatting tags.') -@minLength(1) -param apiDescription string - -@description('Relative URL uniquely identifying this API and all of its resource paths within the API Management service instance. It is appended to the API endpoint base URL specified during the service instance creation to form a public URL for this API.') -@minLength(1) -param apiPath string - -@description('Absolute URL of the web frontend') -param webFrontendUrl string - -@description('Absolute URL of the backend service implementing this API.') -param apiBackendUrl string - -@description('Resource name for backend Web App or Function App') -param apiAppName string = '' - -var apiPolicyContent = replace(loadTextContent('./apim-api-policy.xml'), '{origin}', webFrontendUrl) - -resource restApi 'Microsoft.ApiManagement/service/apis@2021-12-01-preview' = { - name: apiName - parent: apimService - properties: { - description: apiDescription - displayName: apiDisplayName - path: apiPath - protocols: [ 'https' ] - subscriptionRequired: false - type: 'http' - format: 'openapi' - serviceUrl: apiBackendUrl - value: loadTextContent('../../src/api/openapi.yaml') - } -} - -resource apiPolicy 'Microsoft.ApiManagement/service/apis/policies@2021-12-01-preview' = { - name: 'policy' - parent: restApi - properties: { - format: 'rawxml' - value: apiPolicyContent - } -} - -resource apiDiagnostics 'Microsoft.ApiManagement/service/apis/diagnostics@2021-12-01-preview' = { - name: 'applicationinsights' - parent: restApi - properties: { - alwaysLog: 'allErrors' - backend: { - request: { - body: { - bytes: 1024 - } - } - response: { - body: { - bytes: 1024 - } - } - } - frontend: { - request: { - body: { - bytes: 1024 - } - } - response: { - body: { - bytes: 1024 - } - } - } - httpCorrelationProtocol: 'W3C' - logClientIp: true - loggerId: apimLogger.id - metrics: true - sampling: { - percentage: 100 - samplingType: 'fixed' - } - verbosity: 'verbose' - } -} - -resource apimService 'Microsoft.ApiManagement/service@2021-08-01' existing = { - name: name -} - -// Necessary due to https://github.com/Azure/bicep/issues/9594 -// placeholderName is never deployed, it is merely used to make the child name validation pass -var appNameForBicep = !empty(apiAppName) ? apiAppName : 'placeholderName' - -resource apiAppProperties 'Microsoft.Web/sites/config@2022-03-01' = if (!empty(apiAppName)) { - name: '${appNameForBicep}/web' - kind: 'string' - properties: { - apiManagementConfig: { - id: '${apimService.id}/apis/${apiName}' - } - } -} - -resource apimLogger 'Microsoft.ApiManagement/service/loggers@2021-12-01-preview' existing = { - name: 'app-insights-logger' - parent: apimService -} - -output SERVICE_API_URI string = '${apimService.properties.gatewayUrl}/${apiPath}' +// param name string + +// @description('Resource name to uniquely identify this API within the API Management service instance') +// @minLength(1) +// param apiName string + +// @description('The Display Name of the API') +// @minLength(1) +// @maxLength(300) +// param apiDisplayName string + +// @description('Description of the API. May include HTML formatting tags.') +// @minLength(1) +// param apiDescription string + +// @description('Relative URL uniquely identifying this API and all of its resource paths within the API Management service instance. It is appended to the API endpoint base URL specified during the service instance creation to form a public URL for this API.') +// @minLength(1) +// param apiPath string + +// @description('Absolute URL of the web frontend') +// param webFrontendUrl string + +// @description('Absolute URL of the backend service implementing this API.') +// param apiBackendUrl string + +// @description('Resource name for backend Web App or Function App') +// param apiAppName string = '' + +// var apiPolicyContent = replace(loadTextContent('./apim-api-policy.xml'), '{origin}', webFrontendUrl) + +// resource restApi 'Microsoft.ApiManagement/service/apis@2021-12-01-preview' = { +// name: apiName +// parent: apimService +// properties: { +// description: apiDescription +// displayName: apiDisplayName +// path: apiPath +// protocols: [ 'https' ] +// subscriptionRequired: false +// type: 'http' +// format: 'openapi' +// serviceUrl: apiBackendUrl +// value: loadTextContent('../../src/api/openapi.yaml') +// } +// } + +// resource apiPolicy 'Microsoft.ApiManagement/service/apis/policies@2021-12-01-preview' = { +// name: 'policy' +// parent: restApi +// properties: { +// format: 'rawxml' +// value: apiPolicyContent +// } +// } + +// resource apiDiagnostics 'Microsoft.ApiManagement/service/apis/diagnostics@2021-12-01-preview' = { +// name: 'applicationinsights' +// parent: restApi +// properties: { +// alwaysLog: 'allErrors' +// backend: { +// request: { +// body: { +// bytes: 1024 +// } +// } +// response: { +// body: { +// bytes: 1024 +// } +// } +// } +// frontend: { +// request: { +// body: { +// bytes: 1024 +// } +// } +// response: { +// body: { +// bytes: 1024 +// } +// } +// } +// httpCorrelationProtocol: 'W3C' +// logClientIp: true +// loggerId: apimLogger.id +// metrics: true +// sampling: { +// percentage: 100 +// samplingType: 'fixed' +// } +// verbosity: 'verbose' +// } +// } + +// resource apimService 'Microsoft.ApiManagement/service@2021-08-01' existing = { +// name: name +// } + +// // Necessary due to https://github.com/Azure/bicep/issues/9594 +// // placeholderName is never deployed, it is merely used to make the child name validation pass +// var appNameForBicep = !empty(apiAppName) ? apiAppName : 'placeholderName' + +// resource apiAppProperties 'Microsoft.Web/sites/config@2022-03-01' = if (!empty(apiAppName)) { +// name: '${appNameForBicep}/web' +// kind: 'string' +// properties: { +// apiManagementConfig: { +// id: '${apimService.id}/apis/${apiName}' +// } +// } +// } + +// resource apimLogger 'Microsoft.ApiManagement/service/loggers@2021-12-01-preview' existing = { +// name: 'app-insights-logger' +// parent: apimService +// } + +// output SERVICE_API_URI string = '${apimService.properties.gatewayUrl}/${apiPath}' diff --git a/5azd/infra/app/db.bicep b/5azd/infra/app/db.bicep index 938949c..80cfdcc 100644 --- a/5azd/infra/app/db.bicep +++ b/5azd/infra/app/db.bicep @@ -1,40 +1,40 @@ -param accountName string -param location string = resourceGroup().location -param tags object = {} +// param accountName string +// param location string = resourceGroup().location +// param tags object = {} -param collections array = [ - { - name: 'TodoList' - id: 'TodoList' - shardKey: 'Hash' - indexKey: '_id' - } - { - name: 'TodoItem' - id: 'TodoItem' - shardKey: 'Hash' - indexKey: '_id' - } -] -param databaseName string = '' -param keyVaultName string +// param collections array = [ +// { +// name: 'TodoList' +// id: 'TodoList' +// shardKey: 'Hash' +// indexKey: '_id' +// } +// { +// name: 'TodoItem' +// id: 'TodoItem' +// shardKey: 'Hash' +// indexKey: '_id' +// } +// ] +// param databaseName string = '' +// param keyVaultName string -// Because databaseName is optional in main.bicep, we make sure the database name is set here. -var defaultDatabaseName = 'Todo' -var actualDatabaseName = !empty(databaseName) ? databaseName : defaultDatabaseName +// // Because databaseName is optional in main.bicep, we make sure the database name is set here. +// var defaultDatabaseName = 'Todo' +// var actualDatabaseName = !empty(databaseName) ? databaseName : defaultDatabaseName -module cosmos '../core/database/cosmos/mongo/cosmos-mongo-db.bicep' = { - name: 'cosmos-mongo' - params: { - accountName: accountName - databaseName: actualDatabaseName - location: location - collections: collections - keyVaultName: keyVaultName - tags: tags - } -} +// module cosmos '../core/database/cosmos/mongo/cosmos-mongo-db.bicep' = { +// name: 'cosmos-mongo' +// params: { +// accountName: accountName +// databaseName: actualDatabaseName +// location: location +// collections: collections +// keyVaultName: keyVaultName +// tags: tags +// } +// } -output connectionStringKey string = cosmos.outputs.connectionStringKey -output databaseName string = cosmos.outputs.databaseName -output endpoint string = cosmos.outputs.endpoint +// output connectionStringKey string = cosmos.outputs.connectionStringKey +// output databaseName string = cosmos.outputs.databaseName +// output endpoint string = cosmos.outputs.endpoint diff --git a/5azd/infra/main.bicep b/5azd/infra/main.bicep index 14b5fad..063889e 100644 --- a/5azd/infra/main.bicep +++ b/5azd/infra/main.bicep @@ -23,7 +23,7 @@ param keyVaultName string = '' param logAnalyticsName string = '' param resourceGroupName string = '' param storageAccountName string = '' -// param webServiceName string = '' +param webServiceName string = '' // param apimServiceName string = '' @description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API') @@ -46,16 +46,16 @@ resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = { tags: tags } -// // The application frontend -// module web './app/web.bicep' = { -// name: 'web' -// scope: rg -// params: { -// name: !empty(webServiceName) ? webServiceName : '${abbrs.webStaticSites}web-${resourceToken}' -// location: location -// tags: tags -// } -// } +// The application frontend +module web './app/web.bicep' = { + name: 'web' + scope: rg + params: { + name: !empty(webServiceName) ? webServiceName : '${abbrs.webStaticSites}web-${resourceToken}' + location: location + tags: tags + } +} // The application backend module api './app/api.bicep' = { @@ -192,8 +192,8 @@ output AZURE_KEY_VAULT_ENDPOINT string = keyVault.outputs.endpoint output AZURE_KEY_VAULT_NAME string = keyVault.outputs.name output AZURE_LOCATION string = location output AZURE_TENANT_ID string = tenant().tenantId -// output REACT_APP_API_BASE_URL string = useAPIM ? apimApi.outputs.SERVICE_API_URI : api.outputs.SERVICE_API_URI -// output REACT_APP_APPLICATIONINSIGHTS_CONNECTION_STRING string = monitoring.outputs.applicationInsightsConnectionString -// output REACT_APP_WEB_BASE_URL string = web.outputs.SERVICE_WEB_URI +output REACT_APP_API_BASE_URL string = useAPIM ? apimApi.outputs.SERVICE_API_URI : api.outputs.SERVICE_API_URI +output REACT_APP_APPLICATIONINSIGHTS_CONNECTION_STRING string = monitoring.outputs.applicationInsightsConnectionString +output REACT_APP_WEB_BASE_URL string = web.outputs.SERVICE_WEB_URI output USE_APIM bool = useAPIM // output SERVICE_API_ENDPOINTS array = useAPIM ? [ apimApi.outputs.SERVICE_API_URI, api.outputs.SERVICE_API_URI ]: []