Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the infra/core modules to AVM modules #3976

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
953f948
Convert infra/core to AVM
Menghua1 Jun 4, 2024
a66ba8a
Add the modification of repo.yaml
Menghua1 Jun 4, 2024
a6034f5
Modify parameter description, spaces, etc.
Menghua1 Jun 4, 2024
3163c23
Standard parameter naming
Menghua1 Jun 6, 2024
b3a89a8
modify models.py
Menghua1 Jun 19, 2024
50473a4
fix pr2016 and pr2103
Menghua1 Jun 21, 2024
4b2f44a
update apim service toavm module
Menghua1 Jun 24, 2024
00648d5
Add useAPIM conditional judgment
Menghua1 Jun 24, 2024
cef4144
update web site config to avm
Menghua1 Jul 5, 2024
ffa27d9
add api tags
Menghua1 Jul 5, 2024
93de7e6
update keyvault sku
Menghua1 Jul 9, 2024
9f95b92
disable purge protection
Menghua1 Jul 9, 2024
b3fd198
disable purge protection
Menghua1 Jul 9, 2024
a6a3010
Merge remote-tracking branch 'origin/main' into avmupdates
Menghua1 Jul 10, 2024
9b54ddd
Merge remote-tracking branch 'origin/main' into avmupdates
Menghua1 Aug 23, 2024
868ab2e
Add Infra/app files
Menghua1 Sep 2, 2024
7ad17e8
modify parameters
Menghua1 Sep 2, 2024
26963c9
Modify api-avm parameters
Menghua1 Sep 3, 2024
56d33e9
update apimapi to use ptn module
Menghua1 Sep 29, 2024
8f34f52
Merge branch 'main' into avmupdates
Menghua1 Sep 29, 2024
3399e7f
update db to infra/app
Menghua1 Sep 29, 2024
bab182b
Merge branch 'main' into avmupdates
Menghua1 Oct 9, 2024
17f0961
Update apim parameter, cosmos-sql
Menghua1 Oct 9, 2024
93947a2
Update cosmos-mongo module name
Menghua1 Oct 9, 2024
fd8a899
delete the redundant parameter connectionStringKey
Menghua1 Oct 11, 2024
52ddfbe
add monitor ptn module
Menghua1 Oct 12, 2024
def0102
Merge branch 'main' into avmupdates
Menghua1 Oct 15, 2024
1f7da17
add container pth module
Menghua1 Oct 15, 2024
f1077a7
update cosmos-mongo-db-avm output
Menghua1 Oct 22, 2024
828f2a6
update aks and aca to avm
Menghua1 Oct 28, 2024
8910cac
Update appservice with App Insights env var
Menghua1 Oct 28, 2024
260ac1c
Merge branch 'main' into avmupdates
Menghua1 Oct 28, 2024
7eff057
Update module name
Menghua1 Oct 28, 2024
5406a10
Update module container-app-upsert version
Menghua1 Oct 29, 2024
b8ff872
Merge branch 'main' into avmupdates
Menghua1 Nov 20, 2024
257f48a
update nodeResourceGroupName parameter
Menghua1 Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions templates/todo/common/infra/bicep/app/api-appservice-avm.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
param name string
param location string = resourceGroup().location
param tags object = {}

param allowedOrigins array = []
param appCommandLine string?
param appInsightResourceId string
param appServicePlanId string
@secure()
param appSettings object = {}
param siteConfig object = {}
param serviceName string = 'api'

@description('Required. Type of site to deploy.')
param kind string

@description('Optional. If client affinity is enabled.')
param clientAffinityEnabled bool = true

@description('Optional. Required if app of kind functionapp. Resource ID of the storage account to manage triggers and logging function executions.')
param storageAccountResourceId string?

module api 'br/public:avm/res/web/site:0.6.0' = {
name: '${name}-app-module'
params: {
kind: kind
name: name
serverFarmResourceId: appServicePlanId
tags: union(tags, { 'azd-service-name': serviceName })
location: location
appInsightResourceId: appInsightResourceId
clientAffinityEnabled: clientAffinityEnabled
storageAccountResourceId: storageAccountResourceId
managedIdentities: {
systemAssigned: true
}
siteConfig: union(siteConfig, {
cors: {
allowedOrigins: union(['https://portal.azure.com', 'https://ms.portal.azure.com'], allowedOrigins)
}
appCommandLine: appCommandLine
})
appSettingsKeyValuePairs: union(
appSettings,
{ ENABLE_ORYX_BUILD: true, ApplicationInsightsAgent_EXTENSION_VERSION: contains(kind, 'linux') ? '~3' : '~2' }
)
logsConfiguration: {
applicationLogs: { fileSystem: { level: 'Verbose' } }
detailedErrorMessages: { enabled: true }
failedRequestsTracing: { enabled: true }
httpLogs: { fileSystem: { enabled: true, retentionInDays: 1, retentionInMb: 35 } }
}
}
}

output SERVICE_API_IDENTITY_PRINCIPAL_ID string = api.outputs.systemAssignedMIPrincipalId
output SERVICE_API_NAME string = api.outputs.name
output SERVICE_API_URI string = 'https://${api.outputs.defaultHostname}'
77 changes: 77 additions & 0 deletions templates/todo/common/infra/bicep/app/cosmos-mongo-db-avm.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
param accountName string
param location string = resourceGroup().location
param tags object = {}
param cosmosDatabaseName string = ''
param keyVaultResourceId string
param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING'
param collections array = [
{
name: 'TodoList'
id: 'TodoList'
shardKey: {
keys: [
'Hash'
]
}
indexes: [
{
key: {
keys: [
'_id'
]
}
}
]
}
{
name: 'TodoItem'
id: 'TodoItem'
shardKey: {
keys: [
'Hash'
]
}
indexes: [
{
key: {
keys: [
'_id'
]
}
}
]
}
]

var defaultDatabaseName = 'Todo'
var actualDatabaseName = !empty(cosmosDatabaseName) ? cosmosDatabaseName : defaultDatabaseName

module cosmos 'br/public:avm/res/document-db/database-account:0.6.0' = {
name: 'cosmos-mongo'
params: {
locations: [
{
failoverPriority: 0
isZoneRedundant: false
locationName: location
}
]
name: accountName
location: location
mongodbDatabases: [
{
name: actualDatabaseName
tags: tags
collections: collections
}
]
secretsExportConfiguration: {
keyVaultResourceId: keyVaultResourceId
primaryWriteConnectionStringSecretName: connectionStringKey
}
}
}

output connectionStringKey string = connectionStringKey
output databaseName string = actualDatabaseName
output endpoint string = cosmos.outputs.endpoint
66 changes: 66 additions & 0 deletions templates/todo/common/infra/bicep/app/cosmos-sql-db-avm.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
param accountName string
param location string = resourceGroup().location
param tags object = {}
param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING'
param databaseName string = ''
param keyVaultResourceId string
param principalId string = ''

@allowed([
'Periodic'
'Continuous'
])
@description('Optional. Default to Continuous. Describes the mode of backups. Periodic backup must be used if multiple write locations are used.')
param backupPolicyType string = 'Continuous'

var defaultDatabaseName = 'Todo'
var actualDatabaseName = !empty(databaseName) ? databaseName : defaultDatabaseName

module cosmos 'br/public:avm/res/document-db/database-account:0.6.0' = {
name: 'cosmos-sql'
params: {
name: accountName
location: location
tags: tags
backupPolicyType: backupPolicyType
locations: [
{
failoverPriority: 0
locationName: location
isZoneRedundant: false
}
]
secretsExportConfiguration:{
keyVaultResourceId: keyVaultResourceId
primaryWriteConnectionStringSecretName: connectionStringKey
}
capabilitiesToAdd: [ 'EnableServerless' ]
automaticFailover: false
sqlDatabases: [
{
name: actualDatabaseName
containers: [
{
name: 'TodoList'
paths: [ 'id' ]
}
{
name: 'TodoItem'
paths: [ 'id' ]
}
]
}
]
sqlRoleAssignmentsPrincipalIds: [ principalId ]
sqlRoleDefinitions: [
{
name: 'writer'
}
]
}
}

output accountName string = cosmos.outputs.name
output connectionStringKey string = connectionStringKey
output databaseName string = actualDatabaseName
output endpoint string = cosmos.outputs.endpoint
109 changes: 109 additions & 0 deletions templates/todo/common/infra/bicep/app/sqlserver-avm.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
param location string = resourceGroup().location

@description('Application user name')
param appUser string

@description('SQL Server administrator name')
param sqlAdmin string = 'sqlAdmin'

@description('The name for sql database ')
param sqlDatabaseName string = ''

@description('Resource name for sql service')
param sqlServiceName string

@secure()
@description('SQL Server administrator password')
param sqlAdminPassword string

@secure()
@description('Application user password')
param appUserPassword string

param tags object = {}

var defaultDatabaseName = 'Todo'
var actualDatabaseName = !empty(sqlDatabaseName) ? sqlDatabaseName : defaultDatabaseName

module sqlServer 'br/public:avm/res/sql/server:0.2.0' = {
name: 'sqlservice'
params: {
name: sqlServiceName
administratorLogin: sqlAdmin
administratorLoginPassword: sqlAdminPassword
location: location
tags: tags
publicNetworkAccess: 'Enabled'
databases: [
{
name: actualDatabaseName
}
]
firewallRules: [
{
name: 'Azure Services'
startIpAddress: '0.0.0.1'
endIpAddress: '255.255.255.254'
}
]
}
}

module deploymentScript 'br/public:avm/res/resources/deployment-script:0.1.3' = {
name: 'deployment-script'
params: {
kind: 'AzureCLI'
name: 'deployment-script'
azCliVersion: '2.37.0'
location: location
retentionInterval: 'PT1H'
timeout: 'PT5M'
cleanupPreference: 'OnSuccess'
environmentVariables:{
secureList: [
{
name: 'APPUSERNAME'
value: appUser
}
{
name: 'APPUSERPASSWORD'
secureValue: appUserPassword
}
{
name: 'DBNAME'
value: actualDatabaseName
}
{
name: 'DBSERVER'
value: '${sqlServer.outputs.name}${environment().suffixes.sqlServerHostname}'
}
{
name: 'SQLCMDPASSWORD'
secureValue: sqlAdminPassword
}
{
name: 'SQLADMIN'
value: sqlAdmin
}
]
}
scriptContent: '''
wget https://github.com/microsoft/go-sqlcmd/releases/download/v0.8.1/sqlcmd-v0.8.1-linux-x64.tar.bz2
tar x -f sqlcmd-v0.8.1-linux-x64.tar.bz2 -C .

cat <<SCRIPT_END > ./initDb.sql
drop user if exists ${APPUSERNAME}
go
create user ${APPUSERNAME} with password = '${APPUSERPASSWORD}'
go
alter role db_owner add member ${APPUSERNAME}
go
SCRIPT_END

./sqlcmd -S ${DBSERVER} -d ${DBNAME} -U ${SQLADMIN} -i ./initDb.sql
'''
}
}

output databaseName string = actualDatabaseName
output sqlServerName string = sqlServer.outputs.name
37 changes: 37 additions & 0 deletions templates/todo/common/infra/bicep/app/web-appservice-avm.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
param name string
param location string = resourceGroup().location
param tags object = {}
param serviceName string = 'web'
param appCommandLine string = 'pm2 serve /home/site/wwwroot --no-daemon --spa'
param appInsightResourceId string
param appServicePlanId string
param linuxFxVersion string
param kind string = 'app,linux'

module web 'br/public:avm/res/web/site:0.6.0' = {
name: '${name}-deployment'
params: {
kind: kind
name: name
serverFarmResourceId: appServicePlanId
tags: union(tags, { 'azd-service-name': serviceName })
location: location
appInsightResourceId: appInsightResourceId
siteConfig: {
appCommandLine: appCommandLine
linuxFxVersion: linuxFxVersion
alwaysOn: true
}
logsConfiguration: {
applicationLogs: { fileSystem: { level: 'Verbose' } }
detailedErrorMessages: { enabled: true }
failedRequestsTracing: { enabled: true }
httpLogs: { fileSystem: { enabled: true, retentionInDays: 1, retentionInMb: 35 } }
}
appSettingsKeyValuePairs: { ApplicationInsightsAgent_EXTENSION_VERSION: contains(kind, 'linux') ? '~3' : '~2' }
}
}

output SERVICE_WEB_IDENTITY_PRINCIPAL_ID string = web.outputs.systemAssignedMIPrincipalId
output SERVICE_WEB_NAME string = web.outputs.name
output SERVICE_WEB_URI string = 'https://${web.outputs.defaultHostname}'
Loading
Loading