Skip to content

Commit

Permalink
fix: deployment issues (fixes #161) (#195)
Browse files Browse the repository at this point in the history
* fix: deployment error (fixes #161)

* fix: add missing managed identities

* fix: missing client id for user assigned identity

* chore: revert unwanted change
  • Loading branch information
sinedied committed Mar 22, 2024
1 parent bbfbd46 commit 6efe240
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
11 changes: 11 additions & 0 deletions infra/core/security/managed-identity.bicep
@@ -0,0 +1,11 @@
param name string
param location string = resourceGroup().location

resource apiIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
name: name
location: location
}

output tenantId string = apiIdentity.properties.tenantId
output principalId string = apiIdentity.properties.principalId
output clientId string = apiIdentity.properties.clientId
46 changes: 40 additions & 6 deletions infra/main.bicep
Expand Up @@ -83,6 +83,9 @@ var resourceToken = toLower(uniqueString(subscription().id, environmentName, loc
var tags = union({ 'azd-env-name': environmentName }, empty(aliasTag) ? {} : { alias: aliasTag })
var allowedOrigins = empty(allowedOrigin) ? [webApp.outputs.uri] : [webApp.outputs.uri, allowedOrigin]

var indexerApiIdentityName = '${abbrs.managedIdentityUserAssignedIdentities}indexer-api-${resourceToken}'
var searchApiIdentityName = '${abbrs.managedIdentityUserAssignedIdentities}search-api-${resourceToken}'

// Organize resources in a resource group
resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = {
name: !empty(resourceGroupName) ? resourceGroupName : '${abbrs.resourcesResourceGroups}${environmentName}'
Expand Down Expand Up @@ -142,6 +145,16 @@ module webApp './core/host/staticwebapp.bicep' = {
}
}

// search API identity
module searchApiIdentity 'core/security/managed-identity.bicep' = {
name: 'search-api-identity'
scope: resourceGroup
params: {
name: searchApiIdentityName
location: location
}
}

// The search API
module searchApi './core/host/container-app.bicep' = {
name: 'search-api'
Expand All @@ -152,7 +165,7 @@ module searchApi './core/host/container-app.bicep' = {
tags: union(tags, { 'azd-service-name': searchApiName })
containerAppsEnvironmentName: containerApps.outputs.environmentName
containerRegistryName: containerApps.outputs.registryName
identityType: 'SystemAssigned'
identityName: searchApiIdentityName
allowedOrigins: allowedOrigins
containerCpuCoreCount: '1.0'
containerMemory: '2.0Gi'
Expand Down Expand Up @@ -200,15 +213,29 @@ module searchApi './core/host/container-app.bicep' = {
value: storageContainerName
}
{
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
secretRef: 'appinsights-cs'
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
secretRef: 'appinsights-cs'
}
{
name: 'AZURE_CLIENT_ID'
value: searchApiIdentity.outputs.clientId
}
]
imageName: !empty(searchApiImageName) ? searchApiImageName : 'nginx:latest'
targetPort: 3000
}
}

// Indexer API identity
module indexerApiIdentity 'core/security/managed-identity.bicep' = {
name: 'indexer-api-identity'
scope: resourceGroup
params: {
name: indexerApiIdentityName
location: location
}
}

// The indexer API
module indexerApi './core/host/container-app.bicep' = {
name: 'indexer-api'
Expand All @@ -219,7 +246,7 @@ module indexerApi './core/host/container-app.bicep' = {
tags: union(tags, { 'azd-service-name': indexerApiName })
containerAppsEnvironmentName: containerApps.outputs.environmentName
containerRegistryName: containerApps.outputs.registryName
identityType: 'SystemAssigned'
identityName: indexerApiIdentityName
containerCpuCoreCount: '1.0'
containerMemory: '2.0Gi'
secrets: [
Expand Down Expand Up @@ -266,8 +293,12 @@ module indexerApi './core/host/container-app.bicep' = {
value: storageContainerName
}
{
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
secretRef: 'appinsights-cs'
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
secretRef: 'appinsights-cs'
}
{
name: 'AZURE_CLIENT_ID'
value: indexerApiIdentity.outputs.clientId
}
]
imageName: !empty(indexerApiImageName) ? indexerApiImageName : 'nginx:latest'
Expand Down Expand Up @@ -505,3 +536,6 @@ output INDEXER_API_URI string = indexerApi.outputs.uri

output ALLOWED_ORIGINS string = join(allowedOrigins, ',')
output BACKEND_URI string = !empty(backendUri) ? backendUri : searchApi.outputs.uri

output INDEXER_PRINCIPAL_ID string = indexerApi.outputs.identityPrincipalId
output SEARCH_API_PRINCIPAL_ID string = searchApi.outputs.identityPrincipalId

0 comments on commit 6efe240

Please sign in to comment.