-
Notifications
You must be signed in to change notification settings - Fork 1
/
container-app.bicep
92 lines (84 loc) · 2.93 KB
/
container-app.bicep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
param environmentName string
param location string = resourceGroup().location
param containerAppsEnvironmentName string = ''
param containerRegistryName string = ''
param env array = []
param external bool = true
param imageName string
param keyVaultName string = ''
param managedIdentity bool = !(empty(keyVaultName))
param targetPort int = 80
param serviceName string
var abbrs = loadJsonContent('../../abbreviations.json')
var resourceToken = toLower(uniqueString(subscription().id, environmentName, location))
var tags = { 'azd-env-name': environmentName }
resource app 'Microsoft.App/containerApps@2022-10-01' = {
name: '${abbrs.appContainerApps}${serviceName}-${resourceToken}'
location: location
tags: union(tags, { 'azd-service-name': serviceName })
identity: managedIdentity ? { type: 'SystemAssigned' } : null
properties: {
managedEnvironmentId: containerAppsEnvironment.id
configuration: {
activeRevisionsMode: 'single'
ingress: {
external: external
targetPort: targetPort
transport: 'auto'
customDomains: [
{
name: 'savannahostrowski.com'
certificateId: managedCertificate.id
bindingType: 'SniEnabled'
}
]
}
secrets: [
{
name: 'registry-password'
value: containerRegistry.listCredentials().passwords[0].value
}
]
registries: [
{
server: '${containerRegistry.name}.azurecr.io'
username: containerRegistry.name
passwordSecretRef: 'registry-password'
}
]
}
template: {
containers: [
{
image: imageName
name: 'main'
env: env
}
]
}
}
}
module keyVaultAccess '../security/keyvault-access.bicep' = if (!(empty(keyVaultName))) {
name: '${serviceName}-appservice-keyvault-access'
params: {
environmentName: environmentName
location: location
keyVaultName: keyVaultName
principalId: app.identity.principalId
}
}
resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2022-03-01' existing = {
name: !empty(containerAppsEnvironmentName) ? containerAppsEnvironmentName : '${abbrs.appManagedEnvironments}${resourceToken}'
}
// TODO: Maybe find a better way to do this?
resource managedCertificate 'Microsoft.App/managedEnvironments/managedCertificates@2022-11-01-preview' existing = {
name: 'savannahostrowski.com-rg-perso-230529183753'
parent: containerAppsEnvironment
}
resource containerRegistry 'Microsoft.ContainerRegistry/registries@2022-02-01-preview' existing = {
name: !empty(containerRegistryName) ? containerRegistryName : '${abbrs.containerRegistryRegistries}${resourceToken}'
}
output identityPrincipalId string = managedIdentity ? app.identity.principalId : ''
output name string = app.name
output uri string = 'https://${app.properties.configuration.ingress.fqdn}'
output containerAppEnvName string = containerAppsEnvironmentName