@@ -138,6 +138,47 @@ function Create-KeyVault
138
138
return $properties
139
139
}
140
140
141
+ # Create key vault resources
142
+ function Create-KeyVaultWithAclEncryptionIdentity
143
+ {
144
+ Param
145
+ (
146
+ [Parameter (Mandatory = $true , Position = 0 )]
147
+ [string ] $resourceGroupName ,
148
+ [Parameter (Mandatory = $true , Position = 1 )]
149
+ [string ] $location ,
150
+ [Parameter (Mandatory = $false , Position = 2 )]
151
+ [string ] $vaultName ,
152
+ [Parameter (Mandatory = $false , Position = 3 )]
153
+ [String ] $userIdentityPrincipalId
154
+ )
155
+
156
+ # initialize parameters if needed
157
+ if ([string ]::IsNullOrEmpty($resourceGroupName )) { $resourceGroupName = Get-ComputeTestResourceName }
158
+ if ([string ]::IsNullOrEmpty($location )) { $location = Get-ComputeVMLocation }
159
+ if ([string ]::IsNullOrEmpty($vaultName )) { $vaultName = ' kv' + $resourceGroupName }
160
+
161
+ # create vault
162
+ $vault = New-AzKeyVault - VaultName $vaultName - ResourceGroupName $resourceGroupName - Location $location - Sku standard - DisableRbacAuthorization
163
+ $vault = Get-AzKeyVault - VaultName $vaultName - ResourceGroupName $resourceGroupName
164
+
165
+ # create access policy
166
+ $servicePrincipalName = (Get-AzContext ).Account.Id
167
+ Assert-NotNull $servicePrincipalName
168
+ if (-not [string ]::IsNullOrEmpty($userIdentityPrincipalId )) {
169
+ Set-AzKeyVaultAccessPolicy - VaultName $vaultName - ResourceGroupName $resourceGroupName - ObjectId $userIdentityPrincipalId - PermissionsToKeys all - PermissionsToSecrets all
170
+ }
171
+ Set-AzKeyVaultAccessPolicy - VaultName $vaultName - ResourceGroupName $resourceGroupName - EnabledForDeployment - EnabledForTemplateDeployment
172
+
173
+ # return the newly created key vault properties
174
+ $properties = New-Object PSObject - Property @ {
175
+ DiskEncryptionKeyVaultId = $vault.ResourceId
176
+ DiskEncryptionKeyVaultUrl = $vault.VaultUri
177
+ # KeyEncryptionKeyUrl = $kek.Key.kid
178
+ }
179
+ return $properties
180
+ }
181
+
141
182
# Create a new virtual machine with other necessary resources configured
142
183
function Create-VirtualMachine
143
184
{
0 commit comments