-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
273 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
targetScope = 'resourceGroup' | ||
|
||
@description('The tag of the image to be used') | ||
@minLength(3) | ||
param imageTag string | ||
|
||
@description('The environment for the deployment') | ||
@minLength(3) | ||
param environment string | ||
|
||
@description('The location where the resources will be deployed') | ||
@minLength(3) | ||
param location string | ||
|
||
@description('The suffix for the revision of the container app') | ||
@minLength(3) | ||
param revisionSuffix string | ||
|
||
@description('CPU and memory resources for the container app') | ||
param resources object? | ||
|
||
@description('The name of the container app environment') | ||
@minLength(3) | ||
param containerAppEnvironmentName string | ||
|
||
@description('The name of the Service Bus namespace') | ||
@minLength(3) | ||
param serviceBusNamespaceName string | ||
|
||
@description('The connection string for Application Insights') | ||
@minLength(3) | ||
@secure() | ||
param appInsightConnectionString string | ||
|
||
@description('The name of the App Configuration store') | ||
@minLength(5) | ||
param appConfigurationName string | ||
|
||
@description('The name of the Key Vault for the environment') | ||
@minLength(3) | ||
param environmentKeyVaultName string | ||
|
||
var namePrefix = 'dp-be-${environment}' | ||
var baseImageUrl = 'ghcr.io/digdir/dialogporten-' | ||
var tags = { | ||
Environment: environment | ||
Product: 'Dialogporten' | ||
} | ||
|
||
resource appConfiguration 'Microsoft.AppConfiguration/configurationStores@2023-03-01' existing = { | ||
name: appConfigurationName | ||
} | ||
|
||
resource containerAppEnvironment 'Microsoft.App/managedEnvironments@2024-03-01' existing = { | ||
name: containerAppEnvironmentName | ||
} | ||
|
||
resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = { | ||
name: '${namePrefix}-service-identity' | ||
location: location | ||
tags: tags | ||
} | ||
|
||
var containerAppEnvVars = [ | ||
{ | ||
name: 'ASPNETCORE_ENVIRONMENT' | ||
value: environment | ||
} | ||
{ | ||
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING' | ||
value: appInsightConnectionString | ||
} | ||
{ | ||
name: 'AZURE_APPCONFIG_URI' | ||
value: appConfiguration.properties.endpoint | ||
} | ||
{ | ||
name: 'ASPNETCORE_URLS' | ||
value: 'http://+:8080' | ||
} | ||
{ | ||
name: 'AZURE_CLIENT_ID' | ||
value: managedIdentity.properties.clientId | ||
} | ||
] | ||
|
||
resource environmentKeyVaultResource 'Microsoft.KeyVault/vaults@2023-07-01' existing = { | ||
name: environmentKeyVaultName | ||
} | ||
|
||
var serviceName = 'service' | ||
|
||
var containerAppName = '${namePrefix}-${serviceName}' | ||
|
||
var port = 8080 | ||
|
||
var probes = [ | ||
{ | ||
periodSeconds: 5 | ||
initialDelaySeconds: 2 | ||
type: 'Liveness' | ||
httpGet: { | ||
path: '/healthz' | ||
port: port | ||
} | ||
} | ||
{ | ||
periodSeconds: 5 | ||
initialDelaySeconds: 2 | ||
type: 'Readiness' | ||
httpGet: { | ||
path: '/healthz' | ||
port: port | ||
} | ||
} | ||
{ | ||
periodSeconds: 5 | ||
initialDelaySeconds: 2 | ||
type: 'Startup' | ||
httpGet: { | ||
path: '/healthz' | ||
port: port | ||
} | ||
} | ||
] | ||
|
||
module keyVaultReaderAccessPolicy '../../modules/keyvault/addReaderRoles.bicep' = { | ||
name: 'keyVaultReaderAccessPolicy-${containerAppName}' | ||
params: { | ||
keyvaultName: environmentKeyVaultResource.name | ||
principalIds: [managedIdentity.properties.principalId] | ||
} | ||
} | ||
|
||
module appConfigReaderAccessPolicy '../../modules/appConfiguration/addReaderRoles.bicep' = { | ||
name: 'appConfigReaderAccessPolicy-${containerAppName}' | ||
params: { | ||
appConfigurationName: appConfigurationName | ||
principalIds: [managedIdentity.properties.principalId] | ||
} | ||
} | ||
|
||
module serviceBusOwnerAccessPolicy '../../modules/serviceBus/addDataOwnerRoles.bicep' = { | ||
name: 'serviceBusOwnerAccessPolicy-${containerAppName}' | ||
params: { | ||
serviceBusNamespaceName: serviceBusNamespaceName | ||
principalIds: [managedIdentity.properties.principalId] | ||
} | ||
} | ||
|
||
module containerApp '../../modules/containerApp/main.bicep' = { | ||
name: containerAppName | ||
params: { | ||
name: containerAppName | ||
image: '${baseImageUrl}${serviceName}:${imageTag}' | ||
location: location | ||
envVariables: containerAppEnvVars | ||
containerAppEnvId: containerAppEnvironment.id | ||
tags: tags | ||
resources: resources | ||
probes: probes | ||
port: port | ||
revisionSuffix: revisionSuffix | ||
userAssignedIdentityId: managedIdentity.id | ||
// TODO: Once all container apps use user-assigned identities, remove this comment and ensure userAssignedIdentityId is always provided | ||
} | ||
dependsOn: [ | ||
keyVaultReaderAccessPolicy | ||
appConfigReaderAccessPolicy | ||
serviceBusOwnerAccessPolicy | ||
] | ||
} | ||
|
||
output name string = containerApp.outputs.name | ||
output revisionName string = containerApp.outputs.revisionName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using './main.bicep' | ||
|
||
param environment = 'prod' | ||
param location = 'norwayeast' | ||
param imageTag = readEnvironmentVariable('IMAGE_TAG') | ||
param revisionSuffix = readEnvironmentVariable('REVISION_SUFFIX') | ||
param environmentKeyVaultName = readEnvironmentVariable('AZURE_ENVIRONMENT_KEY_VAULT_NAME') | ||
param appConfigurationName = readEnvironmentVariable('AZURE_APP_CONFIGURATION_NAME') | ||
param containerAppEnvironmentName = readEnvironmentVariable('AZURE_CONTAINER_APP_ENVIRONMENT_NAME') | ||
param serviceBusNamespaceName = readEnvironmentVariable('AZURE_SERVICE_BUS_NAMESPACE_NAME') | ||
// secrets | ||
param appInsightConnectionString = readEnvironmentVariable('AZURE_APP_INSIGHTS_CONNECTION_STRING') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using './main.bicep' | ||
|
||
param environment = 'staging' | ||
param location = 'norwayeast' | ||
param imageTag = readEnvironmentVariable('IMAGE_TAG') | ||
param revisionSuffix = readEnvironmentVariable('REVISION_SUFFIX') | ||
param environmentKeyVaultName = readEnvironmentVariable('AZURE_ENVIRONMENT_KEY_VAULT_NAME') | ||
param appConfigurationName = readEnvironmentVariable('AZURE_APP_CONFIGURATION_NAME') | ||
param containerAppEnvironmentName = readEnvironmentVariable('AZURE_CONTAINER_APP_ENVIRONMENT_NAME') | ||
param serviceBusNamespaceName = readEnvironmentVariable('AZURE_SERVICE_BUS_NAMESPACE_NAME') | ||
|
||
// secrets | ||
param appInsightConnectionString = readEnvironmentVariable('AZURE_APP_INSIGHTS_CONNECTION_STRING') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using './main.bicep' | ||
|
||
param environment = 'test' | ||
param location = 'norwayeast' | ||
param imageTag = readEnvironmentVariable('IMAGE_TAG') | ||
param revisionSuffix = readEnvironmentVariable('REVISION_SUFFIX') | ||
param environmentKeyVaultName = readEnvironmentVariable('AZURE_ENVIRONMENT_KEY_VAULT_NAME') | ||
param appConfigurationName = readEnvironmentVariable('AZURE_APP_CONFIGURATION_NAME') | ||
param containerAppEnvironmentName = readEnvironmentVariable('AZURE_CONTAINER_APP_ENVIRONMENT_NAME') | ||
param serviceBusNamespaceName = readEnvironmentVariable('AZURE_SERVICE_BUS_NAMESPACE_NAME') | ||
|
||
// secrets | ||
param appInsightConnectionString = readEnvironmentVariable('AZURE_APP_INSIGHTS_CONNECTION_STRING') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
@description('The name of the Service Bus namespace') | ||
param serviceBusNamespaceName string | ||
|
||
@description('Array of principal IDs to assign the Azure Service Bus Data Owner role to') | ||
param principalIds array | ||
|
||
resource serviceBusNamespace 'Microsoft.ServiceBus/namespaces@2023-01-01-preview' existing = { | ||
name: serviceBusNamespaceName | ||
} | ||
|
||
@description('This is the built-in Azure Service Bus Data Owner role. See https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#azure-service-bus-data-owner') | ||
resource serviceBusDataOwnerRoleDefinition 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = { | ||
scope: subscription() | ||
name: '090c5cfd-751d-490a-894a-3ce6f1109419' | ||
} | ||
|
||
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = [ | ||
for principalId in principalIds: { | ||
scope: serviceBusNamespace | ||
name: guid(serviceBusNamespace.id, principalId, serviceBusDataOwnerRoleDefinition.id) | ||
properties: { | ||
roleDefinitionId: serviceBusDataOwnerRoleDefinition.id | ||
principalId: principalId | ||
principalType: 'ServicePrincipal' | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters