Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 43 additions & 24 deletions cli/azd/internal/repository/infra_confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,42 +348,61 @@ azureDepPrompt:
}
}

authType := scaffold.AuthType(0)
switch azureDep.(type) {
switch dependency := azureDep.(type) {
case appdetect.AzureDepServiceBus:
_authType, err := i.console.Prompt(ctx, input.ConsoleOptions{
Message: fmt.Sprintf("Input the authentication type you want for (%s), "+
"1 for connection string, 2 for managed identity", azureDep.ResourceDisplay()),
Help: "Authentication type:\n\n" +
"Enter 1 if you want to use connection string to connect to the Service Bus.\n" +
"Enter 2 if you want to use user assigned managed identity to connect to the Service Bus.",
})
authType, err := i.chooseAuthType(ctx, azureDepName)
if err != nil {
return err
}

if _authType != "1" && _authType != "2" {
i.console.Message(ctx, "Invalid authentication type. Please enter 0 or 1.")
continue azureDepPrompt
}
if _authType == "1" {
authType = scaffold.AuthType_PASSWORD
} else {
authType = scaffold.AuthType_TOKEN_CREDENTIAL
}
}

switch dependency := azureDep.(type) {
case appdetect.AzureDepServiceBus:
spec.AzureServiceBus = &scaffold.AzureDepServiceBus{
Name: azureDepName,
Queues: dependency.Queues,
AuthUsingConnectionString: authType == scaffold.AuthType_PASSWORD,
AuthUsingManagedIdentity: authType == scaffold.AuthType_TOKEN_CREDENTIAL,
}
break azureDepPrompt
case appdetect.AzureDepEventHubs:
authType, err := i.chooseAuthType(ctx, azureDepName)
if err != nil {
return err
}
spec.AzureEventHubs = &scaffold.AzureDepEventHubs{
Name: azureDepName,
EventHubNames: dependency.Names,
AuthUsingConnectionString: authType == scaffold.AuthType_PASSWORD,
AuthUsingManagedIdentity: authType == scaffold.AuthType_TOKEN_CREDENTIAL,
}
case appdetect.AzureDepStorageAccount:
authType, err := i.chooseAuthType(ctx, azureDepName)
if err != nil {
return err
}
spec.AzureStorageAccount = &scaffold.AzureDepStorageAccount{
Name: azureDepName,
ContainerNames: dependency.ContainerNames,
AuthUsingConnectionString: authType == scaffold.AuthType_PASSWORD,
AuthUsingManagedIdentity: authType == scaffold.AuthType_TOKEN_CREDENTIAL,
}
}
break azureDepPrompt
}
return nil
}

func (i *Initializer) chooseAuthType(ctx context.Context, serviceName string) (scaffold.AuthType, error) {
portOptions := []string{
"User assigned managed identity",
"Connection string",
}
selection, err := i.console.Select(ctx, input.ConsoleOptions{
Message: "Choose auth type for '" + serviceName + "'?",
Options: portOptions,
})
if err != nil {
return scaffold.AUTH_TYPE_UNSPECIFIED, err
}
if selection == 0 {
return scaffold.AuthType_TOKEN_CREDENTIAL, nil
} else {
return scaffold.AuthType_PASSWORD, nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ resource connectionStringSecret 'Microsoft.KeyVault/vaults/secrets@2022-07-01' =
name: connectionStringSecretName
parent: keyVault
properties: {
value: listKeys(concat(resourceId('Microsoft.EventHub/namespaces', eventHubsNamespaceName), '/AuthorizationRules/RootManageSharedAccessKey'), '2024-01-01').primaryConnectionString
value: listKeys(concat(resourceId('Microsoft.EventHub/namespaces', eventHubsNamespaceName), '/AuthorizationRules/RootManageSharedAccessKey'), eventHubsNamespace.apiVersion).primaryConnectionString
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ resource serviceBusConnectionStringSecret 'Microsoft.KeyVault/vaults/secrets@202
value: listKeys(concat(resourceId('Microsoft.ServiceBus/namespaces', serviceBusNamespaceName), '/AuthorizationRules/RootManageSharedAccessKey'), serviceBusNamespace.apiVersion).primaryConnectionString
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
param storageAccountName string
param connectionStringSecretName string
param keyVaultName string

resource storageAccount 'Microsoft.Storage/storageAccounts@2023-05-01' existing = {
name: storageAccountName
}

resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = {
name: keyVaultName
}

resource connectionStringSecret 'Microsoft.KeyVault/vaults/secrets@2022-07-01' = {
name: connectionStringSecretName
parent: keyVault
properties: {
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};AccountKey=${storageAccount.listKeys().keys[0].value};EndpointSuffix=${environment().suffixes.storage}'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

FYI: This is different to Event Hubs and Service Bus.

}
}
50 changes: 43 additions & 7 deletions cli/azd/resources/scaffold/templates/resources.bicept
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,21 @@ module storageAccount 'br/public:avm/res/storage/storage-account:0.14.3' = {
]
networkAcls: {
defaultAction: 'Allow'
}
}
tags: tags
}
}

{{- if (and .AzureStorageAccount .AzureStorageAccount.AuthUsingConnectionString) }}
module storageAccountConnectionString './modules/set-storage-account-connection-string.bicep' = {
name: 'storageAccountConnectionString'
params: {
storageAccountName: storageAccountName
connectionStringSecretName: 'STORAGE-ACCOUNT-CONNECTION-STRING'
keyVaultName: keyVault.outputs.name
}
}
{{end}}
{{end}}

{{- if .AzureServiceBus }}
Expand Down Expand Up @@ -340,6 +351,13 @@ module {{bicepName .Name}} 'br/public:avm/res/app/container-app:0.8.0' = {
keyVaultUrl: '${keyVault.outputs.uri}secrets/SERVICEBUS-CONNECTION-STRING'
}
{{- end}}
{{- if (and .AzureStorageAccount .AzureStorageAccount.AuthUsingConnectionString) }}
{
name: 'storage-account-connection-string'
identity:{{bicepName .Name}}Identity.outputs.resourceId
keyVaultUrl: '${keyVault.outputs.uri}secrets/STORAGE-ACCOUNT-CONNECTION-STRING'
}
{{- end}}
],
map({{bicepName .Name}}Secrets, secret => {
name: secret.secretRef
Expand Down Expand Up @@ -425,7 +443,7 @@ module {{bicepName .Name}} 'br/public:avm/res/app/container-app:0.8.0' = {
{{- end}}
{{- if (and .AzureEventHubs .AzureEventHubs.AuthUsingManagedIdentity) }}
{
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTION_STRING'
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTIONSTRING'

@rujche rujche Nov 1, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

FYI: Both SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTION_STRING and SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTION_STRING SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTIONSTRING can work, but SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTION_STRING is the legacy format.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Did you mean SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTIONSTRING?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes. you are right. I updated the comment.

value: ''
}
{
Expand All @@ -439,7 +457,7 @@ module {{bicepName .Name}} 'br/public:avm/res/app/container-app:0.8.0' = {
{{- end}}
{{- if (and .AzureEventHubs .AzureEventHubs.AuthUsingConnectionString) }}
{
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTION_STRING'
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTIONSTRING'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Same here.

secretRef: 'event-hubs-connection-string'
}
{
Expand All @@ -459,14 +477,32 @@ module {{bicepName .Name}} 'br/public:avm/res/app/container-app:0.8.0' = {
{{- end}}
{{- if (and .AzureStorageAccount .AzureStorageAccount.AuthUsingManagedIdentity) }}
{
name: 'SPRING_CLOUD_AZURE_STORAGE_CREDENTIAL_MANAGEDIDENTITYENABLED'
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_PROCESSOR_CHECKPOINTSTORE_CONNECTIONSTRING'

@rujche rujche Nov 1, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

FYI: SPRING_CLOUD_AZURE_EVENTHUBS_PROCESSOR_CHECKPOINTSTORE_CONNECTION_STRING can not work.
Reason:

image

Convert all - to _ is supported, convert none is also supported. Convert sub set is not supported.

  1. Convert all: SPRING_CLOUD_AZURE_EVENTHUBS_PROCESSOR_CHECKPOINT_STORE_CONNECTION_STRING.
  2. Convert none: SPRING_CLOUD_AZURE_EVENTHUBS_PROCESSOR_CHECKPOINTSTORE_CONNECTIONSTRING.
  3. Convert sub set: SPRING_CLOUD_AZURE_EVENTHUBS_PROCESSOR_CHECKPOINTSTORE_CONNECTIO_NSTRING.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I am just curious how they match the CHECKPOINT_STORE here, is it that if it's a camel case, such as aB, it will switch to A_B?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

value: ''
}
{
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_PROCESSOR_CHECKPOINTSTORE_CREDENTIAL_MANAGEDIDENTITYENABLED'
value: 'true'
}
{
name: 'SPRING_CLOUD_AZURE_STORAGE_CREDENTIAL_CLIENTID'
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_PROCESSOR_CHECKPOINTSTORE_CREDENTIAL_CLIENTID'
value: {{bicepName .Name}}Identity.outputs.clientId
}
{{- end}}
{{- if (and .AzureStorageAccount .AzureStorageAccount.AuthUsingConnectionString) }}
{
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_PROCESSOR_CHECKPOINTSTORE_CONNECTIONSTRING'
secretRef: 'storage-account-connection-string'
}
{
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_PROCESSOR_CHECKPOINTSTORE_CREDENTIAL_MANAGEDIDENTITYENABLED'
value: 'false'
}
{
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_PROCESSOR_CHECKPOINTSTORE_CREDENTIAL_CLIENTID'
value: ''
}
{{- end}}

{{- if .AzureServiceBus }}
{
Expand All @@ -476,7 +512,7 @@ module {{bicepName .Name}} 'br/public:avm/res/app/container-app:0.8.0' = {
{{- end}}
{{- if (and .AzureServiceBus .AzureServiceBus.AuthUsingManagedIdentity) }}
{
name: 'SPRING_CLOUD_AZURE_SERVICEBUS_CONNECTION_STRING'
name: 'SPRING_CLOUD_AZURE_SERVICEBUS_CONNECTIONSTRING'
value: ''
}
{
Expand All @@ -490,7 +526,7 @@ module {{bicepName .Name}} 'br/public:avm/res/app/container-app:0.8.0' = {
{{- end}}
{{- if (and .AzureServiceBus .AzureServiceBus.AuthUsingConnectionString) }}
{
name: 'SPRING_CLOUD_AZURE_SERVICEBUS_CONNECTION_STRING'
name: 'SPRING_CLOUD_AZURE_SERVICEBUS_CONNECTIONSTRING'
secretRef: 'servicebus-connection-string'
}
{
Expand Down