mirror of
https://github.com/inspec/inspec
synced 2024-11-13 00:17:08 +00:00
Added resource documentation
Closes #23 Signed-off-by: Russell Seymour <russell.seymour@turtlesystems.co.uk>
This commit is contained in:
parent
146da84937
commit
3e7880627f
3 changed files with 347 additions and 0 deletions
125
docs/resources/azure_resource_group.md.erb
Normal file
125
docs/resources/azure_resource_group.md.erb
Normal file
|
@ -0,0 +1,125 @@
|
|||
---
|
||||
title: About the azure_resource_group Resource
|
||||
---
|
||||
|
||||
# azure_resource_group
|
||||
|
||||
Use the `azure_resource_group` InSpec audit resource to ensure that an Azure Resource group has the correct resources.
|
||||
|
||||
## Syntax
|
||||
|
||||
The name of the resource group is specified as an attribute on the resource:
|
||||
|
||||
```ruby
|
||||
describe azure_resource_group(name: 'MyResourceGroup') do
|
||||
its('matcher') { should eq 'value' }
|
||||
end
|
||||
```
|
||||
|
||||
where
|
||||
|
||||
* `MyResourceGroup` is the name of the resource group being interrogated
|
||||
* `matcher` is one of
|
||||
- `total`
|
||||
- `count`
|
||||
- `nic_count`
|
||||
- `vm_count`
|
||||
- `vnet_count`
|
||||
- `sa_count`
|
||||
- `public_ip_count`
|
||||
- `contains`
|
||||
* `value` is the expected output from the matcher
|
||||
|
||||
For example:
|
||||
|
||||
```ruby
|
||||
describe azure_resource_group(name: 'ChefAutomate') do
|
||||
its('total') { should eq 7}
|
||||
its('nic_count') { should eq 1 }
|
||||
its('vm_count') { should eq 1 }
|
||||
end
|
||||
```
|
||||
|
||||
## Matchers
|
||||
|
||||
This InSpec audit resource has the following matchers:
|
||||
|
||||
### eq
|
||||
|
||||
<%= partial "/shared/matcher_eq" %>
|
||||
|
||||
### total
|
||||
|
||||
The total number of resources in the resource group
|
||||
|
||||
### nic_count
|
||||
|
||||
The number of network interface cards in the resource group
|
||||
|
||||
### vm_count
|
||||
|
||||
The number of virtual machines in the resource group
|
||||
|
||||
### vnet_count
|
||||
|
||||
The number of virtual networks in the resource group
|
||||
|
||||
### sa_count
|
||||
|
||||
The number of storage accounts in the resource group
|
||||
|
||||
### public_ip_count
|
||||
|
||||
The number of Public IP Addresses in the resource group
|
||||
|
||||
### contains
|
||||
|
||||
The `contains` filter allows testing of resources that are not directly supported by the resource pack:
|
||||
|
||||
```ruby
|
||||
its('contains') { should be true }
|
||||
```
|
||||
|
||||
This matcher is best used in conjunction with filters, for example the following tests that a Managed Disk image exists in the resource group
|
||||
|
||||
```ruby
|
||||
describe azure_resource_group(name: 'MyResourceGroup').where { type: 'Microsoft.Compute/images' } do
|
||||
its('contains') { should be true }
|
||||
end
|
||||
```
|
||||
|
||||
### count
|
||||
|
||||
The `count` filter allows testing for the number of resources that are not directly supported by the resource pack:
|
||||
|
||||
As before it is best used in conjunction with a filter. The following checks that there is at least 1 Managed Disk Image in the resource group.
|
||||
|
||||
```ruby
|
||||
describe azure_resource_group(name: 'MyResourceGroup').where { type: 'Microsoft.Compute/images' } do
|
||||
its('count') { should > 1 }
|
||||
end
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
The following examples show how to use this InSpec audit resource
|
||||
|
||||
### Test Resource Group has the correct number of resources
|
||||
|
||||
```ruby
|
||||
describe azure_resource_group(name: 'ChefAutomate') do
|
||||
its('total') { should eq 7}
|
||||
```
|
||||
|
||||
### Ensure that the Resource Group contains the correct resources
|
||||
|
||||
```ruby
|
||||
describe azure_resource_group(name: 'ChefAutomate') do
|
||||
its('total') { should eq 7 }
|
||||
its('vm_count') { should eq 2 }
|
||||
its('nic_count') { should eq 2 }
|
||||
its('public_ip_count') { should eq 1 }
|
||||
its('sa_count') { should eq 1 }
|
||||
its('vnet_count') { should eq 1 }
|
||||
end
|
||||
```
|
151
docs/resources/azure_virtual_machine.md.erb
Normal file
151
docs/resources/azure_virtual_machine.md.erb
Normal file
|
@ -0,0 +1,151 @@
|
|||
---
|
||||
title: About the azure_virtual_machine Resource
|
||||
---
|
||||
|
||||
# azure_virtual_machine
|
||||
|
||||
Use the `azure_virtual_machine` InSpec audit resource to ensure that a Virtual Machine has been provisionned correctly.
|
||||
|
||||
## Syntax
|
||||
|
||||
The name of the machine and the resourece group are required as attributes to the resource.
|
||||
|
||||
```ruby
|
||||
describe azure_virtual_machine(name: 'MyVM', resource_group: 'MyResourceGroup') do
|
||||
its('matcher') { should eq 'value' }
|
||||
end
|
||||
```
|
||||
|
||||
where
|
||||
|
||||
* `MyVm` is the name of the virtual machine as seen in Azure. (It is **not** the hostname of the machine)
|
||||
* `MyResourceGroup` is the name of the resouce group that the machine is in.
|
||||
* `matcher` is one of
|
||||
- `publisher`
|
||||
- `offer`
|
||||
- `sku`
|
||||
- `size`
|
||||
- `location`
|
||||
- `boot_diagnostics?`
|
||||
- `nic_count`
|
||||
- `username`
|
||||
- `computername`
|
||||
- `hostname`
|
||||
- `password_authentication?`
|
||||
- `ssh_key_count`
|
||||
- `os_type`
|
||||
* `value` is the expected output from the matcher
|
||||
|
||||
For example:
|
||||
|
||||
```ruby
|
||||
describe azure_virtual_machine(name: 'chef-automate-01', resource_group: 'ChefAutomate') do
|
||||
its('os_type') { should eq 'Linux' }
|
||||
its('boot_diagnostics?') { should be false }
|
||||
end
|
||||
```
|
||||
|
||||
## Matchers
|
||||
|
||||
This InSpec audit resource has the following matchers:
|
||||
|
||||
### eq
|
||||
|
||||
<%= partial "/shared/matcher_eq" %>
|
||||
|
||||
### publisher
|
||||
|
||||
The publisher of the image from which this machine was built.
|
||||
|
||||
This will be `nil` if the machine was created from a custom image.
|
||||
|
||||
### offer
|
||||
|
||||
The offer from the publisher of the build image.
|
||||
|
||||
This will be `nil` if the machine was created from a custom image.
|
||||
|
||||
### sku
|
||||
|
||||
The item from the publisher that was used to create the image.
|
||||
|
||||
This will be `nil` if the machine was created from a custom image.
|
||||
|
||||
### size
|
||||
|
||||
The size of the machine in Azure
|
||||
|
||||
```ruby
|
||||
its('size') { should eq 'Standard_DS2_v2' }
|
||||
```
|
||||
|
||||
### location
|
||||
|
||||
Where the machine is located
|
||||
|
||||
```ruby
|
||||
its('location') { should eq 'West Europe' }
|
||||
```
|
||||
|
||||
### boot_diagnostics?
|
||||
|
||||
Boolean test to see if boot diagnostics have been enabled on the machine
|
||||
|
||||
### nic_count
|
||||
|
||||
The number of network interface cards that have been attached to the machine
|
||||
|
||||
### username
|
||||
|
||||
The admin username that was assigned to the machine
|
||||
|
||||
NOTE: Azure does not allow the use of `Administrator` as the admin username on a Windows machine
|
||||
|
||||
### computername
|
||||
|
||||
The computername of the machine. This is what was assigned to the machine during deployment and is what _should_ be returned by the `hostname` command.
|
||||
|
||||
### hostname
|
||||
|
||||
Alias for computername.
|
||||
|
||||
### password_authentication?
|
||||
|
||||
Boolean to state of password authentication is enabled or not for the admin user.
|
||||
|
||||
```ruby
|
||||
its('password_authentication?') { should be false }
|
||||
```
|
||||
|
||||
This only applies to Linux machines and will always return `true` on Windows.
|
||||
|
||||
### ssh_key_count
|
||||
|
||||
Returns how many SSH keys have been applied to the machine.
|
||||
|
||||
This only applies to Linux machines and will always return `0` on Windows.
|
||||
|
||||
### os_type
|
||||
|
||||
Generic test that returns either `Linux` or `Windows`.
|
||||
|
||||
## Examples
|
||||
|
||||
The following examples show how to use this InSpec audit resource.
|
||||
|
||||
### Test that the machine was built from a Windows image
|
||||
|
||||
```ruby
|
||||
describe azure_virtual_machine(name: 'chef-ws-01', resource_group: 'ChefAutomate') do
|
||||
its('publisher') { should eq 'MicrosoftWindowsServer' }
|
||||
its('offer') { should eq 'WindowsServer' }
|
||||
its('sku') { should eq '2012-R2-Datacenter' }
|
||||
end
|
||||
```
|
||||
|
||||
### Ensure the machine is in the correct location
|
||||
|
||||
```ruby
|
||||
describe azure_virtual_machine(name: 'chef-ws-01', resource_group: 'ChefAutomate') do
|
||||
its('location') { should eq 'West Europe' }
|
||||
end
|
71
docs/resources/azure_virtual_machine_datadisks.md.erb
Normal file
71
docs/resources/azure_virtual_machine_datadisks.md.erb
Normal file
|
@ -0,0 +1,71 @@
|
|||
---
|
||||
title: About the azure_virtual_machine_datadisks Resource
|
||||
---
|
||||
|
||||
# azure_virtual_machine_datadisks
|
||||
|
||||
Use this resource to check that the correct number of data disks have been applied to the machine and that they are of the correct size.
|
||||
|
||||
## Syntax
|
||||
|
||||
The name of the resource group and machine are required to use this resource.
|
||||
|
||||
```ruby
|
||||
describe azure_virtual_machine(name: 'MyVM', resource_group: 'MyResourceGroup') do
|
||||
its('matcher') { should eq 'value' }
|
||||
end
|
||||
```
|
||||
|
||||
where
|
||||
|
||||
* `MyVm` is the name of the virtual machine as seen in Azure. (It is **not** the hostname of the machine)
|
||||
* `MyResourceGroup` is the name of the resouce group that the machine is in.
|
||||
* `matcher` is one of
|
||||
- `count` the number of data disks attached to the machine
|
||||
- `has_disks?` boolean test denoting if data disks are attached
|
||||
- `entries` used with the `where` filter to check the size of a disk
|
||||
* `value` is the expected output fdrom the matcher
|
||||
|
||||
## Matchers
|
||||
|
||||
This InSpec audit resource has the following matchers:
|
||||
|
||||
### eq
|
||||
|
||||
<%= partial "/shared/matcher_eq" %>
|
||||
|
||||
### count
|
||||
|
||||
Returns the number of data disks attached to the machine
|
||||
|
||||
```ruby
|
||||
its('count') { should eq 1 }
|
||||
```
|
||||
|
||||
### has_disks?
|
||||
|
||||
Returns a boolean denoting if any data disks are attached to the machine
|
||||
|
||||
```ruby
|
||||
its('has_disks?') { should be true }
|
||||
```
|
||||
|
||||
### entries
|
||||
|
||||
The `entries` filter can be used to check the attributes of indivdual data disks:
|
||||
|
||||
```ruby
|
||||
its('entries') { should_not be_empty }
|
||||
```
|
||||
|
||||
This matcher is best used in conjunction with filters. For example the following tests that the first data disk has a capacity greater than 10gb.
|
||||
|
||||
```ruby
|
||||
describe azure_virtual_machine_datadisks(name: 'MyVM', resource_group: 'MyResourceGroup').where { disk.zero? and size > 10 } do
|
||||
its('entries') { should_not be_empty }
|
||||
end
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
None
|
Loading…
Reference in a new issue