@Casper Rubæk You need to add permissions like below -
permissions = new Permissions { Secrets = new SecretPermissions[] { new SecretPermissions("get") } };
Also, you need to pass access policy object as a List to Vault Properties like below -
var vaultProperties = new VaultProperties(tenantId, new Sku(SkuName.Standard))
{
AccessPolicies = new List<AccessPolicyEntry>
{
accessPolicyEntry
}
};
Also, you need to use WaitForCompletionAsync()
which polls server to know when Key Vault create operation succeeds.
Please find below the updated code to create a Key Vault -
Sku sku = new Sku(SkuName.Standard);
Permissions permissions = new Permissions()
{
Secrets = new SecretPermissions[] { new SecretPermissions("get") }
};
AccessPolicyEntry accessPolicyEntry = new AccessPolicyEntry(tenantId, objectId, permissions1);
var vaultProperties1 = new VaultProperties(tenantId, new Sku(SkuName.Standard))
{
AccessPolicies = new List<AccessPolicyEntry>
{
accessPolicyEntry1
}
};
VaultCreateOrUpdateParameters vaultCreateOrUpdateParameters = new VaultCreateOrUpdateParameters(region, vaultProperties1);
var rawResult = await vaults.StartCreateOrUpdateAsync(rgName, vaultName1, vaultCreateOrUpdateParameters);
var vault1 = (await rawResult.WaitForCompletionAsync()).Value;
I have tested this and it works fine in my local.
Also, please refer to this sample code for your reference to use Azure .NET SDK to create KeyVault.
Please let me know if you have any questions.
Thanks
Saurabh
----------
Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.