Warning
inspec-azure resource pack, which offers rich functionality and specific resources to fit many common use cases. Use the azure_generic_resource Chef 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 Chef InSpec resource for.
This resource is distributed along with Chef InSpec itself. You can use it automatically.
This resource first became available in v2.0.16 of InSpec.
describe azure_generic_resource(group_name: 'MyResourceGroup', name: 'MyResource') do
its('property') { should eq 'value' }
end
where:
MyResourceGroup is the name of the resource group that contains the Azure Resource to be validatedMyResource is the name of the resource that needs to be checkedproperty This generic resource dynamically creates the properties on the fly based on the type of resource that has been targeted.value is the expected output from the chosen propertygroup_namenameapiversiontypeThe options that can be passed to the resource are as follows.
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
nameUse 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
apiversionThe API Version to use when querying the resource. Defaults to the latest version for the resource.
describe azure_virtual_machine_data_disk(group_name: 'InSpec-Azure', name: 'Windows-Internal-VM', apiversion: '2.0') do
...
end
typeUse 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
These options can also be set using the environment variables:
AZURE_RESOURCE_GROUP_NAMEAZURE_RESOURCE_NAMEAZURE_RESOURCE_TYPEAZURE_RESOURCE_API_VERSIONWhen the options have been set as well as the environment variables, the environment variables take priority.
describe azure_generic_resource(group_name: 'Inspec-Azure', name: 'Linux-Internal-VM', apiversion: '2.0') do
its('location') { should eq 'westeurope' }
end
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 to select the resource you are interested in and see what can be tested.
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 Chef InSpec resource.
The following examples show how to use some of the Chef InSpec audit properties:
its('location') { should cmp 'westeurope' }
its('properties.addressSpace.addressPrefixes') { should include '10.1.1.0/24' }
its('properties.creationData.createOption') { should eq 'FromImage' }
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' }
its('properties.diskSizeGB') { should be > 25 }
its('properties.diskState') { should cmp 'Attached' }
its('properties.dnsSettings.dnsServers.count') { should eq 0 }
its('properties.dnsSettings.appliedDnsServers.count') { should eq 0 }
its('properties.virtualMachine.id') { should match 'Linux-External-VM' }
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' }
its('properties.hardwareProfile.vmSize') { should cmp 'Standard_DS2_v2' }
its('properties.networkProfile.networkInterfaces.count') { should eq 1 }
its('properties.osProfile.computerName') { should eq 'linux-external-1' }
its('properties.osProfile.adminUsername') { should eq 'azure' }
its('properties.osProfile.linuxConfiguration.disablePasswordAuthentication') { should be true }
it { should have_tags }
its('tag_count') { should be 1 }
its('tags') { should include 'Description' }
its('Description_tag') { should match 'Externally facing' }
This Chef InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our matchers page.
Please see the integration tests for in depth examples of how this resource can be used.
© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs.chef.io/inspec/resources/azure_generic_resource/