forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyVaultFeature.cs
More file actions
53 lines (48 loc) · 1.98 KB
/
KeyVaultFeature.cs
File metadata and controls
53 lines (48 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Collections.Generic;
using Azure.Provisioning.Authorization;
using Azure.Provisioning.CloudMachine;
using Azure.Provisioning.Expressions;
using Azure.Provisioning.KeyVault;
using Azure.Provisioning.Primitives;
namespace Azure.CloudMachine.KeyVault;
public class KeyVaultFeature : CloudMachineFeature
{
public KeyVaultSku Sku { get; set; }
public KeyVaultFeature(KeyVaultSku? sku = default)
{
if (sku == null)
{
sku = new KeyVaultSku { Name = KeyVaultSkuName.Standard, Family = KeyVaultSkuFamily.A, };
}
Sku = sku;
}
protected override ProvisionableResource EmitCore(CloudMachineInfrastructure infrastructure)
{
// Add a KeyVault to the CloudMachine infrastructure.
KeyVaultService keyVaultResource = new("cm_kv")
{
Name = infrastructure.Id,
Properties =
new KeyVaultProperties
{
Sku = this.Sku,
TenantId = BicepFunction.GetSubscription().TenantId,
EnabledForDeployment = true,
AccessPolicies = [
new KeyVaultAccessPolicy() {
ObjectId = infrastructure.PrincipalIdParameter,
Permissions = new IdentityAccessPermissions() {
Secrets = [IdentityAccessSecretPermission.Get, IdentityAccessSecretPermission.Set]
},
TenantId = infrastructure.Identity.TenantId
}
]
},
};
infrastructure.AddResource(keyVaultResource);
RequiredSystemRoles.Add(keyVaultResource, [(KeyVaultBuiltInRole.GetBuiltInRoleName(KeyVaultBuiltInRole.KeyVaultAdministrator), KeyVaultBuiltInRole.KeyVaultAdministrator.ToString())]);
return keyVaultResource;
}
}