Project: Chef InSpec (Provisioning / Security & Compliance)
File: azurerm_virtual_machine.md

+++ title = "azurermvirtualmachine resource" draft = false gh_repo = "inspec" platform = "azure" [menu] [menu.inspec] title = "azurermvirtualmachine" identifier = "inspec/resources/azure/azurermvirtualmachine.md azurermvirtualmachine resource" parent = "inspec/resources/azure" +++ {{< inspec/azurermdeprecated resource="azurevirtual_machine" >}} Use the `azurermvirtualmachine` InSpec audit resource to test properties related to a virtual machine. This resource interacts with version `2017-12-01` of the Azure Management API. For more information see the . At the moment, there doesn't appear to be a way to select the version of the Azure API docs. If you notice a newer version being referenced in the official documentation please open an issue or submit a pull request using the updated version. This resource is available in the `inspec-azure` [resource pack](/inspec/glossary/#resource-pack). To use it, add the following to your `inspec.yml` in your top-level profile: depends: name: inspec-azure git: https://github.com/inspec/inspec-azure.git You'll also need to setup your Azure credentials; see the resource pack . This resource first became available in 1.0.0 of the inspec-azure resource pack. The `resource_group` and virtual machine `name` must be given as parameters. describe azurermvirtualmachine(resource_group: 'MyResourceGroup', name: 'MyVmName') do ... end describe azurermvirtualmachine(resource_group: 'MyResourceGroup', name: 'MyVmName') do its('data_disks') { should include 'DataDisk1' } its('data_disks') { should include 'DataDisk2' } end describe azurermvirtualmachine(resource_group: 'MyResourceGroup', name: 'MyVmName') do it { should havemonitoringagent_installed } end `resource_group` `name` Defines the resource group that the virtual machine that you wish to test resides in. describe azurermvirtualmachine(resource_group: 'MyResourceGroup', name: 'MyVmName') do ... end Defines the name of the virtual machine that you wish to test. describe azurermvirtualmachine(resource_group: 'MyResourceGroup', name: 'MyVmName') do ... end `id` `name` `location` `properties` `resources` `tags` `type` `zones` `installedextensionstypes` `installedextensionsnames` `monitoringagentinstalled` `osdiskname` `datadisknames` The virtual machine's id. its('id') { should eq(id) } Id will be in format: '/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/virtualMachines/MyVirtualMachine' The virtual machine's name. its('name') { should eq('MyVmName') } The virtual machine's location. its('location') { should eq('East US') } The virtual machine's tags. its('tags') { should eq({ 'key' => 'value' }) } The virtual machine's resource type. its('type') { should eq('Microsoft.Compute/virtualMachines') } The virtual machine's availability zones. its('zones') should include('zone1', 'zone2') The virtual machine's operating system disk name. its('osdiskname') { should eq('OsDiskName') } The virtual machine's data disk names. its('datadisknames') { should include('DataDisk1') } List of all installed extensions' types for the virtual machine. its('installedextensionstypes') { should eq(['ExtensionType']) } List of all installed extensions' names for the virtual machine. its('installedextensionsnames') { should eq(['ExtensionName']) } There are additional attributes that may be accessed that we have not documented. Please take a look at the . Any attribute in the response may be accessed with the key names separated by dots (`.`). The API may not always return keys that do not have any associated data. There may be cases where the deeply nested property may not have the desired attribute along your call chain. If you find yourself writing tests against properties that may be nil, fork this resource pack and add an accessor to the resource. Within that accessor you'll be able to guard against nil keys. Pull requests are always welcome. {{< readfile file="content/inspec/reusable/md/inspecmatcherslink.md" >}} This resource has the following special matchers. describe azurermvirtualmachine(resource_group: 'MyResourceGroup', name: 'MyVmName') do it { should exist } end describe azurermvirtualmachine(resource_group: 'MyResourceGroup', name: 'DoesNotExist') do it { should_not exist } end describe azurermvirtualmachine(resource_group: 'MyResourceGroup', name: 'MyVmName') do it { should haveonlyapproved_extensions(['ApprovedExtension', 'OtherApprovedExtensions']) } end describe azurermvirtualmachine(resource_group: 'MyResourceGroup', name: 'MyVmName') do it { should havemonitoringagent_installed } end describe azurermvirtualmachine(resource_group: 'MyResourceGroup', name: 'MyVmName') do it { should haveendpointprotection_installed(['Extension1', 'Extension2']) } end Your [Service Principal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal) must be setup with a `contributor` role on the subscription you wish to test.