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

Merged
merged 23 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f1ef9e6
added resource and test cases
sa-progress Jul 28, 2021
16a2335
added resource and test cases
sa-progress Jul 28, 2021
d521664
lint fix
sa-progress Jul 28, 2021
90a2464
added test space
ppradhan9 Jul 28, 2021
5a25c07
updated resource
sa-progress Jul 28, 2021
fe8b19d
fixed merge conflict
sa-progress Jul 28, 2021
eadabda
fixed merge conflict
sa-progress Jul 28, 2021
9bb9d28
Merge branch 'f/express_route' of github.com:inspec/inspec-azure into…
sa-progress Jul 28, 2021
6c04d5a
merge fixed
sa-progress Jul 28, 2021
9dfae34
changed test class names
sa-progress Jul 29, 2021
c4f8cb5
updated read me
sa-progress Jul 29, 2021
1384bff
read me updated
sa-progress Jul 29, 2021
18d5367
Merge branch 'master' into f/express_route
sa-progress Jul 29, 2021
41937df
Merge branch 'master' into f/express_route
sa-progress Aug 4, 2021
a87d869
Merge branch 'master' into f/express_route
sathish-progress Aug 5, 2021
3713f75
added comment
sa-progress Aug 5, 2021
b5b6bd5
Merge branch 'f/express_route' of github.com:inspec/inspec-azure into…
sa-progress Aug 5, 2021
5c14ad4
changed to alphabetical order.
sa-progress Aug 12, 2021
1e40bca
Merge branch 'master' into f/express_route
sa-progress Aug 12, 2021
b97dce8
added Reqd me and tf files
sa-progress Aug 5, 2021
f7aadeb
Merge branch 'f/express_route' of github.com:inspec/inspec-azure into…
sa-progress Aug 12, 2021
6a72650
added Reqd me and tf files
sa-progress Aug 12, 2021
2ad6a5a
Merge branch 'master' into f/express_route
sa-progress Aug 13, 2021
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ The following is a list of static resources.
- [azure_web_app_functions](docs/resources/azure_web_app_functions.md)
- [azure_webapp](docs/resources/azure_webapp.md)
- [azure_webapps](docs/resources/azure_webapps.md)
- [azure_express_route_providers](docs/resources/azure_express_route_providers.md)
sa-progress marked this conversation as resolved.
Show resolved Hide resolved


For more details and different use cases, please refer to the specific resource pages.
Expand Down Expand Up @@ -393,7 +394,7 @@ They can be defined as environment variables or resource parameters (has priorit
| azurerm_virtual_machine_disk, azurerm_virtual_machine_disks | `2017-03-30` | [azure_virtual_machine_disk](docs/resources/azure_virtual_machine_disk.md), [azure_virtual_machine_disks](docs/resources/azure_virtual_machine_disks.md) |
| azurerm_virtual_network, azurerm_virtual_networks | `2018-02-01` | [azure_virtual_network](docs/resources/azure_virtual_network.md), [azure_virtual_networks](docs/resources/azure_virtual_networks.md) |
| azurerm_webapp, azurerm_webapps | `2016-08-01` | [azure_webapp](docs/resources/azure_webapp.md), [azure_webapps](docs/resources/azure_webapps.md) |
| azurerm_data_factory, azurerm_data_factories | `2021-06-06` | [azure_data_factory](docs/resources/azure_data_factory.md), [azure_data_factories](docs/resources/azure_data_factories.md) |

## Development

If you'd like to contribute to this project please see [Contributing Rules](CONTRIBUTING.md).
Expand Down
2 changes: 0 additions & 2 deletions docs/resources/azure_express_route_providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ describe azure_express_route_providers(resource_group: 'MyResourceGroup') do
its('peering_locations_list') { should include(["Melbourne", "Sydney"]) }
its('bandwidths_offered_list') { should include('bandwidths_offered') }
end


```
## Azure Permissions

Expand Down
100 changes: 100 additions & 0 deletions libraries/azure_express_route_providers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
require 'azure_generic_resources'

class AzureExpressRouteServiceProviders < AzureGenericResources
name 'azure_express_route_providers'
desc 'Verifies settings for Azure Virtual Machines'
example <<-EXAMPLE
describe azure_express_route_providers(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/expressRouteServiceProviders?api-version=2020-11-01
#
# or in a resource group only
# GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/
# Microsoft.Network/expressRouteServiceProviders?api-version=2019-12-01
#
# The dynamic part that has to be created for this resource:
# Microsoft.Network/expressRouteServiceProviders?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/expressRouteServiceProviders
# 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/expressRouteServiceProviders', 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: :names, field: :name },
{ column: :types, field: :type },
{ column: :ids, field: :id },
{ column: :tags, field: :tags },
{ column: :provisioning_states, field: :provisioningState },
{ column: :peering_locations_list, field: :peeringLocations },
{ column: :bandwidths_offered_list, field: :bandwidthsOffered },
]
# 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(AzureExpressRouteServiceProviders)
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],
type: resource[:type],
tags: resource[:tags],
provisioningState: resource[:properties][:provisioningState],
sa-progress marked this conversation as resolved.
Show resolved Hide resolved
peeringLocations: resource[:properties][:peeringLocations],
bandwidthsOffered: resource[:properties][:bandwidthsOffered],
}
end
end
end
7 changes: 6 additions & 1 deletion terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,13 @@ output "inspec_db_migration_service_name" {
output "inspec_db_migration_service_sku_name" {
value = var.inspec_db_migration_service.sku_name
}


output "express_route_name" {
value = var.express_route_name
}

output "inspec_container_group_name" {
description = "the name of the container group"
value = azurerm_container_group.inspec_container_trial.name
}

4 changes: 4 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ variable "policy_assignment_display_name" {
default = "inspec_policy_assignment_name"
}

variable "express_route_name" {
default = "AARNet"
}

variable "inspec_db_migration_service" {
default = {
name = "inspec-compliance-migration-dev"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
express_route_name = input('express_route_name', value: nil)

control 'azure_express_route_providers' do
describe azure_express_route_providers do
its('names') { should include express_route_name }
its('types') { should include 'Microsoft.Network/expressRouteServiceProviders' }
its('provisioning_states') { should include('Succeeded') }
end
end
24 changes: 24 additions & 0 deletions test/unit/resources/azure_express_route_providers_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require_relative 'helper'
require 'azure_express_route_providers'

class AzureExpressRouteServiceProvidersConstructorTest < Minitest::Test
def test_resource_type_not_ok
assert_raises(ArgumentError) { AzureExpressRouteServiceProviders.new(resource_provider: 'some_type') }
end

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

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

def test_resource_id_not_ok
assert_raises(ArgumentError) { AzureExpressRouteServiceProviders.new(resource_id: 'some_id') }
end

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