From 2f2cea68ae48ca3edaba62db8447158b91039f30 Mon Sep 17 00:00:00 2001 From: sa-progress Date: Mon, 9 Aug 2021 13:25:04 +0530 Subject: [PATCH 1/5] initial commit --- ...ress_route_circuit_connections_resource.md | 135 ++++++++++++++++++ ...ess_route_circuit_connections_resources.md | 120 ++++++++++++++++ 2 files changed, 255 insertions(+) create mode 100644 docs/resources/azure_express_route_circuit_connections_resource.md create mode 100644 docs/resources/azure_express_route_circuit_connections_resources.md diff --git a/docs/resources/azure_express_route_circuit_connections_resource.md b/docs/resources/azure_express_route_circuit_connections_resource.md new file mode 100644 index 000000000..05852ee07 --- /dev/null +++ b/docs/resources/azure_express_route_circuit_connections_resource.md @@ -0,0 +1,135 @@ +--- +title: About the azure_express_route_circuit Resource +platform: azure +--- + +# azure_express_route_circuit + +Use the `azure_express_route_circuit` 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). + +## Syntax + +`resource_group` and express circuit resource `name` or the `resource_id` must be given as a parameter. +```ruby +describe azure_express_route_circuit(resource_group: 'MyResourceGroup', name: 'express circuit_name') 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 circuit test. `circuit_name` | + +Both of the parameter sets should be provided for a valid query: +- `resource_group` and `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. | +| service_provider_properties_bandwidth_in_mbps | The bandwidth in Mbps of the circuit being created on the Service Provider. | +| service_provider_properties_peering_location | The name of the peering location and not the Azure resource location. Changing this forces a new resource to be created. | +| service_provider_properties_name | The name of the ExpressRoute Service Provider. Changing this forces a new resource to be created. | +| service_provider_provisioning_state | The ExpressRoute circuit provisioning state from your chosen service provider. Possible values are "NotProvisioned", "Provisioning", "Provisioned", and "Deprovisioning". | +| service_key | State of express circuitHostName creation | +| stag | The identifier of the circuit traffic. Outer tag for QinQ encapsulation. | +| global_reach_enabled | ExpressRoute circuit allowGlobalReachEnable `boolean` | +| allow_global_reach | ExpressRoute circuit Flag denoting global reach status. `boolean` | +| gateway_manager_etag | The GatewayManager Etag. | +| allow_classic_operations | Allow classic operations. `boolean` | +| circuit_provisioning_state | State of express circuitHostName creation | +| sku_name | Name sku block for the ExpressRoute circuit as documented below. | +| sku_tier | The service tier. Possible values are Basic, Local, Standard or Premium. | +| sku_family | The billing mode for bandwidth. Possible values are MeteredData or UnlimitedData. | +Both of the parameter sets should be provided for a valid query: +- `resource_group` and `circuit_name` + + +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(resource_group: 'MyResourceGroup', name: 'express circuit_name') 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(resource_group: 'MyResourceGroup', name: 'express circuit_name') do + its('provisioning_state') { should include('Succeeded') } +end +``` + +### Ensure that the express circuit resource is from same location +```ruby +describe azure_express_route_circuit(resource_group: 'MyResourceGroup', name: 'circuit_name') 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(resource_group: 'MyResourceGroup', name: 'mycircuit_name') do + it { should exist } + its('service_provider_properties_bandwidth_in_mbps') { should eq bandwidthInMbps } + its('service_provider_properties_peering_location') { should include peeringLocation } + its('service_provider_properties_name') { should include serviceProviderName } + its('service_provider_provisioning_state') { should include serviceProviderProvisioningState } + its('service_key') { should include serviceKey } + its('stag') { should eq stag } + its('global_reach_enabled') { should eq globalReachEnabled } + its('allow_global_reach') { should eq allowGlobalReach } + its('gateway_manager_etag') { should include gatewayManagerEtag } + its('allow_classic_operations') { should eq allowClassicOperations } + its('circuit_provisioning_state') { should include circuitProvisioningState } + its('sku_name') { should include sku_name } + its('sku_tier') { should include sku_tier } + its('sku_family') { should include sku_family } +end +``` + +### exists +```ruby +# If a express circuit resource is found it will exist +describe azure_express_route_circuit(resource_group: 'MyResourceGroup', name: 'mycircuit_name') do + it { should exist } +end + +# express circuit resources that aren't found will not exist +describe azure_express_route_circuit(resource_group: 'MyResourceGroup', name: 'DoesNotExist') 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. \ No newline at end of file diff --git a/docs/resources/azure_express_route_circuit_connections_resources.md b/docs/resources/azure_express_route_circuit_connections_resources.md new file mode 100644 index 000000000..206fc6f7d --- /dev/null +++ b/docs/resources/azure_express_route_circuit_connections_resources.md @@ -0,0 +1,120 @@ +--- +title: About the azure_express_route_circuits Resource +platform: azure +--- + +# azure_express_route_circuits + +Use the `azure_express_route_circuits` 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-circuits/list) for properties available. +Any attribute in the response may be accessed with the key names separated by dots (`.`). +## Syntax + +An `azure_express_route_circuits` resource block returns all Azure express route circuits, either within a Resource Group (if provided) +```ruby +describe azure_express_route_circuits(resource_group: 'my-rg') do + +end +``` + +## Properties + +|Property | Description | Filter Criteria* | +|---------------|--------------------------------------------------------------------------------------|-----------------| +| 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` | +| service_provider_bandwidth_in_mbps | A list of The bandwidth in Mbps of the circuit being created on the Service Provider. | `service_provider_bandwidth_in_mbps` | +| service_provider_peering_locations | A list of The name of the peering location and not the Azure resource location. Changing this forces a new resource to be created. | `service_provider_peering_location` | +| service_provider_names | The name of the ExpressRoute Service Provider. Changing this forces a new resource to be created. | `service_provider_name` | +| service_keys | State of express circuitHostName creation | `service_key` | +| stags | The identifier of the circuit traffic. Outer tag for QinQ encapsulation. `Number` | `stag` | +| global_reach_enabled | A list of The ExpressRoute circuit allowGlobalReachEnable `boolean` `boolean`| `global_reach_enabled` | +| gateway_manager_etags | A list of The GatewayManager Etag. | `gateway_manager_etag` | +| allow_classic_operations | A list of Allow classic operations. `boolean` | `allow_classic_operation` | +| circuit_provisioning_states | A list of State of express circuitHostName creation `Enabled` or `Disabled` | `circuit_provisioning_state` | +| sku_names | A List of Name sku block for the ExpressRoute circuit as documented below. | `sku_name` | +| sku_tiers | A List of The service tier. Possible values are Basic, Local, Standard or Premium. | `sku_tier` | +| sku_family | A List of The billing mode for bandwidth. Possible values are MeteredData or UnlimitedData. | `sku_family` | +* 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_circuits(resource_group: 'MyResourceGroup') do + its('provisioning_states') { should include('Succeeded') } +end +``` + +### Ensure that the express_route_circuits resource is from same location +```ruby +describe azure_express_route_circuits(resource_group: 'MyResourceGroup') 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_circuits(resource_group: 'MyResourceGroup') 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('service_provider_properties_bandwidth_in_mbps') { should include bandwidthInMbps } + its('service_provider_properties_peering_locations') { should include peeringLocation } + its('service_provider_properties_names') { should include serviceProviderName } + its('service_provider_provisioning_states') { should include serviceProviderProvisioningState } + its('service_keys') { should include serviceKey } + its('stags') { should include stag } + its('global_reach_enabled') { should include globalReachEnabled } + its('allow_global_reach') { should include allowGlobalReach } + its('gateway_manager_etags') { should include gatewayManagerEtag } + its('allow_classic_operations') { should include allowClassicOperations } + its('circuit_provisioning_states') { should include circuitProvisioningState } + its('sku_names') { should include sku_name } + its('sku_tiers') { should include sku_tier } + its('sku_families') { should include sku_family } +end +``` + + +### exists +```ruby +# Should exist if express_route_circuits are in the resource group +describe azure_express_route_circuits(resource_group: 'MyResourceGroup') do + it { should exist } +end +# Should not exist if no express_route_circuits are in the resource group +describe azure_express_route_circuits(resource_group: 'MyResourceGroup') 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. \ No newline at end of file From 79a78a65cad61a78dc17e89c66c7765913137eb4 Mon Sep 17 00:00:00 2001 From: sa-progress Date: Mon, 9 Aug 2021 13:25:21 +0530 Subject: [PATCH 2/5] initial commit --- ...ress_route_circuit_connections_resource.rb | 69 ++++++++++ ...ess_route_circuit_connections_resources.rb | 119 ++++++++++++++++++ ...ress_route_circuit_connections_resource.rb | 47 +++++++ ...ess_route_circuit_connections_resources.rb | 37 ++++++ ...route_circuit_connections_resource_test.rb | 17 +++ ...oute_circuit_connections_resources_test.rb | 25 ++++ 6 files changed, 314 insertions(+) create mode 100644 libraries/azure_express_route_circuit_connections_resource.rb create mode 100644 libraries/azure_express_route_circuit_connections_resources.rb create mode 100644 test/integration/verify/controls/azure_express_route_circuit_connections_resource.rb create mode 100644 test/integration/verify/controls/azure_express_route_circuit_connections_resources.rb create mode 100644 test/unit/resources/azure_express_route_circuit_connections_resource_test.rb create mode 100644 test/unit/resources/azure_express_route_circuit_connections_resources_test.rb diff --git a/libraries/azure_express_route_circuit_connections_resource.rb b/libraries/azure_express_route_circuit_connections_resource.rb new file mode 100644 index 000000000..5df43fb03 --- /dev/null +++ b/libraries/azure_express_route_circuit_connections_resource.rb @@ -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', circuitName: 'circuitName') 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_provisioning_state + properties.provisioningState if exists? + end + + def ipv6_circuit_connection_config_status + properties.ipv6CircuitConnectionConfig.circuitConnectionStatus + end +end diff --git a/libraries/azure_express_route_circuit_connections_resources.rb b/libraries/azure_express_route_circuit_connections_resources.rb new file mode 100644 index 000000000..03163f106 --- /dev/null +++ b/libraries/azure_express_route_circuit_connections_resources.rb @@ -0,0 +1,119 @@ +require 'azure_generic_resources' + +class AzureExpressRouteCircuits < AzureGenericResources + name 'azure_express_route_circuits' + desc 'ExpressRoute circuits connect your on-premises infrastructure to Microsoft through a connectivity provider' + example <<-EXAMPLE + describe azure_express_route_circuits(resource_group: 'example') do + it{ should exist } + end + EXAMPLE + + attr_reader :table + + 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 listing the all resources for a given subscription: + # GET https://management.azure.com/subscriptions/{subscriptionId}/providers/ + # Microsoft.Network/expressRouteCircuits?api-version=2020-11-01 + # + # + # The dynamic part that has to be created for this resource: + # Microsoft.Network/expressRouteCircuits?api-version=2019-12-01 + # + # Parameters acquired from environment variables: + # - {subscriptionId} => Required parameter. It will be acquired by the backend from environment variables. + # + # For parameters applicable to all resources, see project's README. + # + # User supplied parameters: + # - resource_group => Optional parameter. + # - api_version => Optional parameter. The latest version will be used unless provided. + # + # **`resource_group` will be used in the backend appropriately. + # We don't have to do anything here. + # + # Following resource parameters have to be defined/created 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) + + # static_resource parameter must be true for setting the resource_provider in the backend. + super(opts, true) + + # Check if the resource is failed. + # It is recommended to check that after every usage of superclass methods or API calls. + return if failed_resource? + + # Define the column and field names for FilterTable. + # - column: It is defined as an instance method, callable on the resource, and present `field` values in a list. + # - field: It has to be identical with the `key` names in @table items that will be presented in the FilterTable. + # @see https://github.com/inspec/inspec/blob/master/docs/dev/filtertable-usage.md + table_schema = [ + { column: :ids, field: :id }, + { column: :names, field: :name }, + { column: :locations, field: :location }, + { column: :types, field: :type }, + { column: :tags, field: :tags }, + { column: :provisioning_states, field: :provisioning_state }, + { column: :sku_names, field: :sku_name }, + { column: :sku_tiers, field: :sku_tier }, + { column: :sku_families, field: :sku_family }, + { column: :circuit_provisioning_states, field: :circuit_provisioning_state }, + { column: :allow_classic_operations, field: :allow_classic_operations }, + { column: :gateway_manager_etags, field: :gateway_manager_etag }, + { column: :service_keys, field: :serviceKey }, + { column: :global_reach_enabled, field: :global_reach_enabled }, + { column: :stags, field: :stag }, + { column: :service_provider_names, field: :service_provider_name }, + { column: :service_provider_peering_locations, field: :service_provider_peering_location }, + { column: :service_provider_bandwidth_in_mbps, field: :service_provider_bandwidth_in_mbps }, + ] + # FilterTable is populated at the very end due to being an expensive operation. + AzureGenericResources.populate_filter_table(:table, table_schema) + end + + def to_s + super(AzureExpressRouteCircuits) + end + + private + + # Populate the @table with the resource attributes. + # @table has been declared in the super class as an empty array. + # Each item in the @table + # - should be a Hash object + # - should have the exact key names defined in the @table_schema as `field`. + def populate_table + # If @resources empty than @table should stay as an empty array as declared in superclass. + # This will ensure constructing resource and passing `should_not exist` test. + return [] if @resources.empty? + + @resources.each do |resource| + @table << { + id: resource[:id], + name: resource[:name], + location: resource[:location], + type: resource[:type], + tags: resource[:tags], + provisioning_state: resource[:properties][:provisioningState], + sku_name: resource[:sku][:name], + sku_tier: resource[:sku][:tier], + sku_family: resource[:sku][:family], + circuit_provisioning_state: resource[:properties][:circuitProvisioningState], + allow_classic_operations: resource[:properties][:allowClassicOperations], + gateway_manager_etag: resource[:properties][:gatewayManagerEtag], + serviceKey: resource[:properties][:serviceKey], + global_reach_enabled: resource[:properties][:globalReachEnabled], + stag: resource[:properties][:stag], + service_provider_name: resource[:properties][:serviceProviderProperties][:serviceProviderName], + service_provider_peering_location: resource[:properties][:serviceProviderProperties][:peeringLocation], + service_provider_bandwidth_in_mbps: resource[:properties][:serviceProviderProperties][:bandwidthInMbps], + } + end + end +end \ No newline at end of file diff --git a/test/integration/verify/controls/azure_express_route_circuit_connections_resource.rb b/test/integration/verify/controls/azure_express_route_circuit_connections_resource.rb new file mode 100644 index 000000000..1d254afe0 --- /dev/null +++ b/test/integration/verify/controls/azure_express_route_circuit_connections_resource.rb @@ -0,0 +1,47 @@ +resource_group = input('resource_group', value: nil) +circuit_name = input('circuitName', value: nil) +location = input('circuitLocation', value: nil) +global_reach_enabled = input('globalReachEnabled', value: false) +allow_global_reach = input('allowGlobalReach', value: false) +service_provider_provisioning_state = input('serviceProviderProvisioningState', value: nil) +gateway_manager_etag = input('gatewayManagerEtag', value: '') +allow_classic_operations = input('allowClassicOperations', value: false) +circuit_provisioning_state = input('circuitProvisioningState', value: nil) + +bandwidth_in_mbps = input('bandwidthInMbps', value: nil) +peering_location = input('peeringLocation', value: nil) +service_provider_name = input('serviceProviderName', value: nil) + +sku_name = input('sku_name', value: nil) +sku_tier = input('sku_tier', value: nil) +sku_family = input('sku_family', value: nil) + +control 'azure_express_route_circuit' do + describe azure_express_route_circuit(resource_group: resource_group, circuit_name: circuit_name) do + it { should exist } + its('name') { should eq circuit_name } + its('type') { should eq 'Microsoft.Network/expressRouteCircuits' } + its('provisioning_state') { should include('Succeeded') } + its('location') { should include location } + its('service_provider_properties_bandwidth_in_mbps') { should eq bandwidth_in_mbps } + its('service_provider_properties_peering_location') { should include peering_location } + its('service_provider_properties_name') { should include service_provider_name } + its('service_provider_provisioning_state') { should eq service_provider_provisioning_state } + its('global_reach_enabled') { should eq global_reach_enabled } + its('allow_global_reach') { should eq allow_global_reach } + its('gateway_manager_etag') { should include gateway_manager_etag } + its('allow_classic_operations') { should eq allow_classic_operations } + its('circuit_provisioning_state') { should include circuit_provisioning_state } + its('sku_name') { should include sku_name } + its('sku_tier') { should include sku_tier } + its('sku_family') { should include sku_family } + end + + describe azure_express_route_circuit(resource_group: resource_group, circuit_name: 'fake') do + it { should_not exist } + end + + describe azure_express_route_circuit(resource_group: 'fake', circuit_name: circuit_name) do + it { should_not exist } + end +end \ No newline at end of file diff --git a/test/integration/verify/controls/azure_express_route_circuit_connections_resources.rb b/test/integration/verify/controls/azure_express_route_circuit_connections_resources.rb new file mode 100644 index 000000000..5a2ed3dcc --- /dev/null +++ b/test/integration/verify/controls/azure_express_route_circuit_connections_resources.rb @@ -0,0 +1,37 @@ +erc_resource_group = input('resource_group', value: nil) +erc_circuit_name = input('circuitName', value: nil) +erc_location = input('circuitLocation', value: nil) +erc_global_reach_enabled = input('globalReachEnabled', value: false) +erc_allow_global_reach = input('allowGlobalReach', value: false) +erc_gateway_manager_etag = input('gatewayManagerEtag', value: '') +allow_classic_operations = input('allowClassicOperations', value: false) +circuit_provisioning_state = input('circuitProvisioningState', value: nil) + +bandwidth_in_mbps = input('bandwidthInMbps', value: nil) +peering_location = input('peeringLocation', value: nil) +service_provider_name = input('serviceProviderName', value: nil) + +sku_name = input('sku_name', value: nil) +sku_tier = input('sku_tier', value: nil) +sku_family = input('sku_family', value: nil) + +control 'azure_express_route_circuits' do + describe azure_express_route_circuits(resource_group: erc_resource_group) do + it { should exist } + its('names') { should include erc_circuit_name } + its('locations') { should include erc_location } + its('types') { should include 'Microsoft.Network/expressRouteCircuits' } + its('provisioning_states') { should include('Succeeded') } + its('service_provider_properties_bandwidth_in_mbps') { should include bandwidth_in_mbps } + its('service_provider_properties_peering_locations') { should include peering_location } + its('service_provider_properties_names') { should include service_provider_name } + its('global_reach_enabled') { should include erc_global_reach_enabled } + its('allow_global_reach') { should include erc_allow_global_reach } + its('gateway_manager_etags') { should include erc_gateway_manager_etag } + its('allow_classic_operations') { should include allow_classic_operations } + its('circuit_provisioning_states') { should include circuit_provisioning_state } + its('sku_names') { should include sku_name } + its('sku_tiers') { should include sku_tier } + its('sku_families') { should include sku_family } + end +end \ No newline at end of file diff --git a/test/unit/resources/azure_express_route_circuit_connections_resource_test.rb b/test/unit/resources/azure_express_route_circuit_connections_resource_test.rb new file mode 100644 index 000000000..6063e4384 --- /dev/null +++ b/test/unit/resources/azure_express_route_circuit_connections_resource_test.rb @@ -0,0 +1,17 @@ +require_relative 'helper' + require 'azure_express_route_circuit' + + class AzureExpressRouteCircuitConstructorTest < Minitest::Test + def test_empty_param_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuit.new } + end + + # resource_provider should not be allowed. + def test_resource_provider_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuit.new(resource_provider: 'some_type') } + end + + def test_resource_group + assert_raises(ArgumentError) { AzureExpressRouteCircuit.new(name: 'my-name') } + end + end \ No newline at end of file diff --git a/test/unit/resources/azure_express_route_circuit_connections_resources_test.rb b/test/unit/resources/azure_express_route_circuit_connections_resources_test.rb new file mode 100644 index 000000000..74e2b166b --- /dev/null +++ b/test/unit/resources/azure_express_route_circuit_connections_resources_test.rb @@ -0,0 +1,25 @@ +require_relative 'helper' + require 'azure_express_route_circuits' + + class AzureExpressRouteCircuitsConstructorTest < Minitest::Test + # resource_type should not be allowed. + def test_resource_type_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(resource_provider: 'some_type') } + end + + def tag_value_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(tag_value: 'some_tag_value') } + end + + def tag_name_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(tag_name: 'some_tag_name') } + end + + def test_resource_id_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(resource_id: 'some_id') } + end + + def test_name_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(name: 'some_name') } + end + end \ No newline at end of file From 607d7e2c7342e8fc5344c7b65b7f226c732b709b Mon Sep 17 00:00:00 2001 From: sa-progress Date: Mon, 9 Aug 2021 14:58:16 +0530 Subject: [PATCH 3/5] added resource for circuit connection --- ...ress_route_circuit_connections_resource.md | 71 +++++++------------ ...ess_route_circuit_connections_resources.md | 64 +++++++---------- ...ress_route_circuit_connections_resource.rb | 6 +- ...ess_route_circuit_connections_resources.rb | 48 +++++-------- ...ress_route_circuit_connections_resource.rb | 38 ++-------- ...ess_route_circuit_connections_resources.rb | 35 ++------- 6 files changed, 85 insertions(+), 177 deletions(-) diff --git a/docs/resources/azure_express_route_circuit_connections_resource.md b/docs/resources/azure_express_route_circuit_connections_resource.md index 05852ee07..f21b6fdc4 100644 --- a/docs/resources/azure_express_route_circuit_connections_resource.md +++ b/docs/resources/azure_express_route_circuit_connections_resource.md @@ -1,11 +1,11 @@ --- -title: About the azure_express_route_circuit Resource +title: About the azure_express_route_circuit_connections_resource Resource platform: azure --- -# azure_express_route_circuit +# azure_express_route_circuit_connections_resource -Use the `azure_express_route_circuit` InSpec audit resource to test properties related to a express circuit 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 @@ -24,11 +24,14 @@ For more information, refer to the resource pack [README](../../README.md). 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 -`resource_group` and express circuit resource `name` or the `resource_id` must be given as a parameter. ```ruby -describe azure_express_route_circuit(resource_group: 'MyResourceGroup', name: 'express circuit_name') do +describe azure_express_route_circuit_connections_resource(resource_group: 'example', circuit_name: 'cn', peering_name: 'pn', connection_name: 'cn') do it { should exist } end ``` @@ -37,10 +40,12 @@ end | Name | Description | |--------------------------------|----------------------------------------------------------------------------------| | resource_group | Azure resource group that the targeted resource resides in. `MyResourceGroup` | -| circuit_name | Name of the circuit test. `circuit_name` | +| 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` | -Both of the parameter sets should be provided for a valid query: -- `resource_group` and `name` +All of the parameter sets should be provided for a valid query: +- `resource_group`, `circuit_name`, `peering_name`, `connection_name` ## Properties @@ -50,23 +55,9 @@ Both of the parameter sets should be provided for a valid query: | 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. | -| service_provider_properties_bandwidth_in_mbps | The bandwidth in Mbps of the circuit being created on the Service Provider. | -| service_provider_properties_peering_location | The name of the peering location and not the Azure resource location. Changing this forces a new resource to be created. | -| service_provider_properties_name | The name of the ExpressRoute Service Provider. Changing this forces a new resource to be created. | -| service_provider_provisioning_state | The ExpressRoute circuit provisioning state from your chosen service provider. Possible values are "NotProvisioned", "Provisioning", "Provisioned", and "Deprovisioning". | -| service_key | State of express circuitHostName creation | -| stag | The identifier of the circuit traffic. Outer tag for QinQ encapsulation. | -| global_reach_enabled | ExpressRoute circuit allowGlobalReachEnable `boolean` | -| allow_global_reach | ExpressRoute circuit Flag denoting global reach status. `boolean` | -| gateway_manager_etag | The GatewayManager Etag. | -| allow_classic_operations | Allow classic operations. `boolean` | -| circuit_provisioning_state | State of express circuitHostName creation | -| sku_name | Name sku block for the ExpressRoute circuit as documented below. | -| sku_tier | The service tier. Possible values are Basic, Local, Standard or Premium. | -| sku_family | The billing mode for bandwidth. Possible values are MeteredData or UnlimitedData. | -Both of the parameter sets should be provided for a valid query: -- `resource_group` and `circuit_name` +| 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. @@ -77,20 +68,20 @@ Any attribute in the response may be accessed with the key names separated by do ### Ensure that the express circuit resource has is from same type ```ruby -describe azure_express_route_circuit(resource_group: 'MyResourceGroup', name: 'express circuit_name') do +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(resource_group: 'MyResourceGroup', name: 'express circuit_name') do +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(resource_group: 'MyResourceGroup', name: 'circuit_name') do +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 ``` @@ -98,34 +89,22 @@ end 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(resource_group: 'MyResourceGroup', name: 'mycircuit_name') do - it { should exist } - its('service_provider_properties_bandwidth_in_mbps') { should eq bandwidthInMbps } - its('service_provider_properties_peering_location') { should include peeringLocation } - its('service_provider_properties_name') { should include serviceProviderName } - its('service_provider_provisioning_state') { should include serviceProviderProvisioningState } - its('service_key') { should include serviceKey } - its('stag') { should eq stag } - its('global_reach_enabled') { should eq globalReachEnabled } - its('allow_global_reach') { should eq allowGlobalReach } - its('gateway_manager_etag') { should include gatewayManagerEtag } - its('allow_classic_operations') { should eq allowClassicOperations } - its('circuit_provisioning_state') { should include circuitProvisioningState } - its('sku_name') { should include sku_name } - its('sku_tier') { should include sku_tier } - its('sku_family') { should include sku_family } +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(resource_group: 'MyResourceGroup', name: 'mycircuit_name') do +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(resource_group: 'MyResourceGroup', name: 'DoesNotExist') do +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 ``` diff --git a/docs/resources/azure_express_route_circuit_connections_resources.md b/docs/resources/azure_express_route_circuit_connections_resources.md index 206fc6f7d..1ea65f525 100644 --- a/docs/resources/azure_express_route_circuit_connections_resources.md +++ b/docs/resources/azure_express_route_circuit_connections_resources.md @@ -1,11 +1,11 @@ --- -title: About the azure_express_route_circuits Resource +title: About the azure_express_route_circuit_connections_resources Resource platform: azure --- -# azure_express_route_circuits +# azure_express_route_circuit_connections_resources -Use the `azure_express_route_circuits` InSpec audit resource to test properties related to express_route_circuits for a resource group or the entire subscription. +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 @@ -25,16 +25,27 @@ This resource is available in the [InSpec Azure resource pack](https://github.co 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-circuits/list) for properties available. +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_circuits` resource block returns all Azure express route circuits, either within a Resource Group (if provided) +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_circuits(resource_group: 'my-rg') do +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 @@ -46,18 +57,9 @@ end | 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` | -| service_provider_bandwidth_in_mbps | A list of The bandwidth in Mbps of the circuit being created on the Service Provider. | `service_provider_bandwidth_in_mbps` | -| service_provider_peering_locations | A list of The name of the peering location and not the Azure resource location. Changing this forces a new resource to be created. | `service_provider_peering_location` | -| service_provider_names | The name of the ExpressRoute Service Provider. Changing this forces a new resource to be created. | `service_provider_name` | -| service_keys | State of express circuitHostName creation | `service_key` | -| stags | The identifier of the circuit traffic. Outer tag for QinQ encapsulation. `Number` | `stag` | -| global_reach_enabled | A list of The ExpressRoute circuit allowGlobalReachEnable `boolean` `boolean`| `global_reach_enabled` | -| gateway_manager_etags | A list of The GatewayManager Etag. | `gateway_manager_etag` | -| allow_classic_operations | A list of Allow classic operations. `boolean` | `allow_classic_operation` | -| circuit_provisioning_states | A list of State of express circuitHostName creation `Enabled` or `Disabled` | `circuit_provisioning_state` | -| sku_names | A List of Name sku block for the ExpressRoute circuit as documented below. | `sku_name` | -| sku_tiers | A List of The service tier. Possible values are Basic, Local, Standard or Premium. | `sku_tier` | -| sku_family | A List of The billing mode for bandwidth. Possible values are MeteredData or UnlimitedData. | `sku_family` | +| 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` | * 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). @@ -65,14 +67,14 @@ end ### Ensure that the express_route_circuits resource is in successful state ```ruby -describe azure_express_route_circuits(resource_group: 'MyResourceGroup') do +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_circuits(resource_group: 'MyResourceGroup') do +describe azure_express_route_circuit_connections_resources(resource_group: 'rg', circuit_name: 'cn', peering_name: 'pn') do its('location') { should include df_location } end ``` @@ -81,25 +83,13 @@ end 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_circuits(resource_group: 'MyResourceGroup') do +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('service_provider_properties_bandwidth_in_mbps') { should include bandwidthInMbps } - its('service_provider_properties_peering_locations') { should include peeringLocation } - its('service_provider_properties_names') { should include serviceProviderName } - its('service_provider_provisioning_states') { should include serviceProviderProvisioningState } - its('service_keys') { should include serviceKey } - its('stags') { should include stag } - its('global_reach_enabled') { should include globalReachEnabled } - its('allow_global_reach') { should include allowGlobalReach } - its('gateway_manager_etags') { should include gatewayManagerEtag } - its('allow_classic_operations') { should include allowClassicOperations } - its('circuit_provisioning_states') { should include circuitProvisioningState } - its('sku_names') { should include sku_name } - its('sku_tiers') { should include sku_tier } - its('sku_families') { should include sku_family } + its('circuit_connection_status') { should include('Connected') } + its('ipv6_circuit_connection_config_status') { should include('Connected') } end ``` @@ -107,11 +97,11 @@ end ### exists ```ruby # Should exist if express_route_circuits are in the resource group -describe azure_express_route_circuits(resource_group: 'MyResourceGroup') do +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_circuits(resource_group: 'MyResourceGroup') do +describe azure_express_route_circuit_connections_resources(resource_group: 'rg', circuit_name: 'cn', peering_name: 'should_not_exist') do it { should_not exist } end ``` diff --git a/libraries/azure_express_route_circuit_connections_resource.rb b/libraries/azure_express_route_circuit_connections_resource.rb index 5df43fb03..8a2a4c607 100644 --- a/libraries/azure_express_route_circuit_connections_resource.rb +++ b/libraries/azure_express_route_circuit_connections_resource.rb @@ -4,7 +4,7 @@ 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', circuitName: 'circuitName') do + 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 @@ -59,8 +59,8 @@ def provisioning_state properties.provisioningState if exists? end - def circuit_provisioning_state - properties.provisioningState if exists? + def circuit_connection_status + properties.circuitConnectionStatus if exists? end def ipv6_circuit_connection_config_status diff --git a/libraries/azure_express_route_circuit_connections_resources.rb b/libraries/azure_express_route_circuit_connections_resources.rb index 03163f106..06e402949 100644 --- a/libraries/azure_express_route_circuit_connections_resources.rb +++ b/libraries/azure_express_route_circuit_connections_resources.rb @@ -1,10 +1,10 @@ require 'azure_generic_resources' -class AzureExpressRouteCircuits < AzureGenericResources - name 'azure_express_route_circuits' +class AzureExpressRouteCircuitConnectionsResources < AzureGenericResources + name 'azure_express_route_circuit_connections_resources' desc 'ExpressRoute circuits connect your on-premises infrastructure to Microsoft through a connectivity provider' example <<-EXAMPLE - describe azure_express_route_circuits(resource_group: 'example') do + describe azure_express_route_circuit_connections_resources(resource_group: 'rg', circuit_name: 'cn', peering_name: 'pn') do it{ should exist } end EXAMPLE @@ -16,12 +16,12 @@ def initialize(opts = {}) raise ArgumentError, 'Parameters must be provided in an Hash object.' unless opts.is_a?(Hash) # Azure REST API endpoint URL format listing the all resources for a given subscription: - # GET https://management.azure.com/subscriptions/{subscriptionId}/providers/ - # Microsoft.Network/expressRouteCircuits?api-version=2020-11-01 + # GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/ + # providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections?api-version=2021-02-01 # # # The dynamic part that has to be created for this resource: - # Microsoft.Network/expressRouteCircuits?api-version=2019-12-01 + # Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/connections?api-version=2021-02-01 # # Parameters acquired from environment variables: # - {subscriptionId} => Required parameter. It will be acquired by the backend from environment variables. @@ -41,6 +41,8 @@ def initialize(opts = {}) # 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('/') # static_resource parameter must be true for setting the resource_provider in the backend. super(opts, true) @@ -60,25 +62,16 @@ def initialize(opts = {}) { column: :types, field: :type }, { column: :tags, field: :tags }, { column: :provisioning_states, field: :provisioning_state }, - { column: :sku_names, field: :sku_name }, - { column: :sku_tiers, field: :sku_tier }, - { column: :sku_families, field: :sku_family }, - { column: :circuit_provisioning_states, field: :circuit_provisioning_state }, - { column: :allow_classic_operations, field: :allow_classic_operations }, - { column: :gateway_manager_etags, field: :gateway_manager_etag }, - { column: :service_keys, field: :serviceKey }, - { column: :global_reach_enabled, field: :global_reach_enabled }, - { column: :stags, field: :stag }, - { column: :service_provider_names, field: :service_provider_name }, - { column: :service_provider_peering_locations, field: :service_provider_peering_location }, - { column: :service_provider_bandwidth_in_mbps, field: :service_provider_bandwidth_in_mbps }, + { column: :circuit_connection_status, field: :circuit_connection_status }, + { column: :ipv6_circuit_connection_config_status, field: :ipv6_circuit_connection_config_status }, + { column: :properties, field: :properties }, ] # FilterTable is populated at the very end due to being an expensive operation. AzureGenericResources.populate_filter_table(:table, table_schema) end def to_s - super(AzureExpressRouteCircuits) + super(AzureExpressRouteCircuitConnectionsResources) end private @@ -101,19 +94,10 @@ def populate_table type: resource[:type], tags: resource[:tags], provisioning_state: resource[:properties][:provisioningState], - sku_name: resource[:sku][:name], - sku_tier: resource[:sku][:tier], - sku_family: resource[:sku][:family], - circuit_provisioning_state: resource[:properties][:circuitProvisioningState], - allow_classic_operations: resource[:properties][:allowClassicOperations], - gateway_manager_etag: resource[:properties][:gatewayManagerEtag], - serviceKey: resource[:properties][:serviceKey], - global_reach_enabled: resource[:properties][:globalReachEnabled], - stag: resource[:properties][:stag], - service_provider_name: resource[:properties][:serviceProviderProperties][:serviceProviderName], - service_provider_peering_location: resource[:properties][:serviceProviderProperties][:peeringLocation], - service_provider_bandwidth_in_mbps: resource[:properties][:serviceProviderProperties][:bandwidthInMbps], + circuit_connection_status: resource[:properties][:circuitConnectionStatus], + ipv6_circuit_connection_config_status: resource[:properties][:ipv6CircuitConnectionConfig][:circuitConnectionStatus], + properties: resource[:properties], } end end -end \ No newline at end of file +end diff --git a/test/integration/verify/controls/azure_express_route_circuit_connections_resource.rb b/test/integration/verify/controls/azure_express_route_circuit_connections_resource.rb index 1d254afe0..8a0df5017 100644 --- a/test/integration/verify/controls/azure_express_route_circuit_connections_resource.rb +++ b/test/integration/verify/controls/azure_express_route_circuit_connections_resource.rb @@ -1,47 +1,23 @@ resource_group = input('resource_group', value: nil) circuit_name = input('circuitName', value: nil) location = input('circuitLocation', value: nil) -global_reach_enabled = input('globalReachEnabled', value: false) -allow_global_reach = input('allowGlobalReach', value: false) -service_provider_provisioning_state = input('serviceProviderProvisioningState', value: nil) -gateway_manager_etag = input('gatewayManagerEtag', value: '') -allow_classic_operations = input('allowClassicOperations', value: false) -circuit_provisioning_state = input('circuitProvisioningState', value: nil) -bandwidth_in_mbps = input('bandwidthInMbps', value: nil) -peering_location = input('peeringLocation', value: nil) -service_provider_name = input('serviceProviderName', value: nil) - -sku_name = input('sku_name', value: nil) -sku_tier = input('sku_tier', value: nil) -sku_family = input('sku_family', value: nil) - -control 'azure_express_route_circuit' do - describe azure_express_route_circuit(resource_group: resource_group, circuit_name: circuit_name) do +control 'azure_express_route_circuit_connections_resource' do + describe azure_express_route_circuit_connections_resource(resource_group: resource_group, circuit_name: circuit_name) do it { should exist } its('name') { should eq circuit_name } its('type') { should eq 'Microsoft.Network/expressRouteCircuits' } its('provisioning_state') { should include('Succeeded') } its('location') { should include location } - its('service_provider_properties_bandwidth_in_mbps') { should eq bandwidth_in_mbps } - its('service_provider_properties_peering_location') { should include peering_location } - its('service_provider_properties_name') { should include service_provider_name } - its('service_provider_provisioning_state') { should eq service_provider_provisioning_state } - its('global_reach_enabled') { should eq global_reach_enabled } - its('allow_global_reach') { should eq allow_global_reach } - its('gateway_manager_etag') { should include gateway_manager_etag } - its('allow_classic_operations') { should eq allow_classic_operations } - its('circuit_provisioning_state') { should include circuit_provisioning_state } - its('sku_name') { should include sku_name } - its('sku_tier') { should include sku_tier } - its('sku_family') { should include sku_family } + its('ipv6_circuit_connection_config_status') { should eq 'Connected' } + its('circuit_connection_status') { should include 'Connected' } end - describe azure_express_route_circuit(resource_group: resource_group, circuit_name: 'fake') do + describe azure_express_route_circuit_connections_resource(resource_group: resource_group, circuit_name: 'fake') do it { should_not exist } end - describe azure_express_route_circuit(resource_group: 'fake', circuit_name: circuit_name) do + describe azure_express_route_circuit_connections_resource(resource_group: 'fake', circuit_name: 'cn', peering_name: 'should_not_exist') do it { should_not exist } end -end \ No newline at end of file +end diff --git a/test/integration/verify/controls/azure_express_route_circuit_connections_resources.rb b/test/integration/verify/controls/azure_express_route_circuit_connections_resources.rb index 5a2ed3dcc..77451bbdd 100644 --- a/test/integration/verify/controls/azure_express_route_circuit_connections_resources.rb +++ b/test/integration/verify/controls/azure_express_route_circuit_connections_resources.rb @@ -1,37 +1,16 @@ erc_resource_group = input('resource_group', value: nil) erc_circuit_name = input('circuitName', value: nil) erc_location = input('circuitLocation', value: nil) -erc_global_reach_enabled = input('globalReachEnabled', value: false) -erc_allow_global_reach = input('allowGlobalReach', value: false) -erc_gateway_manager_etag = input('gatewayManagerEtag', value: '') -allow_classic_operations = input('allowClassicOperations', value: false) -circuit_provisioning_state = input('circuitProvisioningState', value: nil) +peering_name = input('peeringName', value: nil) -bandwidth_in_mbps = input('bandwidthInMbps', value: nil) -peering_location = input('peeringLocation', value: nil) -service_provider_name = input('serviceProviderName', value: nil) - -sku_name = input('sku_name', value: nil) -sku_tier = input('sku_tier', value: nil) -sku_family = input('sku_family', value: nil) - -control 'azure_express_route_circuits' do - describe azure_express_route_circuits(resource_group: erc_resource_group) do +control 'azure_express_route_circuit_connections_resources' do + describe azure_express_route_circuit_connections_resources(resource_group: erc_resource_group, circuit_name: erc_circuit_name, peering_name: peering_name) do it { should exist } - its('names') { should include erc_circuit_name } + its('names') { should include circuitName } its('locations') { should include erc_location } its('types') { should include 'Microsoft.Network/expressRouteCircuits' } its('provisioning_states') { should include('Succeeded') } - its('service_provider_properties_bandwidth_in_mbps') { should include bandwidth_in_mbps } - its('service_provider_properties_peering_locations') { should include peering_location } - its('service_provider_properties_names') { should include service_provider_name } - its('global_reach_enabled') { should include erc_global_reach_enabled } - its('allow_global_reach') { should include erc_allow_global_reach } - its('gateway_manager_etags') { should include erc_gateway_manager_etag } - its('allow_classic_operations') { should include allow_classic_operations } - its('circuit_provisioning_states') { should include circuit_provisioning_state } - its('sku_names') { should include sku_name } - its('sku_tiers') { should include sku_tier } - its('sku_families') { should include sku_family } + its('circuit_connection_status') { should include('Connected') } + its('ipv6_circuit_connection_config_status') { should include('Connected') } end -end \ No newline at end of file +end From 5549230813e9aa1358ca3d5963112ddf4d465aa8 Mon Sep 17 00:00:00 2001 From: sa-progress Date: Mon, 9 Aug 2021 15:08:54 +0530 Subject: [PATCH 4/5] test cases added --- ...ress_route_circuit_connections_resource.rb | 11 ++++-- ...route_circuit_connections_resource_test.rb | 26 ++++++------- ...oute_circuit_connections_resources_test.rb | 38 +++++++++---------- 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/test/integration/verify/controls/azure_express_route_circuit_connections_resource.rb b/test/integration/verify/controls/azure_express_route_circuit_connections_resource.rb index 8a0df5017..5f3e6d392 100644 --- a/test/integration/verify/controls/azure_express_route_circuit_connections_resource.rb +++ b/test/integration/verify/controls/azure_express_route_circuit_connections_resource.rb @@ -1,9 +1,12 @@ resource_group = input('resource_group', value: nil) circuit_name = input('circuitName', value: nil) location = input('circuitLocation', value: nil) +peering_name = input('peeringName', value: nil) +connection_name = input('connectionName', value: nil) control 'azure_express_route_circuit_connections_resource' do - describe azure_express_route_circuit_connections_resource(resource_group: resource_group, circuit_name: circuit_name) do + describe azure_express_route_circuit_connections_resource(resource_group: resource_group, circuit_name: circuit_name, + peering_name: peering_name, connection_name: connection_name) do it { should exist } its('name') { should eq circuit_name } its('type') { should eq 'Microsoft.Network/expressRouteCircuits' } @@ -13,11 +16,13 @@ its('circuit_connection_status') { should include 'Connected' } end - describe azure_express_route_circuit_connections_resource(resource_group: resource_group, circuit_name: 'fake') do + describe azure_express_route_circuit_connections_resource(resource_group: resource_group, circuit_name: circuit_name, + peering_name: peering_name, connection_name: connection_name) do it { should_not exist } end - describe azure_express_route_circuit_connections_resource(resource_group: 'fake', circuit_name: 'cn', peering_name: 'should_not_exist') do + describe azure_express_route_circuit_connections_resource(resource_group: resource_group, circuit_name: circuit_name, + peering_name: peering_name, connection_name: 'does_not_exist') do it { should_not exist } end end diff --git a/test/unit/resources/azure_express_route_circuit_connections_resource_test.rb b/test/unit/resources/azure_express_route_circuit_connections_resource_test.rb index 6063e4384..1394858cb 100644 --- a/test/unit/resources/azure_express_route_circuit_connections_resource_test.rb +++ b/test/unit/resources/azure_express_route_circuit_connections_resource_test.rb @@ -1,17 +1,17 @@ require_relative 'helper' - require 'azure_express_route_circuit' +require 'azure_express_route_circuit' - class AzureExpressRouteCircuitConstructorTest < Minitest::Test - def test_empty_param_not_ok - assert_raises(ArgumentError) { AzureExpressRouteCircuit.new } - end +class AzureExpressRouteCircuitConstructorTest < Minitest::Test + def test_empty_param_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuit.new } + end - # resource_provider should not be allowed. - def test_resource_provider_not_ok - assert_raises(ArgumentError) { AzureExpressRouteCircuit.new(resource_provider: 'some_type') } - end + # resource_provider should not be allowed. + def test_resource_provider_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuit.new(resource_provider: 'some_type') } + end - def test_resource_group - assert_raises(ArgumentError) { AzureExpressRouteCircuit.new(name: 'my-name') } - end - end \ No newline at end of file + def test_resource_group + assert_raises(ArgumentError) { AzureExpressRouteCircuit.new(name: 'my-name') } + end +end diff --git a/test/unit/resources/azure_express_route_circuit_connections_resources_test.rb b/test/unit/resources/azure_express_route_circuit_connections_resources_test.rb index 74e2b166b..461e2f0da 100644 --- a/test/unit/resources/azure_express_route_circuit_connections_resources_test.rb +++ b/test/unit/resources/azure_express_route_circuit_connections_resources_test.rb @@ -1,25 +1,25 @@ require_relative 'helper' - require 'azure_express_route_circuits' +require 'azure_express_route_circuits' - class AzureExpressRouteCircuitsConstructorTest < Minitest::Test - # resource_type should not be allowed. - def test_resource_type_not_ok - assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(resource_provider: 'some_type') } - end +class AzureExpressRouteCircuitsConstructorTest < Minitest::Test + # resource_type should not be allowed. + def test_resource_type_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(resource_provider: 'some_type') } + end - def tag_value_not_ok - assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(tag_value: 'some_tag_value') } - end + def tag_value_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(tag_value: 'some_tag_value') } + end - def tag_name_not_ok - assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(tag_name: 'some_tag_name') } - end + def tag_name_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(tag_name: 'some_tag_name') } + end - def test_resource_id_not_ok - assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(resource_id: 'some_id') } - end + def test_resource_id_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(resource_id: 'some_id') } + end - def test_name_not_ok - assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(name: 'some_name') } - end - end \ No newline at end of file + def test_name_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(name: 'some_name') } + end +end From 2e97e11ab8201c91c8595b73517088bab4254811 Mon Sep 17 00:00:00 2001 From: sa-progress Date: Mon, 9 Aug 2021 15:08:54 +0530 Subject: [PATCH 5/5] docs updated :review fix Signed-off-by: sa-progress --- ...ress_route_circuit_connections_resource.rb | 11 ++++-- ...route_circuit_connections_resource_test.rb | 26 ++++++------- ...oute_circuit_connections_resources_test.rb | 38 +++++++++---------- 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/test/integration/verify/controls/azure_express_route_circuit_connections_resource.rb b/test/integration/verify/controls/azure_express_route_circuit_connections_resource.rb index 8a0df5017..5f3e6d392 100644 --- a/test/integration/verify/controls/azure_express_route_circuit_connections_resource.rb +++ b/test/integration/verify/controls/azure_express_route_circuit_connections_resource.rb @@ -1,9 +1,12 @@ resource_group = input('resource_group', value: nil) circuit_name = input('circuitName', value: nil) location = input('circuitLocation', value: nil) +peering_name = input('peeringName', value: nil) +connection_name = input('connectionName', value: nil) control 'azure_express_route_circuit_connections_resource' do - describe azure_express_route_circuit_connections_resource(resource_group: resource_group, circuit_name: circuit_name) do + describe azure_express_route_circuit_connections_resource(resource_group: resource_group, circuit_name: circuit_name, + peering_name: peering_name, connection_name: connection_name) do it { should exist } its('name') { should eq circuit_name } its('type') { should eq 'Microsoft.Network/expressRouteCircuits' } @@ -13,11 +16,13 @@ its('circuit_connection_status') { should include 'Connected' } end - describe azure_express_route_circuit_connections_resource(resource_group: resource_group, circuit_name: 'fake') do + describe azure_express_route_circuit_connections_resource(resource_group: resource_group, circuit_name: circuit_name, + peering_name: peering_name, connection_name: connection_name) do it { should_not exist } end - describe azure_express_route_circuit_connections_resource(resource_group: 'fake', circuit_name: 'cn', peering_name: 'should_not_exist') do + describe azure_express_route_circuit_connections_resource(resource_group: resource_group, circuit_name: circuit_name, + peering_name: peering_name, connection_name: 'does_not_exist') do it { should_not exist } end end diff --git a/test/unit/resources/azure_express_route_circuit_connections_resource_test.rb b/test/unit/resources/azure_express_route_circuit_connections_resource_test.rb index 6063e4384..1394858cb 100644 --- a/test/unit/resources/azure_express_route_circuit_connections_resource_test.rb +++ b/test/unit/resources/azure_express_route_circuit_connections_resource_test.rb @@ -1,17 +1,17 @@ require_relative 'helper' - require 'azure_express_route_circuit' +require 'azure_express_route_circuit' - class AzureExpressRouteCircuitConstructorTest < Minitest::Test - def test_empty_param_not_ok - assert_raises(ArgumentError) { AzureExpressRouteCircuit.new } - end +class AzureExpressRouteCircuitConstructorTest < Minitest::Test + def test_empty_param_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuit.new } + end - # resource_provider should not be allowed. - def test_resource_provider_not_ok - assert_raises(ArgumentError) { AzureExpressRouteCircuit.new(resource_provider: 'some_type') } - end + # resource_provider should not be allowed. + def test_resource_provider_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuit.new(resource_provider: 'some_type') } + end - def test_resource_group - assert_raises(ArgumentError) { AzureExpressRouteCircuit.new(name: 'my-name') } - end - end \ No newline at end of file + def test_resource_group + assert_raises(ArgumentError) { AzureExpressRouteCircuit.new(name: 'my-name') } + end +end diff --git a/test/unit/resources/azure_express_route_circuit_connections_resources_test.rb b/test/unit/resources/azure_express_route_circuit_connections_resources_test.rb index 74e2b166b..461e2f0da 100644 --- a/test/unit/resources/azure_express_route_circuit_connections_resources_test.rb +++ b/test/unit/resources/azure_express_route_circuit_connections_resources_test.rb @@ -1,25 +1,25 @@ require_relative 'helper' - require 'azure_express_route_circuits' +require 'azure_express_route_circuits' - class AzureExpressRouteCircuitsConstructorTest < Minitest::Test - # resource_type should not be allowed. - def test_resource_type_not_ok - assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(resource_provider: 'some_type') } - end +class AzureExpressRouteCircuitsConstructorTest < Minitest::Test + # resource_type should not be allowed. + def test_resource_type_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(resource_provider: 'some_type') } + end - def tag_value_not_ok - assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(tag_value: 'some_tag_value') } - end + def tag_value_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(tag_value: 'some_tag_value') } + end - def tag_name_not_ok - assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(tag_name: 'some_tag_name') } - end + def tag_name_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(tag_name: 'some_tag_name') } + end - def test_resource_id_not_ok - assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(resource_id: 'some_id') } - end + def test_resource_id_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(resource_id: 'some_id') } + end - def test_name_not_ok - assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(name: 'some_name') } - end - end \ No newline at end of file + def test_name_not_ok + assert_raises(ArgumentError) { AzureExpressRouteCircuits.new(name: 'some_name') } + end +end