Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Key Vault virtual machine extension examples and suggestions #15467

Merged
merged 7 commits into from
Jul 18, 2021
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
22 changes: 21 additions & 1 deletion src/Compute/Compute/help/Add-AzVMSecret.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,28 @@ For more information about the cmdlets, see [Azure Key Vault Cmdlets](/powershel

## EXAMPLES

### Example 1: Add a secret to a virtual machine
### Example 1: Add a secret to a virtual machine using the Azure Key Vault virtul machine extension
Copy link

@smotwani smotwani Jul 21, 2021

Choose a reason for hiding this comment

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

There is a typo in virtual word.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will push and update.

To install certificates on a virtual machine it is recommended to use the [Azure Key Vault virtual machine extension for Linux](https://docs.microsoft.com/azure/virtual-machines/extensions/key-vault-linux) or the [Azure Key Vault virtual machine extension for Windows](https://docs.microsoft.com/azure/virtual-machines/extensions/key-vault-windows).

```powershell
# Build settings
PS C:\> $settings = @{
secretsManagementSettings = @{
pollingIntervalInS = "<pollingInterval>"
certificateStoreName = "<certStoreName>"
certificateStoreLocation = "<certStoreLoc>"
observedCertificates = @("<observedCert1>", "<observedCert2>")
}
} | ConvertTo-Json
PS C:\> $extName = "KeyVaultForLinux"
PS C:\> $extPublisher = "Microsoft.Azure.KeyVault"
PS C:\> $extType = "KeyVaultForLinux"
# Start the deployment
PS C:\> Set-AzVmExtension -TypeHandlerVersion "2.0" -ResourceGroupName <ResourceGroupName> -Location <Location> -VMName <VMName> -Name $extName -Publisher $extPublisher -Type $extType -SettingString $settings
```

### Example 2: Add a secret to a virtual machine using Add-AzVMSecret
```powershell
PS C:\> $VirtualMachine = New-AzVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1" -AvailabilitySetID $AvailabilitySet.Id
PS C:\> $Credential = Get-Credential
PS C:\> $VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine -Windows -ComputerName "Contoso26" -Credential $Credential
Expand Down
26 changes: 25 additions & 1 deletion src/Compute/Compute/help/Add-AzVmssSecret.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,32 @@ For more information about the cmdlets, see [Azure Key Vault Cmdlets](/powershel

## EXAMPLES

### Example 1: Add a secret to the VMSS
### Example 1: Add a secret to the VMSS using the Azure Key Vault virtual machine extension

```powershell
# Build settings
PS C:\> $settings = @{
secretsManagementSettings = @{
pollingIntervalInS = "<pollingInterval>"
certificateStoreName = "<certStoreName>"
certificateStoreLocation = "<certStoreLoc>"
observedCertificates = @("<observedCert1>", "<observedCert2>")
}
} | ConvertTo-Json
PS C:\> $extName = "KeyVaultForLinux"
PS C:\> $extPublisher = "Microsoft.Azure.KeyVault"
PS C:\> $extType = "KeyVaultForLinux"
# Add Extension to VMSS
PS C:\> $vmss = Get-AzVmss -ResourceGroupName <ResourceGroupName> -VMScaleSetName <VmssName>
PS C:\> Add-AzVmssExtension -VirtualMachineScaleSet $vmss -Name $extName -Publisher $extPublisher -Type $extType -TypeHandlerVersion "2.0" -Setting $settings
# Start the deployment
PS C:\> Update-AzVmss -ResourceGroupName <ResourceGroupName> -VMScaleSetName <VmssName> -VirtualMachineScaleSet $vmss
```

To install certificates on a virtual machine it is recommended to use the [Azure Key Vault virtual machine extension for Linux](https://docs.microsoft.com/azure/virtual-machines/extensions/key-vault-linux) or the [Azure Key Vault virtual machine extension for Windows](https://docs.microsoft.com/azure/virtual-machines/extensions/key-vault-windows).

Choose a reason for hiding this comment

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

Shouldn't the above statement be added before the Example 1 that provides the steps to add a secret to the VMSS using the Azure Key Vault extension, also we should mention virtual machine scaleset vm or someting similar that points to the scaleset resource which is different than the stand alone vm resource.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I basically just inserted the extension info into what was already there. I will revisit this and see how to make the order more clear.


### Example 2: Add a secret to the VMSS using Add-AzVmssSecret
```powershell
PS C:\> $Vault = Get-AzKeyVault -VaultName "ContosoVault"
PS C:\> $CertConfig = New-AzVmssVaultCertificateConfig -CertificateUrl "http://keyVaultName.vault.contoso.net/secrets/secretName/secretVersion" -CertificateStore "Certificates"
PS C:\> $VMSS = New-AzVmssConfig
Expand Down