microsoft / microsoft/aspire

Unable to retrieve value for secret in already provisioned Key Vault

Open
#13,533 1 comment 2 reactions 0 assignees View on GitHub
area-integrations
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

Attempting to read a value from an existing Key Vault secret in an AppHost with the following code:

```csharp
var builder = DistributedApplication.CreateBuilder(args);

var keyVaultNameParam = builder.AddParameter("integration-keyvault-name");
var keyVaultResourceGroupParam = builder.AddParameter("integration-keyvault-resource-group-name");

var integrationVault = builder.AddAzureKeyVault("integration-keyvault")
.AsExisting(keyVaultNameParam, keyVaultResourceGroupParam);

var connectionString = integrationVault.GetSecret("MyConnectionString");

var connectionStringValue = await connectionString.GetValueAsync();
```

Throws:

```
System.InvalidOperationException: 'Secret 'MyConnectionString' not found in Key Vault 'integration-keyvault'.'
```

I've been through the Aspire docs and unable to find anything else that needs to be configured for this to work. What am I missing?

appsettings.json

```json

{
"Azure": {
"SubscriptionId": "",
"AllowResourceGroupCreation": false,
"ResourceGroup": "",
"CredentialSource": "VisualStudio"
},
"Parameters": {
"integration-keyvault-name": "",
"integration-keyvault-resource-group-name": ""
}
}
```

### Expected Behavior

_No response_

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version info

_No response_

### Anything else?

dotnet 8.0
Visual Studio 22 17.14.20
Aspire.Hosting.Apphost 13.0.2
Aspire.Hosting.Azure 13.0.2
Aspire.Hosting.Azure.KeyVault 13.0.2

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.