2017-12-12 18:20:22 +00:00
---
title: About the azure_generic_resource Resource
---
2018-02-15 02:23:29 +00:00
# azure\_generic\_resource
2017-12-12 18:20:22 +00:00
2018-02-15 04:31:56 +00:00
Use the `azure_generic_resource` InSpec audit resource to test any valid Azure Resource. This is very useful if you need to test something that we do not yet have a specific Inspec resource for.
2017-12-12 18:20:22 +00:00
## Syntax
2018-02-15 02:23:29 +00:00
describe azure_generic_resource(group_name: 'MyResourceGroup', name: 'MyResource') do
its('property') { should eq 'value' }
end
2017-12-12 18:20:22 +00:00
where
2018-02-15 04:31:56 +00:00
* `MyResourceGroup` is the name of the resource group that contains the Azure Resource to be validated
* `MyResource` is the name of the resource that needs to be checked
2018-02-19 13:43:12 +00:00
* `property` This generic resource dynamically creates the properties on the fly based on the type of resource that has been targetted.
2017-12-12 18:20:22 +00:00
* `value` is the expected output from the chosen property
2018-02-20 02:35:14 +00:00
<br>
## Parameters
* `group_name`, `name`, `apiversion`, `type`
<br>
## Parameter Examples
2017-12-12 18:20:22 +00:00
The options that can be passed to the resource are as follows.
2018-02-20 02:35:14 +00:00
### group_name (required)
Use this parameter to define the Azure Resource Group to be tested.
describe azure_virtual_machine_data_disk(group_name: 'InSpec-Azure') do
...
end
### name
Use this parameter to define the name of the Azure resource to test.
describe azure_virtual_machine_data_disk(group_name: 'InSpec-Azure', name: 'Windows-Internal-VM') do
...
end
### apiversion
The API Version to use when querying the resource. Defaults to the latest version for the resoure type is used.
describe azure_virtual_machine_data_disk(group_name: 'InSpec-Azure', name: 'Windows-Internal-VM', apiversion: '2.0') do
...
end
### type
Use this parameter to define the type of resources to test.
describe azure_virtual_machine_data_disk(group_name: 'InSpec-Azure', name: 'Windows-Internal-VM', apiversion: '2.0', type: 'Microsoft.Compute/virtualMachines') do
...
end
2017-12-12 18:20:22 +00:00
These options can also be set using the environment variables:
2018-02-19 13:43:12 +00:00
* `AZURE_RESOURCE_GROUP_NAME`
* `AZURE_RESOURCE_NAME`
* `AZURE_RESOURCE_TYPE`
* `AZURE_RESOURCE_API_VERSION`
2017-12-12 18:20:22 +00:00
When the options have been set as well as the environment variables, the environment variables take priority.
2018-02-19 13:43:12 +00:00
<br>
2017-12-12 18:20:22 +00:00
2018-02-20 03:09:51 +00:00
## Parameter Example
2017-12-12 18:20:22 +00:00
2018-02-20 02:35:14 +00:00
describe azure_generic_resource(group_name: 'Inspec-Azure', name: 'Linux-Internal-VM', apiversion: '2.0') do
2018-02-15 04:31:56 +00:00
its('location') { should eq 'westeurope' }
end
2017-12-12 18:20:22 +00:00
2018-02-19 13:43:12 +00:00
<br>
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
## Properties
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
The properties that can be tested are entirely dependent on the Azure Resource that is under scrutiny. That means the properties vary. The best way to see what is available please use the [Azure Resources Portal](https://resources.azure.com) to select the resource you are interested in and see what can be tested.
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
This resource allows you to test _any_ valid Azure Resource. The trade off for this is that the language to check each item is not as natural as it would be for a native Inspec resource.
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
<br>
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
## Property Examples
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
The following examples show how to use some of the InSpec audit properties:
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
### Tests the virtual machine's location
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
its('location') { should cmp 'westeurope' }
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
### Tests for the presence of a specified address prefix
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
its('properties.addressSpace.addressPrefixes') { should include '10.1.1.0/24' }
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
### Tests that virtual machine was created from the correct disk
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
its('properties.creationData.createOption') { should eq 'FromImage' }
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
### Tests that the image is Ubuntu
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
its('properties.creationData.imageReference.id') { should match 'Canonical' }
its('properties.creationData.imageReference.id') { should match 'UbuntuServer' }
its('properties.creationData.imageReference.id') { should match '16.04.0-LTS' }
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
### Tests the disk size
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
its('properties.diskSizeGB') { should be > 25 }
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
### Tests the disk state
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
its('properties.diskState') { should cmp 'Attached' }
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
### Tests that there are no custom DNS settings
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
its('properties.dnsSettings.dnsServers.count') { should eq 0 }
its('properties.dnsSettings.appliedDnsServers.count') { should eq 0 }
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
### Tests that the NIC is connected to the correct machine
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
its('properties.virtualMachine.id') { should match 'Linux-External-VM' }
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
### Tests that the blob and file services are enabled
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
its('properties.encryption.services.blob.enabled') { should be true }
its('properties.encryption.services.file.enabled') { should be true }
its('properties.encryption.keySource') { should cmp 'Microsoft.Storage' }
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
### Test the hardware profile
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
its('properties.hardwareProfile.vmSize') { should cmp 'Standard_DS2_v2' }
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
### Test the network interfaces
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
its('properties.networkProfile.networkInterfaces.count') { should eq 1 }
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
### Test the authentication and OS type
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
its('properties.osProfile.computerName') { should eq 'linux-external-1' }
its('properties.osProfile.adminUsername') { should eq 'azure' }
its('properties.osProfile.linuxConfiguration.disablePasswordAuthentication') { should be true }
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
### Test that the tags are properly set
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
it { should have_tags }
its('tag_count') { should be 1 }
its('tags') { should include 'Description' }
its('Description_tag') { should match 'Externally facing' }
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
<br>
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
## Matchers
2018-02-16 02:52:54 +00:00
2018-02-20 03:09:51 +00:00
This 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-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
<br>
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
## References
2018-02-16 02:52:54 +00:00
2018-02-19 13:43:12 +00:00
Please see the integration tests for in depth examples of how this resource can be used.
2018-02-15 04:31:56 +00:00
2018-02-19 13:43:12 +00:00
[Inspec Integration Tests for Azure Generic Resources](https://github.com/chef/inspec/tree/master/test/azure/verify/controls)