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

fix: deployment issues (fixes #161) #195

Merged
merged 4 commits into from Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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