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-115 Support azure service fabric mesh network #582

Merged
merged 9 commits into from
Mar 12, 2022
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ The following is a list of static resources.
- [azure_security_center_policies](docs/resources/azure_security_center_policies.md)
- [azure_sentinel_alert_rule_template](docs/resources/azure_sentinel_alert_rule_template.md)
- [azure_sentinel_alert_rule_templates](docs/resources/azure_sentinel_alert_rule_templates.md)
- [azure_service_fabric_mesh_network](docs/resources/azure_service_fabric_mesh_network.md)
- [azure_service_fabric_mesh_networks](docs/resources/azure_service_fabric_mesh_networks.md)
- [azure_sql_database](docs/resources/azure_sql_database.md)
- [azure_sql_databases](docs/resources/azure_sql_databases.md)
- [azure_sql_server](docs/resources/azure_sql_server.md)
Expand Down
101 changes: 101 additions & 0 deletions docs/resources/azure_service_fabric_mesh_network.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
title: About the azure_service_fabric_mesh_network Resource
platform: azure
---

# azure_service_fabric_mesh_network

Use the `azure_service_fabric_mesh_network` InSpec audit resource to test properties related to an Azure Service Fabric Mesh Network.

## 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

`name`, `resource_group` is a required parameter.

```ruby
describe azure_service_fabric_mesh_network(resource_group: 'RESOURCE_GROUP', name: 'SERVICE_FABRIC_MESH_NETWORK_NAME') do
it { should exist }
its('type') { should eq 'Microsoft.ServiceFabricMesh/networks' }
its('location') { should eq 'eastus' }
end
```

```ruby
describe azure_service_fabric_mesh_network(resource_group: 'RESOURCE_GROUP', name: 'SERVICE_FABRIC_MESH_NETWORK_NAME') do
it { should exist }
end
```
## Parameters

| Name | Description |
|----------------|----------------------------------------------------------------------------------|
| name | Name of the Azure Service Fabric Mesh Networks to test. |
| resource_group | Azure resource group that the targeted resource resides in. `MyResourceGroup` |

The parameter set should be provided for a valid query:
- `resource_group` and `name`

## Properties

| Property | Description |
|--------------------------|------------------------------------------------------------------|
| id | Resource Id. |
| name | Resource name. |
| type | Resource type. `Microsoft.ServiceFabricMesh/networks` |
| location | The Geo-location where the resource lives. |
| properties | The properties of the Service Fabric Mesh Network. |
| properties.addressPrefix | the address prefix for this network. |
| properties.provisioningState | State of the resource. |
| properties.ingressConfig.qosLevel | The QoS tier for ingress. |


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-network_get) for other properties available.

## Examples

### Test that the Service Fabric Mesh Network is provisioned successfully.

```ruby
describe azure_service_fabric_mesh_network(resource_group: 'RESOURCE_GROUP', name: 'SERVICE_FABRIC_MESH_NETWORK_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 Service Fabric Mesh Network is found it will exist
describe azure_service_fabric_mesh_network(resource_group: 'RESOURCE_GROUP', name: 'SERVICE_FABRIC_MESH_NETWORK_NAME') do
it { should exist }
end
# if Service Fabric Mesh Network is not found it will not exist
describe azure_service_fabric_mesh_network(resource_group: 'RESOURCE_GROUP', name: 'SERVICE_FABRIC_MESH_NETWORK_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.
96 changes: 96 additions & 0 deletions docs/resources/azure_service_fabric_mesh_networks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
title: About the azure_service_fabric_mesh_networks Resource
platform: azure
---

# azure_service_fabric_mesh_networks

Use the `azure_service_fabric_mesh_networks` InSpec audit resource to test properties related to all Azure Service Fabric Mesh Networks.

## 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_service_fabric_mesh_networks` resource block returns all Azure Service Fabric Mesh Networks.

```ruby
describe azure_service_fabric_mesh_networks do
#...
end
```

## Parameters
| Name | Description |
|----------------|----------------------------------------------------------------------------------|
| resource_group | Azure resource group that the targeted resource resides in. `MyResourceGroup` (Optional) |

The parameter set optionally be provided for a valid query:
- `resource_group`

## 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 Service Fabric Mesh Networks. | `properties` |
| locations | A list of the Geo-locations. | `location` |
| provisioningStates | A list of provisioning states of the Service Fabric Mesh Networks. | `provisioningState`|
| addressPrefixes | A list of address prefixes. | `addressPrefix` |

<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 Service Fabric Mesh Networks by their names.

```ruby
azure_service_fabric_mesh_networks(resource_group: 'RESOURCE_GROUP').names.each do |name|
describe azure_service_fabric_mesh_network(resource_group: 'RESOURCE_GROUP', name: name) do
it { should exist }
end
end
```
### Test that there are Service Fabric Mesh Networks that are successfully provisioned.

```ruby
describe azure_service_fabric_mesh_networks(resource_group: 'RESOURCE_GROUP').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 Service Fabric Mesh Networks are present
describe azure_service_fabric_mesh_networks(resource_group: 'RESOURCE_GROUP') do
it { should_not exist }
end
# Should exist if the filter returns at least one Service Fabric Mesh Networks
describe azure_service_fabric_mesh_networks(resource_group: 'RESOURCE_GROUP') 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.
22 changes: 22 additions & 0 deletions libraries/azure_service_fabric_mesh_network.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'azure_generic_resource'

class AzureServiceFabricMeshNetwork < AzureGenericResource
name 'azure_service_fabric_mesh_network'
desc 'Retrieves and verifies the settings of an Azure Service Fabric Mesh Network.'
example <<-EXAMPLE
describe azure_service_fabric_mesh_network(resource_group: 'inspec-rg', name: 'fabric-vol') 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.ServiceFabricMesh/networks', opts)
super(opts, true)
end

def to_s
super(AzureServiceFabricMeshNetwork)
end
end
33 changes: 33 additions & 0 deletions libraries/azure_service_fabric_mesh_networks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'azure_generic_resources'

class AzureServiceFabricMeshNetworks < AzureGenericResources
name 'azure_service_fabric_mesh_networks'
desc 'Verifies settings for a collection of Azure Service Fabric Mesh Networks'
example <<-EXAMPLE
describe azure_service_fabric_mesh_networks 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.ServiceFabricMesh/networks', opts)
super(opts, true)
return if failed_resource?

populate_filter_table_from_response
end

def to_s
super(AzureServiceFabricMeshNetworks)
end

private

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

control 'test the properties of all Azure Service Fabric Mesh Networks' do
soumyo13 marked this conversation as resolved.
Show resolved Hide resolved
describe azure_service_fabric_mesh_networks(resource_group: rg, name: 'mesh-fabric-name') do
it { should exist }
its('location') { should eq location.downcase.gsub("\s", '') }
its('addressPrefix') { should eq '10.0.0.4/22' }
its('provisioningState') { should eq 'Succeeded' }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
location = input(:location, value: '')

control 'test the properties of all Azure Service Fabric Mesh Networks' do
soumyo13 marked this conversation as resolved.
Show resolved Hide resolved
describe azure_service_fabric_mesh_networks do
it { should exist }
its('names') { should include 'inspec-fb-mesh-vol' }
its('locations') { should include location.downcase.gsub("\s", '') }
its('addressPrefixes') { should include '10.0.0.4/22' }
its('provisioningStates') { should include 'Succeeded' }
end
end
17 changes: 17 additions & 0 deletions test/unit/resources/azure_service_fabric_mesh_network_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require_relative 'helper'
require 'azure_service_fabric_mesh_network'

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

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

def test_resource_group_name_alone_not_ok
assert_raises(ArgumentError) { AzureServiceFabricMeshNetwork.new(resource_group: 'test') }
end
end
21 changes: 21 additions & 0 deletions test/unit/resources/azure_service_fabric_mesh_networks_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative 'helper'
require 'azure_service_fabric_mesh_networks'

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

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

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

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