Skip to content

Commit

Permalink
update apim service toavm module
Browse files Browse the repository at this point in the history
  • Loading branch information
Menghua1 committed Jun 24, 2024
1 parent 50473a4 commit 4b2f44a
Show file tree
Hide file tree
Showing 24 changed files with 692 additions and 220 deletions.
99 changes: 0 additions & 99 deletions templates/todo/common/infra/bicep/app/apim-api-settings.bicep

This file was deleted.

21 changes: 21 additions & 0 deletions templates/todo/common/infra/bicep/app/website-config.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@description('Resource name for backend Web App or Function App')
param apiAppName string = ''

@description('Resource name to uniquely identify this API within the API Management service instance')
@minLength(1)
param apiName string

@description('Resource ID for the existing apim service')
param apimServiceId string

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: '${apimServiceId}/apis/${apiName}'
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ param resourceGroupName string = ''
param webServiceName string = ''
param apimServiceName string = ''
param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING'
param apimApiName string = 'todo-api'
param apimLoggerName string = 'app-insights-logger'

@description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API')
param useAPIM bool = false
Expand Down Expand Up @@ -250,7 +252,7 @@ module applicationInsightsDashboard '../../../../../common/infra/bicep/app/appli
}

// Creates Azure API Management (APIM) service to mediate the requests between the frontend and the backend API
module apim 'br/public:avm/res/api-management/service:0.1.7' = if (useAPIM) {
module apim 'br/public:avm/res/api-management/service:0.2.0' = if (useAPIM) {
name: 'apim-deployment'
scope: rg
params: {
Expand All @@ -261,9 +263,59 @@ module apim 'br/public:avm/res/api-management/service:0.1.7' = if (useAPIM) {
tags: tags
sku: apimSku
skuCount: 0
customProperties: {}
zones: []
apiDiagnostics: [
{
apiName: apimApiName
alwaysLog: 'allErrors'
backend: {
request: {
body: {
bytes: 1024
}
}
response: {
body: {
bytes: 1024
}
}
}
frontend: {
request: {
body: {
bytes: 1024
}
}
response: {
body: {
bytes: 1024
}
}
}
httpCorrelationProtocol: 'W3C'
logClientIp: true
loggerName: apimLoggerName
metrics: true
verbosity: 'verbose'
name: 'applicationinsights'
}
]
loggers: [
{
name: apimLoggerName
credentials: {
instrumentationKey: applicationInsights.outputs.instrumentationKey
}
loggerDescription: 'Logger to Azure Application Insights'
isBuffered: false
loggerType: 'applicationInsights'
targetResourceId: applicationInsights.outputs.resourceId
}
]
apis: [
{
name: 'todo-api'
name: apimApiName
path: 'todo'
displayName: 'Simple Todo API'
apiDescription: 'This is a simple Todo API'
Expand All @@ -283,16 +335,14 @@ module apim 'br/public:avm/res/api-management/service:0.1.7' = if (useAPIM) {
}
}

// Configures the API in the Azure API Management (APIM) service
module apimSettings '../../../../../common/infra/bicep/app/apim-api-settings.bicep' = if (useAPIM) {
name: 'apim-api-settings'
//Configures the API settings for an api app within the Azure API Management (APIM) service.
module apiConfig '../../../../../common/infra/bicep/app/website-config.bicep' = if (useAPIM) {
name: 'apiconfig'
scope: rg
params: {
apimServiceId: apim.outputs.resourceId
apiName: apimApiName
apiAppName: api.outputs.name
apiName: 'todo-api'
name: useAPIM ? apim.outputs.name : ''
apiPath: 'todo'
applicationInsightsName: applicationInsights.outputs.name
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ repo:
- from: ../../../../common/infra/bicep/app/applicationinsights-dashboard.bicep
to: ./infra/app/applicationinsights-dashboard.bicep

- from: ../../../../common/infra/bicep/app/apim-api-settings.bicep
to: ./infra/app/apim-api-settings.bicep
- from: ../../../../common/infra/bicep/app/website-config.bicep
to: ./infra/app/website-config.bicep

- from: ./../../
to: ./
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ param apimServiceName string = ''
param appUser string = 'appUser'
param sqlAdmin string = 'sqlAdmin'
param connectionStringKey string = 'AZURE-SQL-CONNECTION-STRING'
param apimApiName string = 'todo-api'
param apimLoggerName string = 'app-insights-logger'

@description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API')
param useAPIM bool = false
Expand Down Expand Up @@ -269,7 +271,7 @@ module applicationInsightsDashboard '../../../../../common/infra/bicep/app/appli
}

// Creates Azure API Management (APIM) service to mediate the requests between the frontend and the backend API
module apim 'br/public:avm/res/api-management/service:0.1.7' = if (useAPIM) {
module apim 'br/public:avm/res/api-management/service:0.2.0' = if (useAPIM) {
name: 'apim-deployment'
scope: rg
params: {
Expand All @@ -280,9 +282,59 @@ module apim 'br/public:avm/res/api-management/service:0.1.7' = if (useAPIM) {
tags: tags
sku: apimSku
skuCount: 0
customProperties: {}
zones: []
apiDiagnostics: [
{
apiName: apimApiName
alwaysLog: 'allErrors'
backend: {
request: {
body: {
bytes: 1024
}
}
response: {
body: {
bytes: 1024
}
}
}
frontend: {
request: {
body: {
bytes: 1024
}
}
response: {
body: {
bytes: 1024
}
}
}
httpCorrelationProtocol: 'W3C'
logClientIp: true
loggerName: apimLoggerName
metrics: true
verbosity: 'verbose'
name: 'applicationinsights'
}
]
loggers: [
{
name: apimLoggerName
credentials: {
instrumentationKey: applicationInsights.outputs.instrumentationKey
}
loggerDescription: 'Logger to Azure Application Insights'
isBuffered: false
loggerType: 'applicationInsights'
targetResourceId: applicationInsights.outputs.resourceId
}
]
apis: [
{
name: 'todo-api'
name: apimApiName
path: 'todo'
displayName: 'Simple Todo API'
apiDescription: 'This is a simple Todo API'
Expand All @@ -302,16 +354,14 @@ module apim 'br/public:avm/res/api-management/service:0.1.7' = if (useAPIM) {
}
}

// Configures the API in the Azure API Management (APIM) service
module apimSettings '../../../../../common/infra/bicep/app/apim-api-settings.bicep' = if (useAPIM) {
name: 'apim-api-settings'
//Configures the API settings for an api app within the Azure API Management (APIM) service.
module apiConfig '../../../../../common/infra/bicep/app/website-config.bicep' = if (useAPIM) {
name: 'apiconfig'
scope: rg
params: {
apimServiceId: apim.outputs.resourceId
apiName: apimApiName
apiAppName: api.outputs.name
apiName: 'todo-api'
name: useAPIM ? apim.outputs.name : ''
apiPath: 'todo'
applicationInsightsName: applicationInsights.outputs.name
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ repo:
- from: ../../../../common/infra/bicep/app/applicationinsights-dashboard.bicep
to: ./infra/app/applicationinsights-dashboard.bicep

- from: ../../../../common/infra/bicep/app/apim-api-settings.bicep
to: ./infra/app/apim-api-settings.bicep
- from: ../../../../common/infra/bicep/app/website-config.bicep
to: ./infra/app/website-config.bicep

- from: ../../../../common/infra/bicep/app/sql-deployment-script.bicep
to: ./infra/app/sql-deployment-script.bicep
Expand Down
Loading

0 comments on commit 4b2f44a

Please sign in to comment.