2017-12-12 18:20:22 +00:00
---
title: About the azure_virtual_machine_datadisk Resource
2018-02-20 02:12:53 +00:00
platform: azure
2017-12-12 18:20:22 +00:00
---
2018-02-15 02:23:29 +00:00
# azure\_virtual\_machine\_datadisk
2017-12-12 18:20:22 +00:00
Use this resource to ensure that a specific data disk attached to a machine has been created properly.
2018-08-09 12:34:49 +00:00
## Availability
### Installation
2019-04-26 18:24:29 +00:00
This resource is distributed along with Chef InSpec itself. You can use it automatically.
2018-08-09 12:34:49 +00:00
### Version
This resource first became available in v2.0.16 of InSpec.
2017-12-12 18:20:22 +00:00
## Syntax
The name of the resource group and machine are required to use this resource.
2018-02-20 02:12:53 +00:00
describe azure_virtual_machine_data_disk(group_name: 'InSpec-Azure', name: 'MyVM') do
2018-02-15 02:23:29 +00:00
its('property') { should eq 'value' }
end
2017-12-12 18:20:22 +00:00
2018-02-15 18:24:21 +00:00
where
2017-12-12 18:20:22 +00:00
2018-02-15 18:24:21 +00:00
* `MyVm` is the name of the virtual machine as seen in Azure. (It is **not** the hostname of the machine)
2018-03-20 12:43:30 +00:00
* `InSpec-Azure` is the name of the resource group that the machine is in.
2018-02-15 02:23:29 +00:00
* `property` is a resource property
2018-02-20 02:12:53 +00:00
* `value` is the expected output from the matcher
2017-12-12 18:20:22 +00:00
2018-02-15 02:23:29 +00:00
<br>
2017-12-12 18:20:22 +00:00
2018-02-15 02:23:29 +00:00
## Examples
2017-12-12 18:20:22 +00:00
2019-04-26 18:24:29 +00:00
The following examples show to use this Chef InSpec audit resource.
2017-12-12 18:20:22 +00:00
2018-02-15 02:23:29 +00:00
### Check that the first data disk is of the correct size
2018-02-20 02:12:53 +00:00
describe azure_virtual_machine_data_disk(group_name: 'InSpec-Azure', name: 'Linux-Internal-VM').where(number: 1) do
2018-02-15 02:23:29 +00:00
its('size') { should cmp >= 15 }
end
2017-12-12 18:20:22 +00:00
2018-02-15 02:23:29 +00:00
<br>
2017-12-12 18:20:22 +00:00
2018-02-20 02:12:53 +00:00
## Resource Parameters
2017-12-12 18:20:22 +00:00
2018-02-20 02:12:53 +00:00
* `group_name`, `name`, `apiversion`
2018-02-15 02:23:29 +00:00
2018-02-20 02:12:53 +00:00
## Parameter Examples
2018-02-15 02:23:29 +00:00
2018-02-20 02:12:53 +00:00
The options that can be passed to the resource are as follows.
2018-02-15 02:23:29 +00:00
2018-02-20 02:12:53 +00:00
### group_name (required)
2017-12-12 18:20:22 +00:00
2018-02-20 02:12:53 +00:00
Use this parameter to define the Azure Resource Group to be tested.
2017-12-12 18:20:22 +00:00
2018-02-20 02:12:53 +00:00
describe azure_virtual_machine_data_disk(group_name: 'InSpec-Azure') do
...
end
2017-12-12 18:20:22 +00:00
2018-02-20 02:12:53 +00:00
### name
2017-12-12 18:20:22 +00:00
2018-02-20 02:12:53 +00:00
Use this parameter to define the name of the Azure resource to test.
2017-12-12 18:20:22 +00:00
2018-02-20 02:12:53 +00:00
describe azure_virtual_machine_data_disk(group_name: 'InSpec-Azure', name: 'Windows-Internal-VM') do
...
end
2017-12-12 18:20:22 +00:00
2018-02-20 02:12:53 +00:00
### apiversion
2017-12-12 18:20:22 +00:00
2018-03-02 14:18:01 +00:00
The API Version to use when querying the resource. Defaults to the latest version for the resource.
2017-12-12 18:20:22 +00:00
2018-02-20 02:12:53 +00:00
describe azure_virtual_machine_data_disk(group_name: 'InSpec-Azure', name: 'Windows-Internal-VM', apiversion: '2.0') do
...
end
2017-12-12 18:20:22 +00:00
2018-02-20 02:12:53 +00:00
These options can also be set using the environment variables:
2017-12-12 18:20:22 +00:00
2018-02-20 02:12:53 +00:00
* `AZURE_RESOURCE_GROUP_NAME`
* `AZURE_RESOURCE_NAME`
* `AZURE_RESOURCE_API_VERSION`
2017-12-12 18:20:22 +00:00
2018-02-20 02:12:53 +00:00
When the options have been set as well as the environment variables, the environment variables take priority.
<br>
## Filter Criteria
* `number`, `disk`
<br>
## Filter Examples
2017-12-12 18:20:22 +00:00
### disk
The zero based index of the disk attached to the machine.
2018-02-20 02:12:53 +00:00
describe azure_virtual_machine_data_disk(group_name: 'InSpec-Azure', name: 'Windows-Internal-VM').where(disk: 0)
end
2017-12-12 18:20:22 +00:00
### number
The '1' based index of the disk attached to the machine.
2018-02-20 02:12:53 +00:00
describe azure_virtual_machine_data_disk(group_name: 'InSpec-Azure', name: 'Windows-Internal-VM').where(number: 1)
end
<br>
## Properties
* `count`, `disk`, `number`, `name`, `size`, `lun`, `caching`, `create_option`, `is_managed_disk?`, `vhd_uri`, `storage_account_name`, `storage_account_type`, `id`, `subscription_id`, `resource_group`
<br>
## Property Examples
### count
Returns the number of data disks attached to the machine
its('count') { should eq 1 }
2017-12-12 18:20:22 +00:00
### name
Returns a string of the name of the disk.
2018-02-20 02:12:53 +00:00
its('name') { should cmp 'linux-external-datadisk-1' }
2017-12-12 18:20:22 +00:00
### size
Returns an integer of size of this disk in GB.
2018-02-20 02:12:53 +00:00
its('size') { should cmp >= 15 }
2017-12-12 18:20:22 +00:00
### lun
2018-02-20 03:09:51 +00:00
The disk number as reported by Azure. Has a zero-based index value.
2017-12-12 18:20:22 +00:00
2018-02-20 02:12:53 +00:00
its('lun') { should cmp 0 }
2017-12-12 18:20:22 +00:00
### caching
String stating the caching that has been set on the disk.
2018-02-20 02:12:53 +00:00
its('caching') { should cmp 'none' }
2018-02-15 02:23:29 +00:00
### create\_option
2017-12-12 18:20:22 +00:00
2018-02-20 03:09:51 +00:00
How the disk was created. Typically for data disks, this will be the string value 'Empty'.
2017-12-12 18:20:22 +00:00
2018-02-20 02:12:53 +00:00
its('create_option') { should cmp 'Empty' }
2018-02-15 02:23:29 +00:00
### is\_managed\_disk?
2017-12-12 18:20:22 +00:00
Boolean stating if the disk is a managed disk or not. If it is not a managed disk then it is one that is stored in a Storage Account.
2018-02-20 02:12:53 +00:00
its('is_managed_disk?') { should cmp 'false' }
2018-02-15 02:23:29 +00:00
### vhd\_uri
2017-12-12 18:20:22 +00:00
2018-02-20 03:09:51 +00:00
If this _not_ a managed disk, then the `vhd_uri` will be the full URI to the disk in the storage account.
2017-12-12 18:20:22 +00:00
2018-02-20 02:12:53 +00:00
its('vhd_uri') { should cmp '
https://primary_storage.blob.core.windows.net/container_name/vm_name.vhd' }
2018-02-15 02:23:29 +00:00
### storage\_account\_name
2017-12-12 18:20:22 +00:00
If this is _not_ a managed disk this will be the storage account name in which the disk is stored.
2018-02-20 02:12:53 +00:00
This derived from the `vhd_uri`.
its('storage_account_name') { should cmp 'primary_storage' }
2017-12-12 18:20:22 +00:00
2018-02-15 02:23:29 +00:00
### storage\_account\_type
2017-12-12 18:20:22 +00:00
2018-02-20 03:09:51 +00:00
If this is a managed disk this is the storage account type, e.g. `Standard_LRS`.
2017-12-12 18:20:22 +00:00
2018-02-20 02:12:53 +00:00
its('storage_account_type') { should cmp 'Standard_LRS' }
2017-12-12 18:20:22 +00:00
### id
2018-02-20 02:12:53 +00:00
If this is a managed disk then this is the fully qualified id for the disk in Azure.
its('id') { should cmp '/subscriptions/1234abcd-e567-890f-g123-456h78i9jkl0/resourceGroups/InSpec-Azure' }
2017-12-12 18:20:22 +00:00
2018-02-15 02:23:29 +00:00
### subscription\_id
2017-12-12 18:20:22 +00:00
2018-02-14 01:42:39 +00:00
If this is a managed disk, this returns the subscription id of where the disk is stored.
2017-12-12 18:20:22 +00:00
This is derived from the `id`.
2018-02-20 02:12:53 +00:00
its('subscription_id') { should cmp '1234abcd-e567-890f-g123-456h78i9jkl0' }
2018-02-15 02:23:29 +00:00
### resource\_group
2017-12-12 18:20:22 +00:00
If this is a managed disk, this returns the resource group in which the disk is stored.
This is derived from the `id`.
2018-02-20 02:12:53 +00:00
its('resource_group') { should cmp 'InSpec-Azure' }
2018-02-15 02:23:29 +00:00
<br>
2017-12-12 18:20:22 +00:00
2018-02-15 02:23:29 +00:00
## Matchers
2017-12-12 18:20:22 +00:00
2019-04-26 18:24:29 +00:00
This Chef InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
2018-02-20 02:12:53 +00:00
2018-03-20 12:43:30 +00:00
The following properties are applied to the virtual machine itself and not specific disks.
2018-02-20 02:12:53 +00:00
### have\_data\_disks
Returns a boolean denoting if any data disks are attached to the machine.
it { should have_data_disks }
### have\_managed\_disks
Returns a boolean stating if the machine has Managed Disks for data disks.
2017-12-12 18:20:22 +00:00
2018-02-20 02:12:53 +00:00
it { should have_managed_disks }
2018-02-15 02:23:29 +00:00
2018-02-20 02:12:53 +00:00
<br>
2018-02-15 02:23:29 +00:00
2018-02-20 02:12:53 +00:00
## References
2018-02-15 02:23:29 +00:00
2018-02-20 02:12:53 +00:00
* [Azure Ruby SDK - Compute](https://github.com/Azure/azure-sdk-for-ruby/tree/master/management/azure_mgmt_compute)
* [Linux Internal Data Disks](https://github.com/chef/inspec/blob/master/test/azure/verify/controls/virtual_machine_linux_external_vm_datadisk.rb)
2018-02-20 03:09:51 +00:00
* [Windows Internal Data Disk](https://github.com/chef/inspec/blob/master/test/azure/verify/controls/virtual_machine_windows_internal_vm_datadisk.rb)