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

move IaC to broker repo #403

Merged
merged 28 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e09f8ee
move IaC to broker repo
Apr 24, 2024
3596483
remove example files
Apr 24, 2024
6afa000
Fix bug
Ceredron Apr 24, 2024
4c8192c
Container app job name can be max 32 characters long
Ceredron Apr 24, 2024
4a551ce
Also can get too long
Ceredron Apr 24, 2024
d59892e
Remove dead code
Ceredron Apr 24, 2024
2b24980
Consistent file name
Ceredron Apr 24, 2024
dd6eebb
Fix migration bicep
Ceredron Apr 26, 2024
0f5b7ba
Fixes after testing
Ceredron Apr 26, 2024
2fb2290
Shorter name
Ceredron Apr 26, 2024
88af7d2
Need to expose name from bicep for use in pipeline
Ceredron Apr 26, 2024
2040ef4
Use environment for azure cli
Ceredron Apr 26, 2024
82edbb5
Use app version env variable to find container job instead of name
Ceredron Apr 27, 2024
fa6c353
Fix
Ceredron Apr 27, 2024
02e064a
Select first in array
Ceredron Apr 27, 2024
816b076
Fix
Ceredron Apr 27, 2024
e09507f
There seems to be a delay after Postgres password has been updated du…
Ceredron Apr 27, 2024
abd0b88
Fix
Ceredron Apr 27, 2024
0d3e8a6
Failed to use keyvault in same deployment that creates it
Ceredron Apr 28, 2024
e74ca65
Generate password without characters that become troublesome in an ur…
Ceredron Apr 28, 2024
5740b94
We do not use source keys because we use Github secrets as our config…
Ceredron Apr 28, 2024
ee85ee4
Added logic for initial deploy
Ceredron Apr 28, 2024
143082a
This works
Ceredron Apr 28, 2024
53149b3
Required parameter is required
Ceredron Apr 28, 2024
e6cae16
Fixed pwd generator to not use chars not supported by postgres (and a…
Ceredron Apr 29, 2024
5fa55ee
activate action on push to main
Apr 29, 2024
e48f6bd
merge
Apr 29, 2024
5733aa5
Merge branch 'feat/infrastructure' of https://github.com/altinn/altin…
Apr 29, 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
104 changes: 104 additions & 0 deletions .azure/applications/api/main.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
targetScope = 'resourceGroup'

@minLength(3)
param imageTag string
@minLength(3)
param environment string
@minLength(3)
param location string
@minLength(3)
param platform_base_url string
@minLength(3)
param maskinporten_environment string
@secure()
@minLength(3)
param sourceKeyVaultName string
@secure()
param keyVaultUrl string

@secure()
param client_id string

@secure()
param tenant_id string
@secure()
param namePrefix string

var baseImageUrl = 'ghcr.io/altinn/altinn-broker'
var containerAppName = '${namePrefix}-app'

resource userAssignedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
name: '${namePrefix}-app-identity'
location: location
}

module keyVaultReaderAccessPolicyUserIdentity '../../modules/keyvault/addReaderRoles.bicep' = {
name: 'kvreader-${namePrefix}-app'
params: {
keyvaultName: sourceKeyVaultName
tenantId: userAssignedIdentity.properties.tenantId
principalIds: [userAssignedIdentity.properties.principalId]
}
}

module databaseAccess '../../modules/postgreSql/AddAdministrationAccess.bicep' = {
name: 'databaseAccess'
dependsOn: [
keyVaultReaderAccessPolicyUserIdentity // Timing issue
]
params: {
tenantId: userAssignedIdentity.properties.tenantId
principalId: userAssignedIdentity.properties.principalId
appName: userAssignedIdentity.name
namePrefix: namePrefix
}
}

resource keyvault 'Microsoft.KeyVault/vaults@2023-07-01' existing = {
name: sourceKeyVaultName
}

module containerApp '../../modules/containerApp/main.bicep' = {
name: containerAppName
dependsOn: [keyVaultReaderAccessPolicyUserIdentity, databaseAccess]
params: {
namePrefix: namePrefix
image: '${baseImageUrl}:${imageTag}'
location: location
environment: environment
client_id: client_id
tenant_id: tenant_id
subscription_id: subscription().subscriptionId
principal_id: userAssignedIdentity.id
platform_base_url: platform_base_url
keyVaultUrl: keyVaultUrl
maskinporten_environment: maskinporten_environment
malwarescan_event_grid_topic_name: eventgrid_topic.name
userIdentityTenantId: userAssignedIdentity.properties.tenantId
userIdentityClientId: userAssignedIdentity.properties.clientId
userIdentityPrincipalId: userAssignedIdentity.properties.principalId
containerAppEnvId: keyvault.getSecret('container-app-env-id')
}
}

resource eventgrid_topic 'Microsoft.EventGrid/topics@2022-06-15' = {
name: '${namePrefix}-malware-scan-event-topic'
location: location
}

resource eventgrid_event_subscription 'Microsoft.EventGrid/topics/eventSubscriptions@2022-06-15' = {
name: '${namePrefix}-malware-scan-event-subscription'
parent: eventgrid_topic
dependsOn: [containerApp]
properties: {
destination: {
endpointType: 'WebHook'
properties: {
endpointUrl: 'https://${containerApp.outputs.app.properties.configuration.ingress.fqdn}/broker/api/v1/webhooks/malwarescanresults'
}
}
}
}

output name string = containerApp.outputs.name
output revisionName string = containerApp.outputs.revisionName
13 changes: 13 additions & 0 deletions .azure/applications/api/params.bicepparam
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using './main.bicep'

param namePrefix = readEnvironmentVariable('NAME_PREFIX')
param location = 'norwayeast'
param imageTag = readEnvironmentVariable('IMAGE_TAG')
param platform_base_url = 'https://platform.tt02.altinn.no/'
param maskinporten_environment = 'ver2'
param environment = readEnvironmentVariable('ENVIRONMENT')
// secrets
param sourceKeyVaultName = readEnvironmentVariable('KEY_VAULT_NAME')
param keyVaultUrl = readEnvironmentVariable('KEY_VAULT_URL')
param client_id = readEnvironmentVariable('CLIENT_ID')
param tenant_id = readEnvironmentVariable('TENANT_ID')
96 changes: 96 additions & 0 deletions .azure/applications/migration/main.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
param namePrefix string
param location string
param appVersion string

@secure()
param keyVaultUrl string

@secure()
param keyVaultName string

var containerAppJobName = '${namePrefix}-migration'
var containerAppEnvName = '${namePrefix}-env'
var migrationConnectionStringName = 'broker-migration-connection-string'

resource userAssignedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
name: '${namePrefix}-migration-identity'
location: location
}

module addKeyvaultRead '../../modules/keyvault/addReaderRoles.bicep' = {
name: 'kvreader-${namePrefix}-migration'
params: {
keyvaultName: keyVaultName
tenantId: userAssignedIdentity.properties.tenantId
principalIds: [userAssignedIdentity.properties.principalId]
}
}

var secrets = [
{
name: migrationConnectionStringName
keyVaultUrl: '${keyVaultUrl}/secrets/${migrationConnectionStringName}'
identity: userAssignedIdentity.id
}
]

var containerAppEnvVars = [
{
name: 'FLYWAY_URL'
secretRef: migrationConnectionStringName
}
{
name: 'FLYWAY_CONNECT_RETRIES'
value: '3'
}
{
name: 'FLYWAY_VALIDATE_MIGRATION_NAMING'
value: 'true'
}
{
name: 'APP_VERSION'
value: appVersion
}
]

var volumes = [
{
name: 'migrations'
storageName: 'migrations'
storageType: 'AzureFile'
mountOptions: 'cache=none'
}
]

var volumeMounts = [
{
volumeName: 'migrations'
mountPath: '/flyway/sql'
subPath: ''
}
]

resource containerAppEnv 'Microsoft.App/managedEnvironments@2023-11-02-preview' existing = {
name: containerAppEnvName
}

module containerAppJob '../../modules/containerAppJob/main.bicep' = {
name: containerAppJobName
dependsOn: [
addKeyvaultRead
]
params: {
name: containerAppJobName
location: location
containerAppEnvId: containerAppEnv.id
environmentVariables: containerAppEnvVars
secrets: secrets
command: ['/bin/bash', '-c', 'flyway migrate;']
image: 'flyway/flyway:latest'
volumes: volumes
volumeMounts: volumeMounts
principalId: userAssignedIdentity.id
}
}

output name string = containerAppJob.name
7 changes: 7 additions & 0 deletions .azure/applications/migration/params.bicepparam
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using './main.bicep'

param location = 'norwayeast'
param keyVaultName = readEnvironmentVariable('KEY_VAULT_NAME')
param keyVaultUrl = readEnvironmentVariable('KEY_VAULT_URL')
param namePrefix = readEnvironmentVariable('NAME_PREFIX')
param appVersion = readEnvironmentVariable('APP_VERSION')
32 changes: 32 additions & 0 deletions .azure/bicepconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
// See https://aka.ms/bicep/config for more information on Bicep configuration options
// Press CTRL+SPACE/CMD+SPACE at any location to see Intellisense suggestions
"analyzers": {
"core": {
"rules": {
"no-unused-params": {
"level": "warning"
},
"no-unused-vars": {
"level": "warning"
},
"no-hardcoded-env-urls": {
"level": "warning"
},
"secure-secrets-in-params": {
"level": "warning"
},
"no-unnecessary-dependson": {
"level": "warning"
},
"outputs-should-not-contain-secrets": {
"level": "warning"
}
}
}
},
"experimentalFeaturesEnabled": {
"compileTimeImports": true,
"userDefinedFunctions": false
}
}
Loading