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

ci: refactor deployment of infrastructure and add PR validation #346

Merged
merged 46 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d15ee51
ci: refactor pull request workflow
arealmaas Jan 9, 2024
c29af3f
cleanup
arealmaas Jan 9, 2024
ba3c339
ci: refactor build test and publish
arealmaas Jan 9, 2024
b22bde8
cleanup
arealmaas Jan 9, 2024
77f839a
refactor
arealmaas Jan 10, 2024
ed8ef33
refactor to pass secrets and inputs
arealmaas Jan 10, 2024
56e9f77
cleanup
arealmaas Jan 10, 2024
8685323
cleanup
arealmaas Jan 10, 2024
b12eabd
cleanup
arealmaas Jan 10, 2024
cd2cf9e
cleanup
arealmaas Jan 10, 2024
7657b44
Merge branch 'ci/refactor-pull-request-wf' into ci/refactor-build-tes…
arealmaas Jan 10, 2024
b7a2da7
cleanup
arealmaas Jan 10, 2024
60d7a83
cleanup
arealmaas Jan 10, 2024
fdd5438
ci: build bicep files on pull requests
arealmaas Jan 10, 2024
1de2795
Merge branch 'main' into ci/verify-env-in-pull-requests
arealmaas Jan 10, 2024
f7a8310
cleanup
arealmaas Jan 10, 2024
9075409
cleanup
arealmaas Jan 10, 2024
01967f9
wip
arealmaas Jan 10, 2024
53a69b2
ci: add filter
arealmaas Jan 10, 2024
f69b855
cleanup
arealmaas Jan 11, 2024
2664c03
cleanup
arealmaas Jan 11, 2024
a4bd300
cleanup
arealmaas Jan 11, 2024
81a3599
cleanup
arealmaas Jan 11, 2024
0a071ba
cleanup
arealmaas Jan 11, 2024
f954113
cleanup
arealmaas Jan 11, 2024
bad685e
cleanup
arealmaas Jan 11, 2024
357e6c5
wip
arealmaas Jan 15, 2024
98b3a56
refactor
arealmaas Jan 15, 2024
0799792
Merge branch 'main' into ci/validate-azure-deployment
arealmaas Jan 15, 2024
367f5e7
fix path to generatepassword
arealmaas Jan 16, 2024
6da4b5a
Merge branch 'main' into ci/validate-azure-deployment
arealmaas Jan 16, 2024
be58490
cleanup
arealmaas Jan 16, 2024
a384bf5
cleanup
arealmaas Jan 16, 2024
5ceff5e
cleanup
arealmaas Jan 16, 2024
b2fabba
cleanup
arealmaas Jan 16, 2024
b98f2a4
cleanup
arealmaas Jan 16, 2024
274ad2f
cleanup
arealmaas Jan 16, 2024
ed56cac
Merge branch 'main' into ci/validate-azure-deployment
arealmaas Jan 16, 2024
da79ee9
Update addBackends.bicep
arealmaas Jan 17, 2024
1f89e8e
cleanup
arealmaas Jan 17, 2024
c568d27
cleanup
arealmaas Jan 17, 2024
c3f0169
Merge branch 'main' into ci/validate-azure-deployment
arealmaas Jan 17, 2024
980afdf
cleanup
arealmaas Jan 17, 2024
33b3639
cleanup
arealmaas Jan 17, 2024
a51b855
cleanup
arealmaas Jan 17, 2024
6516db7
cleanup
arealmaas Jan 17, 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
12 changes: 12 additions & 0 deletions .azure/.test.bicepparam
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using 'main.bicep'

param environment = 'test'
param location = 'norwayeast'
param keyVaultSourceKeys = json(readEnvironmentVariable('KEYVAULT_SOURCE_KEYS', '[]'))
param gitSha = readEnvironmentVariable('GIT_SHA', '')

param dialogportenPgAdminPassword = readEnvironmentVariable('PG_ADMIN_PASSWORD', '')
param apiManagementDigDirEmail = readEnvironmentVariable('APIM_DIGDIR_EMAIL', '')
param sourceKeyVaultSubscriptionId = readEnvironmentVariable('SOURCE_KEYVAULT_SUBSCRIPTION_ID', '')
param sourceKeyVaultResourceGroup = readEnvironmentVariable('SOURCE_KEYVAULT_RESOURCE_GROUP', '')
param sourceKeyVaultName = readEnvironmentVariable('SOURCE_KEYVAULT_NAME', '')
18 changes: 9 additions & 9 deletions .azure/apim/addBackends.bicep
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
param apiManagementName string
param apiManagementName string
param containerAppEnvName string
param webApiSoName string
param webApiEuName string
Expand All @@ -19,7 +19,7 @@ resource webApiEu 'Microsoft.App/containerApps@2023-05-01' existing = {
name: webApiEuName
}

var managementBaseUrl = 'https://management.azure.com'
var managementBaseUrl = environment().resourceManager

var webApiSoFqdn = 'https://${webApiSoName}.${containerAppEnv.properties.defaultDomain}'
resource serviceownerBackend 'Microsoft.ApiManagement/service/backends@2022-08-01' = {
Expand Down Expand Up @@ -65,14 +65,14 @@ resource apimPolicy 'Microsoft.ApiManagement/service/policies@2023-03-01-preview
<inbound>
<choose>
<when condition="@(context.Request.Url.Path != null &amp;&amp; Regex.IsMatch(context.Request.Url.Path, @&quot;^api/[^/]+/enduser/&quot;) || context.Request.Url.Path.StartsWith(&quot;swagger&quot;))">
''',
'<set-backend-service backend-id="${enduserBackend.name}" />',
'''
''',
'<set-backend-service backend-id="${enduserBackend.name}" />',
'''
</when>
<when condition="@(context.Request.Url.Path != null &amp;&amp; Regex.IsMatch(context.Request.Url.Path, @&quot;^api/[^/]+/serviceowner/&quot;))">
''',
'<set-backend-service backend-id="${serviceownerBackend.name}" />',
'''
''',
'<set-backend-service backend-id="${serviceownerBackend.name}" />',
'''
</when>
<otherwise>
<return-response>
Expand Down Expand Up @@ -111,7 +111,7 @@ resource defaultApi 'Microsoft.ApiManagement/service/apis@2023-03-01-preview' =
path: ''
}

resource operations 'operations' = [for operation in ['DELETE', 'GET', 'POST', 'PUT', 'PATCH', 'OPTIONS', 'HEAD', 'TRACE'] : {
resource operations 'operations' = [for operation in [ 'DELETE', 'GET', 'POST', 'PUT', 'PATCH', 'OPTIONS', 'HEAD', 'TRACE' ]: {
name: toLower(operation)
properties: {
displayName: operation
Expand Down
13 changes: 13 additions & 0 deletions .azure/apim/create.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ resource apim 'Microsoft.ApiManagement/service@2023-03-01-preview' = {
publisherEmail: publisherEmail
publisherName: 'Digitaliseringsdirektoratet'
developerPortalStatus: 'Disabled'
legacyPortalStatus: 'Enabled'
publicNetworkAccess: 'Enabled'
natGatewayState: 'Disabled'
customProperties: {
'Microsoft.WindowsAzure.ApiManagement.Gateway.Protocols.Server.Http2': 'False'
'Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Ssl30': 'False'
'Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10': 'False'
'Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11': 'False'
'Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TripleDes168': 'False'
'Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Ssl30': 'False'
'Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10': 'False'
'Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11': 'False'
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions .azure/applicationInsights/create.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ param location string
resource appInsightsWorkspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' = {
name: '${namePrefix}-insightsWorkspace'
location: location
properties: {
retentionInDays: 30
sku: {
name: 'PerGB2018'
}
workspaceCapping: {
dailyQuotaGb: -1
}
}
}

resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
Expand All @@ -13,6 +22,8 @@ resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
properties: {
Application_Type: 'web'
WorkspaceResourceId: appInsightsWorkspace.id
Flow_Type: 'Bluefield'
Request_Source: 'rest'
}
}

Expand Down
86 changes: 0 additions & 86 deletions .azure/deployBicep.ps1

This file was deleted.

5 changes: 3 additions & 2 deletions .azure/functionApp/slackNotifier.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module updateAppSettings 'appSettings.bicep' = {
}

var defaultFunctionKey = listkeys('${functionApp.id}/host/default', '2023-01-01').functionKeys.default

var forwardAlertToSlackTriggerUrl = 'https://${functionApp.properties.defaultHostName}/api/forwardalerttoslack?code=${defaultFunctionKey}'
resource notifyDevTeam 'Microsoft.Insights/actionGroups@2023-01-01' = {
name: '${namePrefix}-notify-devteam-ag'
location: 'Global'
Expand All @@ -83,7 +83,7 @@ resource notifyDevTeam 'Microsoft.Insights/actionGroups@2023-01-01' = {
name: functionApp.properties.defaultHostName
functionName: 'ForwardAlertToSlack'
functionAppResourceId: functionApp.id
httpTriggerUrl: 'https://${functionApp.properties.defaultHostName}/api/forwardalerttoslack?code=${defaultFunctionKey}'
httpTriggerUrl: forwardAlertToSlackTriggerUrl
useCommonAlertSchema: true
}
]
Expand All @@ -94,6 +94,7 @@ resource exceptionOccuredAlertRule 'Microsoft.Insights/scheduledQueryRules@2023-
name: '${namePrefix}-exception-occured-sqr'
location: location
properties: {
enabled: true
severity: 1
evaluationFrequency: 'PT5M'
windowSize: 'PT5M'
Expand Down
26 changes: 21 additions & 5 deletions .azure/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,27 @@ targetScope = 'subscription'
@minLength(3)
param environment string
param location string
param keyVault object
param keyVaultSourceKeys array
param gitSha string

@secure()
param secrets object
param dialogportenPgAdminPassword string
@secure()
param apiManagementDigDirEmail string
@secure()
param sourceKeyVaultSubscriptionId string
@secure()
param sourceKeyVaultResourceGroup string
@secure()
param sourceKeyVaultName string

var secrets = {
dialogportenPgAdminPassword: dialogportenPgAdminPassword
apiManagementDigDirEmail: apiManagementDigDirEmail
sourceKeyVaultSubscriptionId: sourceKeyVaultSubscriptionId
sourceKeyVaultResourceGroup: sourceKeyVaultResourceGroup
sourceKeyVaultName: sourceKeyVaultName
}

var namePrefix = 'dp-be-${environment}'
var baseImageUrl = 'ghcr.io/digdir/dialogporten-'
Expand Down Expand Up @@ -82,15 +98,15 @@ module postgresql 'postgreSql/create.bicep' = {
keyVaultName: keyVaultModule.outputs.name
srcKeyVault: srcKeyVault
srcSecretName: 'dialogportenPgAdminPassword${environment}'
administratorLoginPassword: contains(keyVault.source.keys, 'dialogportenPgAdminPassword${environment}') ? srcKeyVaultResource.getSecret('dialogportenPgAdminPassword${environment}') : secrets.dialogportenPgAdminPassword
administratorLoginPassword: contains(keyVaultSourceKeys, 'dialogportenPgAdminPassword${environment}') ? srcKeyVaultResource.getSecret('dialogportenPgAdminPassword${environment}') : secrets.dialogportenPgAdminPassword
}
}

module copyEnvironmentSecrets 'keyvault/copySecrets.bicep' = {
scope: resourceGroup
name: 'copyEnvironmentSecrets'
params: {
srcKeyVaultKeys: keyVault.source.keys
srcKeyVaultKeys: keyVaultSourceKeys
srcKeyVaultName: secrets.sourceKeyVaultName
srcKeyVaultRGNName: secrets.sourceKeyVaultResourceGroup
srcKeyVaultSubId: secrets.sourceKeyVaultSubscriptionId
Expand All @@ -102,7 +118,7 @@ module copyEnvironmentSecrets 'keyvault/copySecrets.bicep' = {
module copyCrossEnvironmentSecrets 'keyvault/copySecrets.bicep' = {
scope: resourceGroup
name: 'copyCrossEnvironmentSecrets'
params: { srcKeyVaultKeys: keyVault.source.keys
params: { srcKeyVaultKeys: keyVaultSourceKeys
srcKeyVaultName: secrets.sourceKeyVaultName
srcKeyVaultRGNName: secrets.sourceKeyVaultResourceGroup
srcKeyVaultSubId: secrets.sourceKeyVaultSubscriptionId
Expand Down
9 changes: 0 additions & 9 deletions .azure/main.parameters.json

This file was deleted.

81 changes: 46 additions & 35 deletions .azure/postgreSql/create.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,55 @@ var databaseName = 'dialogporten'
//}

module saveAdmPassword '../keyvault/upsertSecret.bicep' = {
name: 'Save_${srcSecretName}'
scope: resourceGroup(srcKeyVault.subscriptionId, srcKeyVault.resourceGroupName)
params: {
destKeyVaultName: srcKeyVault.name
secretName: srcSecretName
secretValue: administratorLoginPassword
}
name: 'Save_${srcSecretName}'
scope: resourceGroup(srcKeyVault.subscriptionId, srcKeyVault.resourceGroupName)
params: {
destKeyVaultName: srcKeyVault.name
secretName: srcSecretName
secretValue: administratorLoginPassword
}
}

resource postgres 'Microsoft.DBforPostgreSQL/flexibleServers@2022-12-01' = {
name: '${namePrefix}-postgres'
location: location
properties: {
version: '15'
administratorLogin: administratorLogin
administratorLoginPassword: administratorLoginPassword
storage: { storageSizeGB: 32 }
}
sku: {
name: 'Standard_B1ms'
tier: 'Burstable'
}
resource database 'databases' = {
name: databaseName
}
resource allowAzureAccess 'firewallRules' = {
name: 'AllowAccessFromAzure'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '0.0.0.0'
}
}
//resource configurations 'configurations' = [for config in items(postgresqlConfiguration): {
// name: config.key
// properties: {
// value: config.value
// }
//}]
name: '${namePrefix}-postgres'
location: location
properties: {
version: '15'
administratorLogin: administratorLogin
administratorLoginPassword: administratorLoginPassword
storage: { storageSizeGB: 32 }
authConfig: {
activeDirectoryAuth: 'Disabled'
}
dataEncryption: {
type: 'SystemManaged'
}
replicationRole: 'Primary'
}
sku: {
name: 'Standard_B1ms'
tier: 'Burstable'
}
resource database 'databases' = {
name: databaseName
properties: {
charset: 'UTF8'
collation: 'en_US.utf8'
}
}
resource allowAzureAccess 'firewallRules' = {
name: 'AllowAccessFromAzure'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '0.0.0.0'
}
}
//resource configurations 'configurations' = [for config in items(postgresqlConfiguration): {
// name: config.key
// properties: {
// value: config.value
// }
//}]
}

module adoConnectionString '../keyvault/upsertSecret.bicep' = {
Expand Down
14 changes: 0 additions & 14 deletions .azure/powershell/fetchKeyvaultSecret.ps1

This file was deleted.

Loading