Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
added CMS Identity to KV and CMS CA
Browse files Browse the repository at this point in the history
  • Loading branch information
Physer committed Dec 13, 2024
1 parent 6fe7507 commit b2ef5e9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
21 changes: 21 additions & 0 deletions infrastructure/cms.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,31 @@ resource resourceGroup 'Microsoft.Resources/resourceGroups@2024-07-01' = {
location: deployment().location
}

module cmsIdentity 'modules/identity.bicep' = {
scope: resourceGroup
name: 'deployCmsIdentity'
params: {
identityName: 'id-cms'
}
}

module keyVault 'modules/keyVault.bicep' = {
scope: resourceGroup
name: 'deployCmsKeyVault'
params: {
keyVaultName: 'kv-cms'
accessPolicies: [
{
objectId: cmsIdentity.outputs.cmsIdentityPrincipalId
permissions: {
secrets: [
'list'
'get'
]
}
tenantId: cmsIdentity.outputs.cmsIdentityTenantId
}
]
}
}

Expand All @@ -38,6 +58,7 @@ module cmsContainerApp 'modules/containerApp.bicep' = {
logAnalyicsWorkspaceName: logAnalyticsWorkspace.outputs.resourceName
keyVaultName: keyVault.outputs.resourceName
targetPort: 1337
cmsIdentityPrincipalId: cmsIdentity.outputs.cmsIdentityPrincipalId
environmentVariables: [
{
name: 'DATABASE_CLIENT'
Expand Down
2 changes: 2 additions & 0 deletions infrastructure/modules/containerApp.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ param targetPort int = 80
param environmentVariables array
param secrets array
param keyVaultName string
param cmsIdentityPrincipalId string

var location = resourceGroup().location

Expand Down Expand Up @@ -66,6 +67,7 @@ resource containerApp 'Microsoft.App/containerApps@2024-08-02-preview' = {
for secret in secrets: {
name: secret.name
keyVaultUrl: '${keyVault.properties.vaultUri}secrets/${replaceUnderscoresWithDashes(secret.name)}'
identity: cmsIdentityPrincipalId
}
]
}
Expand Down
11 changes: 11 additions & 0 deletions infrastructure/modules/identity.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { appendHash } from '../utilities.bicep'

param identityName string

resource cmsIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-07-31-preview' = {
name: appendHash(identityName)
location: resourceGroup().location
}

output cmsIdentityPrincipalId string = cmsIdentity.properties.principalId
output cmsIdentityTenantId string = cmsIdentity.properties.tenantId
3 changes: 2 additions & 1 deletion infrastructure/modules/keyVault.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { appendHash } from '../utilities.bicep'

param keyVaultName string
param sku string = 'standard'
param accessPolicies array = []

resource keyVault 'Microsoft.KeyVault/vaults@2024-04-01-preview' = {
name: appendHash(keyVaultName)
Expand All @@ -12,7 +13,7 @@ resource keyVault 'Microsoft.KeyVault/vaults@2024-04-01-preview' = {
family: 'A'
}
tenantId: subscription().tenantId
accessPolicies: []
accessPolicies: accessPolicies
}
}

Expand Down

0 comments on commit b2ef5e9

Please sign in to comment.