Skip to content

Commit

Permalink
chore(azure): add tags and param-descriptions on all resources (#942)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description

- Adds tags on all resources with Environment. Might look into adding
more tags like version etc eventually.
- Adds @description for all params in modules

<!--- Describe your changes in detail -->

## Related Issue(s)

- #{issue number}

## Verification

- [ ] **Your** code builds clean without any errors or warnings
- [ ] Manual testing done (required)
- [ ] Relevant automated test added (if you find this hard, leave it and
we'll help out)

## Documentation

- [ ] Documentation is updated (either in `docs`-directory, Altinnpedia
or a separate linked PR in
[altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if
applicable)

---------

Co-authored-by: Ole Jørgen Skogstad <skogstad@softis.net>
  • Loading branch information
arealmaas and oskogstad authored Jul 30, 2024
1 parent 9e0f436 commit 1834045
Show file tree
Hide file tree
Showing 23 changed files with 322 additions and 50 deletions.
14 changes: 14 additions & 0 deletions .azure/applications/graphql/main.bicep
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
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 IP address of the API Management instance')
@minLength(3)
param apimIp string

@description('The name of the container app environment')
@minLength(3)
@secure()
param containerAppEnvironmentName string

@description('The connection string for Application Insights')
@minLength(3)
@secure()
param appInsightConnectionString string

@description('The name of the App Configuration store')
@minLength(5)
@secure()
param appConfigurationName string

@description('The name of the Key Vault for the environment')
@minLength(3)
@secure()
param environmentKeyVaultName string
Expand Down
18 changes: 16 additions & 2 deletions .azure/applications/web-api-eu/main.bicep
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
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 IP address of the API Management instance')
@minLength(3)
param apimIp string

@description('The name of the container app environment')
@minLength(3)
@secure()
param containerAppEnvironmentName string

@description('The connection string for Application Insights')
@minLength(3)
@secure()
param appInsightConnectionString string

@description('The name of the App Configuration store')
@minLength(5)
@secure()
param appConfigurationName string

@description('The name of the Key Vault for the environment')
@minLength(3)
@secure()
param environmentKeyVaultName string
Expand Down Expand Up @@ -74,15 +88,15 @@ module keyVaultReaderAccessPolicy '../../modules/keyvault/addReaderRoles.bicep'
name: 'keyVaultReaderAccessPolicy-${containerAppName}'
params: {
keyvaultName: environmentKeyVaultResource.name
principalIds: [ containerApp.outputs.identityPrincipalId ]
principalIds: [containerApp.outputs.identityPrincipalId]
}
}

module appConfigReaderAccessPolicy '../../modules/appConfiguration/addReaderRoles.bicep' = {
name: 'appConfigReaderAccessPolicy-${containerAppName}'
params: {
appConfigurationName: appConfigurationName
principalIds: [ containerApp.outputs.identityPrincipalId ]
principalIds: [containerApp.outputs.identityPrincipalId]
}
}

Expand Down
8 changes: 8 additions & 0 deletions .azure/applications/web-api-migration-job/main.bicep
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
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 name of the container app environment')
@minLength(3)
@secure()
param containerAppEnvironmentName string

@description('The name of the Key Vault for the environment')
@minLength(3)
@secure()
param environmentKeyVaultName string
Expand Down
18 changes: 16 additions & 2 deletions .azure/applications/web-api-so/main.bicep
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
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 IP address of the API Management instance')
@minLength(3)
param apimIp string

@description('The name of the container app environment')
@minLength(3)
@secure()
param containerAppEnvironmentName string

@description('The connection string for Application Insights')
@minLength(3)
@secure()
param appInsightConnectionString string

@description('The name of the App Configuration store')
@minLength(5)
@secure()
param appConfigurationName string

@description('The name of the Key Vault for the environment')
@minLength(3)
@secure()
param environmentKeyVaultName string
Expand Down Expand Up @@ -78,15 +92,15 @@ module keyVaultReaderAccessPolicy '../../modules/keyvault/addReaderRoles.bicep'
name: 'keyVaultReaderAccessPolicy-${containerAppName}'
params: {
keyvaultName: environmentKeyVaultResource.name
principalIds: [ containerApp.outputs.identityPrincipalId ]
principalIds: [containerApp.outputs.identityPrincipalId]
}
}

module appConfigReaderAccessPolicy '../../modules/appConfiguration/addReaderRoles.bicep' = {
name: 'appConfigReaderAccessPolicy-${containerAppName}'
params: {
appConfigurationName: appConfigurationName
principalIds: [ containerApp.outputs.identityPrincipalId ]
principalIds: [containerApp.outputs.identityPrincipalId]
}
}

Expand Down
5 changes: 2 additions & 3 deletions .azure/functions/resourceName.bicep
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// This function generates a unique string based on the subscription ID and resource group ID
@description('This function generates a unique string based on the subscription ID and resource group ID')
@export()
func uniqueStringBySubscriptionAndResourceGroup() string => uniqueString('${subscription().id}${resourceGroup().id}')

// This function generates a unique resource name by appending a unique string to the given name, ensuring the total length does not exceed the specified limit.
// It also ensures that the name is always postfixed with the full length of the unique string, which is 13 characters plus a dash.
@description('This function generates a unique resource name by appending a unique string to the given name, ensuring the total length does not exceed the specified limit. It also ensures that the name is always postfixed with the full length of the unique string, which is 13 characters plus a dash.')
// Example:
// uniqueResourceName(name: 'my-resource', limit: 50) => 'my-resource-1234567890123'
// Example:
Expand Down
32 changes: 31 additions & 1 deletion .azure/infrastructure/main.bicep
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
targetScope = 'subscription'

@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('Array of all keys in the source Key Vault')
param keyVaultSourceKeys array

@description('Password for PostgreSQL admin')
@secure()
@minLength(3)
param dialogportenPgAdminPassword string

@description('Subscription ID for the source Key Vault')
@secure()
@minLength(3)
param sourceKeyVaultSubscriptionId string

@description('Resource group for the source Key Vault')
@secure()
@minLength(3)
param sourceKeyVaultResourceGroup string

@description('Name of the source Key Vault')
@secure()
@minLength(3)
param sourceKeyVaultName string
Expand Down Expand Up @@ -51,10 +63,15 @@ var secrets = {

var namePrefix = 'dp-be-${environment}'

var tags = {
Environment: environment
}

// Create resource groups
resource resourceGroup 'Microsoft.Resources/resourceGroups@2024-03-01' = {
name: '${namePrefix}-rg'
location: location
tags: tags
}

module environmentKeyVault '../modules/keyvault/create.bicep' = {
Expand All @@ -64,6 +81,7 @@ module environmentKeyVault '../modules/keyvault/create.bicep' = {
namePrefix: namePrefix
location: location
sku: keyVaultSku
tags: tags
}
}

Expand All @@ -74,6 +92,7 @@ module appConfiguration '../modules/appConfiguration/create.bicep' = {
namePrefix: namePrefix
location: location
sku: appConfigurationSku
tags: tags
}
}

Expand All @@ -84,6 +103,7 @@ module appInsights '../modules/applicationInsights/create.bicep' = {
namePrefix: namePrefix
location: location
sku: appInsightsSku
tags: tags
}
}

Expand All @@ -96,6 +116,7 @@ module serviceBus '../modules/serviceBus/main.bicep' = {
sku: serviceBusSku
subnetId: vnet.outputs.serviceBusSubnetId
vnetId: vnet.outputs.virtualNetworkId
tags: tags
}
}

Expand All @@ -105,6 +126,7 @@ module vnet '../modules/vnet/main.bicep' = {
params: {
namePrefix: namePrefix
location: location
tags: tags
}
}

Expand Down Expand Up @@ -135,13 +157,14 @@ module postgresql '../modules/postgreSql/create.bicep' = {
location: location
environmentKeyVaultName: environmentKeyVault.outputs.name
srcKeyVault: srcKeyVault
srcSecretName: 'dialogportenPgAdminPassword${environment}'
srcKeyVaultAdministratorLoginPasswordKey: 'dialogportenPgAdminPassword${environment}'
administratorLoginPassword: contains(keyVaultSourceKeys, 'dialogportenPgAdminPassword${environment}')
? srcKeyVaultResource.getSecret('dialogportenPgAdminPassword${environment}')
: secrets.dialogportenPgAdminPassword
sku: postgresSku
subnetId: vnet.outputs.postgresqlSubnetId
vnetId: vnet.outputs.virtualNetworkId
tags: tags
}
}

Expand All @@ -156,6 +179,7 @@ module redis '../modules/redis/main.bicep' = {
version: redisVersion
subnetId: vnet.outputs.redisSubnetId
vnetId: vnet.outputs.virtualNetworkId
tags: tags
}
}

Expand All @@ -170,6 +194,7 @@ module copyCrossEnvironmentSecrets '../modules/keyvault/copySecrets.bicep' = {
srcKeyVaultSubId: secrets.sourceKeyVaultSubscriptionId
destKeyVaultName: environmentKeyVault.outputs.name
secretPrefix: 'dialogporten--any--'
tags: tags
}
}

Expand All @@ -184,6 +209,7 @@ module copyEnvironmentSecrets '../modules/keyvault/copySecrets.bicep' = {
srcKeyVaultSubId: secrets.sourceKeyVaultSubscriptionId
destKeyVaultName: environmentKeyVault.outputs.name
secretPrefix: 'dialogporten--${environment}--'
tags: tags
}
}

Expand All @@ -196,6 +222,7 @@ module slackNotifier '../modules/functionApp/slackNotifier.bicep' = {
namePrefix: namePrefix
applicationInsightsName: appInsights.outputs.appInsightsName
sku: slackNotifierSku
tags: tags
}
}

Expand All @@ -207,6 +234,7 @@ module containerAppEnv '../modules/containerAppEnv/main.bicep' = {
location: location
appInsightWorkspaceName: appInsights.outputs.appInsightsWorkspaceName
subnetId: vnet.outputs.containerAppEnvironmentSubnetId
tags: tags
}
}

Expand All @@ -227,6 +255,7 @@ module postgresConnectionStringAppConfig '../modules/appConfiguration/upsertKeyV
key: 'Infrastructure:DialogDbConnectionString'
value: postgresql.outputs.adoConnectionStringSecretUri
keyValueType: 'keyVaultReference'
tags: tags
}
}

Expand All @@ -238,6 +267,7 @@ module redisConnectionStringAppConfig '../modules/appConfiguration/upsertKeyValu
key: 'Infrastructure:Redis:ConnectionString'
value: redis.outputs.connectionStringSecretUri
keyValueType: 'keyVaultReference'
tags: tags
}
}

Expand Down
9 changes: 9 additions & 0 deletions .azure/modules/appConfiguration/create.bicep
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { uniqueResourceName } from '../../functions/resourceName.bicep'

@description('The prefix used for naming resources to ensure unique names')
param namePrefix string

@description('The location where the resources will be deployed')
param location string

@description('Tags to apply to resources')
param tags object

@export()
type Sku = {
name: 'standard'
}

@description('The SKU of the App Configuration')
param sku Sku

var appConfigNameMaxLength = 63
Expand All @@ -26,6 +34,7 @@ resource appConfig 'Microsoft.AppConfiguration/configurationStores@2023-03-01' =
value: '1'
}
}
tags: tags
}

output endpoint string = appConfig.properties.endpoint
Expand Down
Loading

0 comments on commit 1834045

Please sign in to comment.