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

F/express route circuit connections #427

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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 @@ -218,6 +218,8 @@ The following is a list of static resources.
- [azure_webapps](docs/resources/azure_webapps.md)
- [azure_bastion_hosts_resource](docs/resources/azure_bastion_hosts_resource.md)
- [azure_bastion_hosts_resources](docs/resources/azure_bastion_hosts_resources.md)
- [azure_express_route_circuit_connections_resource](docs/resources/azure_express_route_circuit_connections_resource.md)
- [azure_express_route_circuit_connections_resources](docs/resources/azure_express_route_circuit_connections_resources.md)

For more details and different use cases, please refer to the specific resource pages.

Expand Down
114 changes: 114 additions & 0 deletions docs/resources/azure_express_route_circuit_connections_resource.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
title: About the azure_express_route_circuit_connections_resource Resource
platform: azure
---

# azure_express_route_circuit_connections_resource

Use the `azure_express_route_circuit_connections_resource` InSpec audit resource to test properties related to a express circuit resource.

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



Also, refer to [Azure documentation](https://docs.microsoft.com/en-us/rest/api/expressroute/express-route-circuit-connections/get) for properties available.
Any attribute in the response may be accessed with the key names separated by dots (`.`).
## Syntax

```ruby
describe azure_express_route_circuit_connections_resource(resource_group: 'example', circuit_name: 'cn', peering_name: 'pn', connection_name: 'cn') do
it { should exist }
end
```
## Parameters

| Name | Description |
|--------------------------------|----------------------------------------------------------------------------------|
| resource_group | Azure resource group that the targeted resource resides in. `MyResourceGroup` |
| circuit_name | Name of the Express route circuit to test. `circuit_name` |
| peering_name | Name of the peering to test. `peering_name` |
| connection_name | The name of the express route circuit connection. `connection_name` |

All of the parameter sets should be provided for a valid query:
- `resource_group`, `circuit_name`, `peering_name`, `connection_name`

## Properties

| Name | Description |
|--------------------------------|----------------------------------------------------------------------------------|
| resource_group | The name of the resource group in which to create the ExpressRoute circuit. Changing this forces a new resource to be created. `MyResourceGroup` |
| name | The name of the ExpressRoute circuit. Changing this forces a new resource to be created. `Myexpress circuitHostName` |
| type | type of express ExpressRoute circuit |
| provisioning_state | State of express ExpressRoute circuit creation |
| location | Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. |
| circuit_connection_status | Express Route Circuit connection state. |
| ipv6_circuit_connection_config_status | IPv6 Address PrefixProperties of the express route circuit connection i.e Express Route Circuit connection state. |


Also, refer to [Azure documentation](https://docs.microsoft.com/en-us/rest/api/expressroute/express-route-circuits/get) for other properties available.
Any attribute in the response may be accessed with the key names separated by dots (`.`).


## Examples

### Ensure that the express circuit resource has is from same type
```ruby
describe azure_express_route_circuit_connections_resource(resource_group: 'example', circuit_name: 'cn', peering_name: 'pn', connection_name: 'cn') do
its('type') { should eq 'Microsoft.Network/expressRouteCircuits' }
end
```
### Ensure that the express circuit resource is in successful state
```ruby
describe azure_express_route_circuit_connections_resource(resource_group: 'example', circuit_name: 'cn', peering_name: 'pn', connection_name: 'cn') do
its('provisioning_state') { should include('Succeeded') }
end
```

### Ensure that the express circuit resource is from same location
```ruby
describe azure_express_route_circuit_connections_resource(resource_group: 'example', circuit_name: 'cn', peering_name: 'pn', connection_name: 'cn') do
its('location') { should include df_location }
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/).
```ruby
describe azure_express_route_circuit_connections_resource(resource_group: 'example', circuit_name: 'cn', peering_name: 'pn', connection_name: 'cn') do
its('provisioning_state') { should eq 'Succeeded' }
its('ipv6_circuit_connection_config_status') { should eq 'Connected' }
its('circuit_connection_status') { should eq 'Connected' }
end
```

### exists
```ruby
# If a express circuit resource is found it will exist
describe azure_express_route_circuit_connections_resource(resource_group: 'example', circuit_name: 'cn', peering_name: 'pn', connection_name: 'cn') do
it { should exist }
end

# express circuit resources that aren't found will not exist
describe azure_express_route_circuit_connections_resource(resource_group: 'example', circuit_name: 'cn', peering_name: 'pn', connection_name: 'does_not_exist') 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 `contributor` role on the subscription you wish to test.
110 changes: 110 additions & 0 deletions docs/resources/azure_express_route_circuit_connections_resources.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---
title: About the azure_express_route_circuit_connections_resources Resource
platform: azure
---

# azure_express_route_circuit_connections_resources

Use the `azure_express_route_circuit_connections_resources` InSpec audit resource to test properties related to express_route_circuits for a resource group or the entire subscription.

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


Also, refer to [Azure documentation](https://docs.microsoft.com/en-us/rest/api/expressroute/express-route-circuit-connections/list) for properties available.
Any attribute in the response may be accessed with the key names separated by dots (`.`).
## Syntax

An `azure_express_route_circuit_connections_resources` resource block returns all Azure express route circuits, either within a Resource Group (if provided)
```ruby
describe azure_express_route_circuit_connections_resources(resource_group: 'rg', circuit_name: 'cn', peering_name: 'pn') do

end
```
## Parameters

| Name | Description |
|--------------------------------|----------------------------------------------------------------------------------|
| resource_group | Azure resource group that the targeted resource resides in. `MyResourceGroup` |
| circuit_name | The name of the express route circuit to test. `circuit_name` |
| peering_name | Name of the peering to test. `peering_name` |


All of the parameter sets should be provided for a valid query:
- `resource_group`, `circuit_name`, `peering_name`

## Properties

|Property | Description | Filter Criteria<superscript>*</superscript> |
|---------------|--------------------------------------------------------------------------------------|-----------------|
| names | A list of name the resource group in which to create the ExpressRoute circuit. Changing this forces a new resource to be created. `MyResourceGroup` | `name` |
| ids | A list of id the ExpressRoute circuit. Changing this forces a new resource to be created. `Myexpress circuitHostName | `id` |
| tags | A list of `tag:value` pairs defined on the resources. | `tags` |
| provisioning_states | State of express_route_circuits creation | `provisioning_state` |
| types | Types of all the express_route_circuits | `type` |
| locations | Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. | `location` |
| circuit_connection_status| Express Route Circuit connection state. | `circuit_connection_status`|
| ipv6_circuit_connection_config_status |IPv6 Address PrefixProperties of the express route circuit connection.| `ipv6_circuit_connection_config_status` |
| properties| The properties of Resource. | `properties` |
<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

### Ensure that the express_route_circuits resource is in successful state
```ruby
describe azure_express_route_circuit_connections_resources(resource_group: 'rg', circuit_name: 'cn', peering_name: 'pn') do
its('provisioning_states') { should include('Succeeded') }
end
```

### Ensure that the express_route_circuits resource is from same location
```ruby
describe azure_express_route_circuit_connections_resources(resource_group: 'rg', circuit_name: 'cn', peering_name: 'pn') do
its('location') { should include df_location }
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/).
```ruby
describe azure_express_route_circuit_connections_resources(resource_group: 'rg', circuit_name: 'cn', peering_name: 'pn') do
its('names') { should include circuitName }
its('locations') { should include location }
its('types') { should include 'Microsoft.Network/expressRouteCircuits' }
its('provisioning_states') { should include('Succeeded') }
its('circuit_connection_status') { should include('Connected') }
its('ipv6_circuit_connection_config_status') { should include('Connected') }
end
```


### exists
```ruby
# Should exist if express_route_circuits are in the resource group
describe azure_express_route_circuit_connections_resources(resource_group: 'rg', circuit_name: 'cn', peering_name: 'pn') do
it { should exist }
end
# Should not exist if no express_route_circuits are in the resource group
describe azure_express_route_circuit_connections_resources(resource_group: 'rg', circuit_name: 'cn', peering_name: 'should_not_exist') 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 `contributor` role on the subscription you wish to test.
69 changes: 69 additions & 0 deletions libraries/azure_express_route_circuit_connections_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require 'azure_generic_resource'

class AzureExpressRouteCircuitConnectionsResource < AzureGenericResource
name 'azure_express_route_circuit_connections_resource'
desc 'ExpressRoute circuit connect your on-premises infrastructure to Microsoft through a connectivity provider'
example <<-EXAMPLE
describe azure_express_route_circuit_connections_resource(resource_group: 'example', circuit_name: 'cn', peering_name: 'pn', connection_name: 'cn') do
it { should exist }
end
EXAMPLE

def initialize(opts = {})
# Options should be Hash type. Otherwise Ruby will raise an error when we try to access the keys.
raise ArgumentError, 'Parameters must be provided in an Hash object.' unless opts.is_a?(Hash)

# Azure REST API endpoint URL format for the resource:
# GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
# providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/
# connections/{connectionName}?api-version=2021-02-01
#
# The dynamic part that has to be created in this resource:
# Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/
# connections/{connectionName}?api-version=2021-02-01
#
# Parameters acquired from environment variables:
# - {subscriptionId} => Required parameter. It will be acquired by the backend from environment variables.
#
# User supplied parameters:
# - resource_group => Required parameter unless `resource_id` is provided. {resourceGroupName}
# - name => Required parameter unless `resource_id` is provided. ExpressRouteCircuit name. {vmName}
# - resource_id => Optional parameter. If exists, `resource_group` and `name` must not be provided.
# In the following format:
# /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
# providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/
# connections/{connectionName}
# - api_version => Optional parameter. The latest version will be used unless provided. api-version
#
# **`resource_group` and (resource) `name` or `resource_id` will be validated in the backend appropriately.
# We don't have to do anything here.
#
# Following resource parameters have to be defined here.
# - resource_provider => Microsoft.Network/expressRouteCircuits
# The `specific_resource_constraint` method will validate the user input
# not to accept a different `resource_provider`.
#
opts[:resource_provider] = specific_resource_constraint('Microsoft.Network/expressRouteCircuits', opts)
opts[:required_parameters] = %i(circuit_name peering_name)
opts[:resource_path] = [opts[:circuit_name], 'peerings', opts[:peering_name], 'connections'].join('/')
opts[:resource_identifiers] = %i(connection_name)
# static_resource parameter must be true for setting the resource_provider in the backend.
super(opts, true)
end

def to_s
super(AzureExpressRouteCircuitConnectionsResource)
end

def provisioning_state
properties.provisioningState if exists?
end

def circuit_connection_status
properties.circuitConnectionStatus if exists?
end

def ipv6_circuit_connection_config_status
properties.ipv6CircuitConnectionConfig.circuitConnectionStatus
end
end
Loading