Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RESOURCE-110 Support availability group listeners sql vm #596

Merged
merged 6 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ The following is a list of static resources.
- [azure_sql_servers](https://docs.chef.io/inspec/resources/azure_sql_servers/)
- [azure_sql_virtual_machine](https://docs.chef.io/inspec/resources/azure_sql_virtual_machine.md)
- [azure_sql_virtual_machines](https://docs.chef.io/inspec/resources/azure_sql_virtual_machines.md)
- [azure_sql_virtual_machine_group_availability_listener](https://docs.chef.io/inspec/resources/azure_sql_virtual_machine_group_availability_listener.md)
- [azure_sql_virtual_machine_group_availability_listeners](https://docs.chef.io/inspec/resources/azure_sql_virtual_machine_group_availability_listeners.md)
- [azure_storage_account](https://docs.chef.io/inspec/resources/azure_storage_account/)
- [azure_storage_accounts](https://docs.chef.io/inspec/resources/azure_storage_accounts/)
- [azure_storage_account_blob_container](https://docs.chef.io/inspec/resources/azure_storage_account_blob_container/)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
title: About the azure_sql_virtual_machine_group_availability_listener Resource
platform: azure
---

# azure_sql_virtual_machine_group_availability_listener

Use the `azure_sql_virtual_machine_group_availability_listener` InSpec audit resource to test properties related to an Azure SQL virtual machine group availability listener.

## Azure REST API version, endpoint and http client parameters

This resource interacts with api versions supported by the resource provider.
The `api_version` can be defined as a resource parameter.
If not provided, the latest version will be used.
For more information, refer to [`azure_generic_resource`](azure_generic_resource.md).

Unless defined, `azure_cloud` global endpoint, and default values for the http client will be used.
For more information, refer to the resource pack [README](../../README.md).

## Availability

### Installation

This resource is available in the [InSpec Azure resource pack](https://github.com/inspec/inspec-azure).
For an example `inspec.yml` file and how to set up your Azure credentials, refer to resource pack [README](../../README.md#Service-Principal).

## Syntax

```ruby
describe azure_sql_virtual_machine_group_availability_listener(resource_group: 'RESOURCE_GROUP', sql_virtual_machine_group_name: 'SQL_VIRTUAL_MACHINE_GROUP_NAME', name: 'AVAILABILITY_LISTENER_NAME') do
it { should exist }
its('type') { should eq 'Microsoft.SqlVirtualMachine/sqlVirtualMachineGroups/availabilityGroupListeners' }
end
```

```ruby
describe azure_sql_virtual_machine_group_availability_listener(resource_group: 'RESOURCE_GROUP', sql_virtual_machine_group_name: 'SQL_VIRTUAL_MACHINE_GROUP_NAME', name: 'AVAILABILITY_LISTENER_NAME') do
it { should exist }
end
```

## Parameters

`name` _(required)_

Name of the Azure SQL virtual machine group availability listeners to test.

`resource_group` _(required)_

Azure resource group that the targeted resource resides in.

`sql_virtual_machine_group_name` _(required)_

The Azure SQL virtual machine group name

## Properties

| Property | Description |
|--------------------------|------------------------------------------------------------------|
| id | Resource ID. |
| name | Resource name. |
| type | Resource type. |
| properties | The properties of the SQL virtual machine group availability listener. |
| properties.provisioningState | State of the resource. |


For properties applicable to all resources, such as `type`, `name`, `id`, `properties`, refer to [`azure_generic_resource`](azure_generic_resource.md#properties).

Also, refer to [Azure documentation](https://docs.microsoft.com/en-us/rest/api/servicefabric/sfmeshrp-api-application_get) for other properties available.

## Examples

### Test that the SQL virtual machine group availability listener is provisioned successfully.

```ruby
describe azure_sql_virtual_machine_group_availability_listener(resource_group: 'RESOURCE_GROUP', sql_virtual_machine_group_name: 'SQL_VIRTUAL_MACHINE_GROUP_NAME', name: 'AVAILABILITY_LISTENER_NAME') do
its('properties.provisioningState') { should eq 'Succeeded' }
end
```

## Matchers

This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our [Universal Matchers page](/inspec/matchers/).

### exists

```ruby
# If a SQL virtual machine group availability listener is found it will exist
describe azure_sql_virtual_machine_group_availability_listener(resource_group: 'RESOURCE_GROUP', sql_virtual_machine_group_name: 'SQL_VIRTUAL_MACHINE_GROUP_NAME', name: 'AVAILABILITY_LISTENER_NAME') do
it { should exist }
end
# if SQL virtual machine group availability listener is not found it will not exist
describe azure_sql_virtual_machine_group_availability_listener(resource_group: 'RESOURCE_GROUP', sql_virtual_machine_group_name: 'SQL_VIRTUAL_MACHINE_GROUP_NAME', name: 'AVAILABILITY_LISTENER_NAME') do
it { should_not exist }
end
```

## Azure Permissions

Your [Service Principal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal) must be setup with a `reader` role on the subscription you wish to test.
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
title: About the azure_sql_virtual_machine_group_availability_listeners Resource
platform: azure
---

# azure_sql_virtual_machine_group_availability_listeners

Use the `azure_sql_virtual_machine_group_availability_listeners` InSpec audit resource to test properties related to all Azure SQL virtual machine group availability listeners.

## Azure REST API version, endpoint and http client parameters

This resource interacts with api versions supported by the resource provider.
The `api_version` can be defined as a resource parameter.
If not provided, the latest version will be used.
For more information, refer to [`azure_generic_resource`](azure_generic_resource.md).

Unless defined, `azure_cloud` global endpoint, and default values for the http client will be used.
For more information, refer to the resource pack [README](../../README.md).

## Availability

### Installation

This resource is available in the [InSpec Azure resource pack](https://github.com/inspec/inspec-azure).
For an example `inspec.yml` file and how to set up your Azure credentials, refer to resource pack [README](../../README.md#Service-Principal).

## Syntax

An `azure_sql_virtual_machine_group_availability_listeners` resource block returns all Azure SQL virtual machine group availability listeners.

```ruby
describe azure_sql_virtual_machine_group_availability_listeners(resource_group: 'RESOURCE_GROUP', sql_virtual_machine_group_name: 'SQL_VIRTUAL_MACHINE_GROUP_NAME') do
#...
end
```

## Parameters

`resource_group` _(required)_

Azure resource group that the targeted resource resides in.

`sql_virtual_machine_group_name` _(required)_

Azure SQL virtual machine group name

## Properties

|Property | Description | Filter Criteria<superscript>*</superscript> |
|--------------------------------|------------------------------------------------------------------------|------------------|
| ids | A list of resource IDs. | `id` |
| names | A list of resource names. | `name` |
| types | A list of the resource types. | `type` |
| properties | A list of Properties for all the SQL virtual machine group availability listeners. | `properties` |
| provisioningStates | A list of provisioning states of the SQL virtual machine group availability listeners. | `provisioningState`|

<superscript>*</superscript> For information on how to use filter criteria on plural resources refer to [FilterTable usage](https://github.com/inspec/inspec/blob/master/dev-docs/filtertable-usage.md).

## Examples

### Loop through SQL virtual machine group availability listeners by their names.

```ruby
azure_sql_virtual_machine_group_availability_listeners(resource_group: 'RESOURCE_GROUP', sql_virtual_machine_group_name: 'SQL_VIRTUAL_MACHINE_GROUP_NAME').names.each do |name|
describe azure_sql_virtual_machine_group_availability_listener(resource_group: 'RESOURCE_GROUP', sql_virtual_machine_group_name: 'SQL_VIRTUAL_MACHINE_GROUP_NAME', name: name) do
it { should exist }
end
end
```

### Test that there are SQL virtual machine group availability listeners that are successfully provisioned.

```ruby
describe azure_sql_virtual_machine_group_availability_listeners(resource_group: 'RESOURCE_GROUP', sql_virtual_machine_group_name: 'SQL_VIRTUAL_MACHINE_GROUP_NAME').where(provisioningState: 'Succeeded') do
it { should exist }
end
```

## Matchers

This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our [Universal Matchers page](https://www.inspec.io/docs/reference/matchers/).

### exists

```ruby
# Should not exist if no SQL virtual machine group availability listeners are present
describe azure_sql_virtual_machine_group_availability_listeners(resource_group: 'RESOURCE_GROUP', sql_virtual_machine_group_name: 'SQL_VIRTUAL_MACHINE_GROUP_NAME') do
it { should_not exist }
end
# Should exist if the filter returns at least one SQL virtual machine group availability listeners
describe azure_sql_virtual_machine_group_availability_listeners(resource_group: 'RESOURCE_GROUP', sql_virtual_machine_group_name: 'SQL_VIRTUAL_MACHINE_GROUP_NAME') do
it { should exist }
end
```

## Azure Permissions

Your [Service Principal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal) must be setup with a `reader` role on the subscription you wish to test.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'azure_generic_resource'

class AzureSQLVirtualMachineGroupAvailabilityListener < AzureGenericResource
name 'azure_sql_virtual_machine_group_availability_listener'
desc 'Retrieves and verifies the settings of an Azure SQL Virtual Machine Group Availability Listener.'
example <<-EXAMPLE
describe azure_sql_virtual_machine_group_availability_listener(resource_group: 'inspec-def-rg', sql_virtual_machine_group_name: 'inspec-sql-vm-group', name: 'inspec-avl') do
it { should exist }
end
EXAMPLE

def initialize(opts = {})
raise ArgumentError, 'Parameters must be provided in an Hash object.' unless opts.is_a?(Hash)

opts[:resource_provider] = specific_resource_constraint('Microsoft.SqlVirtualMachine/sqlVirtualMachineGroups', opts)
opts[:required_parameters] = %i(sql_virtual_machine_group_name)
opts[:resource_path] = "#{opts[:sql_virtual_machine_group_name]}/availabilityGroupListeners"
super(opts, true)
end

def to_s
super(AzureSQLVirtualMachineGroupAvailabilityListener)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'azure_generic_resources'

class AzureSQLVirtualMachineGroupAvailabilityListeners < AzureGenericResources
name 'azure_sql_virtual_machine_group_availability_listeners'
desc 'Verifies settings for a collection of Azure SQL Virtual Machine Group Availability Listeners'
example <<-EXAMPLE
describe azure_sql_virtual_machine_group_availability_listeners(resource_group: 'inspec-def-rg', sql_virtual_machine_group_name: 'inspec-sql-vm-group') do
it { should exist }
end
EXAMPLE

def initialize(opts = {})
raise ArgumentError, 'Parameters must be provided in an Hash object.' unless opts.is_a?(Hash)

opts[:resource_provider] = specific_resource_constraint('Microsoft.SqlVirtualMachine/sqlVirtualMachineGroups', opts)
opts[:required_parameters] = %i(sql_virtual_machine_group_name)
opts[:resource_path] = "#{opts[:sql_virtual_machine_group_name]}/availabilityGroupListeners"
super(opts, true)
return if failed_resource?

populate_filter_table_from_response
end

def to_s
super(AzureSQLVirtualMachineGroupAvailabilityListeners)
end

private

def populate_table
@resources.each do |resource|
@table << resource.merge(resource[:properties])
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rg = input(:resource_group, value: '')

control 'Verify the settings of an SQL VM Availability listener' do
describe azure_sql_virtual_machine_group_availability_listener(resource_group: rg, sql_virtual_machine_group_name: 'inspec-sql-vm-group', name: 'inspec-avl') do
it { should exist }
its('type') { should eq 'Microsoft.SqlVirtualMachine/sqlVirtualMachineGroups/availabilityGroupListeners' }
its('properties.provisioningState') { should eq ' Succeeded' }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rg = input(:resource_group, value: '')

control 'Verify the settings of a collection of all SQL VM Availability listeners' do
describe azure_sql_virtual_machine_group_availability_listeners(resource_group: rg, sql_virtual_machine_group_name: 'inspec-sql-vm-group') do
it { should exist }
its('types') { should include 'Microsoft.SqlVirtualMachine/sqlVirtualMachineGroups/availabilityGroupListeners' }
its('provisioningStates') { should include ' Succeeded' }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require_relative 'helper'
require 'azure_sql_virtual_machine_group_availability_listener'

class AzureSQLVirtualMachineGroupAvailabilityListenerConstructorTest < Minitest::Test
def test_empty_param_not_ok
assert_raises(ArgumentError) { AzureSQLVirtualMachineGroupAvailabilityListener.new }
end

# resource_provider should not be allowed.
def test_resource_provider_not_ok
assert_raises(ArgumentError) { AzureSQLVirtualMachineGroupAvailabilityListener.new(resource_provider: 'some_type') }
end

def test_resource_group_name_alone_not_ok
assert_raises(ArgumentError) { AzureSQLVirtualMachineGroupAvailabilityListener.new(resource_group: 'test') }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative 'helper'
require 'azure_sql_virtual_machine_group_availability_listeners'

class AzureSQLVirtualMachineGroupAvailabilityListenersConstructorTest < Minitest::Test
# resource_type should not be allowed.
def test_resource_type_not_ok
assert_raises(ArgumentError) { AzureSQLVirtualMachineGroupAvailabilityListeners.new(resource_provider: 'some_type') }
end

def tag_value_not_ok
assert_raises(ArgumentError) { AzureSQLVirtualMachineGroupAvailabilityListeners.new(tag_value: 'some_tag_value') }
end

def tag_name_not_ok
assert_raises(ArgumentError) { AzureSQLVirtualMachineGroupAvailabilityListeners.new(tag_name: 'some_tag_name') }
end

def test_name_not_ok
assert_raises(ArgumentError) { AzureSQLVirtualMachineGroupAvailabilityListeners.new(name: 'some_name') }
end
end