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

leverage ServiceConnector to setup connection to keyvault and DB #1

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yungezz
Copy link

@yungezz yungezz commented Feb 1, 2023

leverage ServiceConnector to setup connections to keyvault and DB

@yungezz yungezz marked this pull request as draft February 1, 2023 08:59
@@ -33,6 +33,13 @@ param numberOfWorkers int = -1
param scmDoBuildDuringDeployment bool = false
param use32BitWorkerProcess bool = false

// Target DB properties
param connectionStringKey string = 'AZURE-SQL-CONNECTION-STRING'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We wouldn't update /core/host/appservice to use SQL because the app service itself can be used with any DB and it shouldn't default to anything.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update default to empty

Comment on lines +39 to +42
param appUser string = ''
@secure()
param appUserPassword string = ''

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need appUser for app service?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when setting up connection between the app service and target db, user need to provide target db's connection info including appUser, appPassword.

Comment on lines +118 to +122
configurationInfo: {
customizedKeys: {
'AZURE_KEYVAULT_RESOURCEENDPOINT': 'AZURE_KEY_VAULT_ENDPOINT'
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How set are you on using that key? Ideally azd and service connector use the same so we don't have to overide by default.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

azd's default is AZURE_KEY_VAULT_ENDPOINT, service connector default is AZURE_KEYVAULT_RESOURCEENDPOINT, so here is to follow azd default

Comment on lines +129 to +155
resource connectionToTargetDB 'Microsoft.ServiceLinker/linkers@2022-11-01-preview' = if (!empty(targetResourceId)) {
name: 'conn_db'
scope: appService
properties: {
targetService: {
id: targetResourceId
type: 'AzureResource'
}
secretStore: {
keyVaultId: !empty(keyVaultName) ? keyVault.id : ''
keyVaultSecretName: !empty(keyVaultName) ? connectionStringKey : ''
}
authInfo: {
authType: 'secret'
name: appUser
secretInfo: {
secretType: 'rawValue'
value: appUserPassword
}
}
clientType: 'dotnet'
}
dependsOn: [
connectionToKeyVault
]
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (being in appservice) means that app service can only be linked to one db. I think we need to consider a scenario where all of this is abstracted and included in main.bicep as a module with very few inputs.

params: {
keyVaultName: keyVault.outputs.name
principalId: api.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID
targetResourceId: '${sqlServer.outputs.id}/databases/${sqlServer.outputs.databaseName}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add this string as an output of db.bicep

Comment on lines +36 to +37
appUser: appUser
appUserPassword: appUserPassword
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does appservice need to know about appUser? We don't want to couple the two at the appservice level.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appservice doesn't know appUser, it's a param passed in from main, user knows their app, and their db's username/password.

@@ -25,6 +32,10 @@ module api '../core/host/appservice.bicep' = {
runtimeName: 'dotnetcore'
runtimeVersion: '6.0'
scmDoBuildDuringDeployment: false
targetResourceId: targetResourceId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, targetResourceId name isn't enough to know what it is or used for.

Comment on lines +137 to +140
secretStore: {
keyVaultId: !empty(keyVaultName) ? keyVault.id : ''
keyVaultSecretName: !empty(keyVaultName) ? connectionStringKey : ''
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to not created the resource if the keyVult isn't passed in?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, no need to create keyvault conn is keyvault is empty

resource connectionToKeyVault 'Microsoft.ServiceLinker/linkers@2022-11-01-preview' =  if(!empty(keyVaultName)) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants