-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #432 from inspec/support-migrate-project-solutions
Support migrate project solutions
- Loading branch information
Showing
9 changed files
with
332 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
--- | ||
title: About the azure_migrate_project_solution Resource | ||
platform: azure | ||
--- | ||
|
||
# azure_migrate_project_solution | ||
|
||
Use the `azure_migrate_project_solution` InSpec audit resource to test the properties related to an Azure Migrate Project Solution. | ||
|
||
## Azure REST API Version, Endpoint, and HTTP Client Parameters | ||
|
||
This resource interacts with API versions supported by the resource provider. The `api_version` is defined as a resource parameter. If not provided, the latest version is 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 is used. For more information, refer to the resource pack [README](../../README.md). | ||
|
||
## Availability | ||
|
||
### Installation | ||
|
||
This resource is available in the [InSpec Azure resource pack](https://github.com/inspec/inspec-azure). For an example, `inspec.yml` file and how to set up your Azure credentials, refer to resource pack [README](../../README.md#Service-Principal). | ||
|
||
## Syntax | ||
|
||
`name` and `resource_group` are required parameters. | ||
|
||
```ruby | ||
describe azure_migrate_project_solution(resource_group: 'RESOURCE_GROUP', project_name: 'PROJECT_NAME', name: 'PROJECT_SOLUTION_NAME') do | ||
it { should exist } | ||
its('name') { should cmp 'PROJECT_SOLUTION_NAME' } | ||
its('type') { should cmp 'Microsoft.Migrate/MigrateProjects/Solutions' } | ||
end | ||
``` | ||
|
||
```ruby | ||
describe azure_migrate_project_solution(resource_group: 'RESOURCE_GROUP', project_name: 'PROJECT_NAME', name: 'PROJECT_SOLUTION_NAME') do | ||
it { should exist } | ||
end | ||
``` | ||
|
||
## Parameters | ||
|
||
| Name | Description | | ||
|----------------|----------------------------------------------------------------------------------| | ||
| name | Name of the Azure Migrate project solution to test. | | ||
| resource_group | Azure resource group that the targeted resource resides in. | | ||
| project_name | Azure Migrate project. | | ||
|
||
The parameter set should be provided for a valid query: | ||
|
||
- `resource_group`, `project_name`, and `name`. | ||
|
||
## Properties | ||
|
||
| Property | Description | | ||
|-------------------------------|------------------------------------------------------------------| | ||
| id | Path reference to the project solution. | | ||
| name | Unique name of the project solution. | | ||
| type | Object type. `Microsoft.Migrate/MigrateProjects/Solutions` | | ||
| eTag | For optimistic concurrency control. | | ||
| properties | Properties of the project Solution. | | ||
| properties.cleanupState | The cleanup state of the solution. | | ||
| properties.details | The details of the solution. | | ||
| properties.summary | The summary of the solution. | | ||
| properties.purpose | The purpose of the solution. | | ||
|
||
For properties applicable to all resources, such as `type`, `name`, `id`, and `properties`, refer to [`azure_generic_resource`](azure_generic_resource.md#properties). | ||
|
||
Also, refer to [Azure documentation](https://docs.microsoft.com/en-us/rest/api/migrate/projects/solutions/get-solution) for other properties available. Any attribute in the response is accessed with the key names separated by dots (`.`). | ||
|
||
## Examples | ||
|
||
### Test that the migrate project solution is defined for assessment | ||
|
||
```ruby | ||
describe azure_migrate_project_solution(resource_group: 'RESOURCE_GROUP', project_name: 'PROJECT_NAME', name: 'PROJECT_SOLUTION_NAME') do | ||
its('properties.purpose') { should eq 'ASSESSMENT' } | ||
end | ||
``` | ||
|
||
## Matchers | ||
|
||
This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our [Universal Matchers page](/inspec/matchers/). | ||
|
||
### exists | ||
|
||
```ruby | ||
# If a Migrate Project Solution is found, it will exist | ||
describe azure_migrate_project_solution(resource_group: 'RESOURCE_GROUP', project_name: 'PROJECT_NAME', name: 'PROJECT_SOLUTION_NAME') do | ||
it { should exist } | ||
end | ||
|
||
# if Migrate Project Solution are not found, it will not exist | ||
describe azure_migrate_project_solution(resource_group: 'RESOURCE_GROUP', project_name: 'PROJECT_NAME', name: 'PROJECT_SOLUTION_NAME') do | ||
it { should_not exist } | ||
end | ||
``` | ||
|
||
## Azure Permissions | ||
|
||
Your [Service Principal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal) must be set up with a `contributor` role on the subscription you wish to test. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
--- | ||
title: About the azure_migrate_project_solutions Resource | ||
platform: azure | ||
--- | ||
|
||
# azure_migrate_project_solutions | ||
|
||
Use the `azure_migrate_project_solutions` InSpec audit resource to test the properties related to all Azure Migrate project solutions within a project. | ||
|
||
## Azure REST API Version, Endpoint, and HTTP Client Parameters | ||
|
||
This resource interacts with api versions supported by the resource provider. The `api_version` is defined as a resource parameter. | ||
If not provided, the latest version is 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 is used. For more information, refer to the resource pack [README](../../README.md). | ||
|
||
## Availability | ||
|
||
### Installation | ||
|
||
This resource is available in the [InSpec Azure resource pack](https://github.com/inspec/inspec-azure). For an example, `inspec.yml` file and how to set up your Azure credentials, refer to resource pack [README](../../README.md#Service-Principal). | ||
|
||
## Syntax | ||
|
||
An `azure_migrate_project_solutions` resource block returns all Azure Migrate project solutions within a project. | ||
|
||
```ruby | ||
describe azure_migrate_project_solutions(resource_group: 'RESOURCE_GROUP', project_name: 'PROJECT_NAME') do | ||
#... | ||
end | ||
``` | ||
|
||
## Parameters | ||
|
||
| Name | Description | | ||
|----------------|----------------------------------------------------------------------------------| | ||
| resource_group | Azure resource group that the targeted resource resides in. | | ||
| project_name | Azure Migrate Project. | | ||
|
||
The parameter set should be provided for a valid query: | ||
|
||
- `resource_group` and `project_name`. | ||
|
||
## Properties | ||
|
||
|Property | Description | Filter Criteria<superscript>*</superscript> | | ||
|--------------------------------|------------------------------------------------------------------------|------------------| | ||
| ids | Path reference to the project solutions. | `id` | | ||
| names | Unique names for all project solutions. | `name` | | ||
| types | Type of the objects. | `type` | | ||
| eTags | A list of eTags for all the Project Solutions. | `eTag` | | ||
| properties | A list of Properties for all the Project Solutions. | `properties` | | ||
| tools | The tool used in all the solutions. | `tool` | | ||
| purposes | The purpose of all the solutions. | `purpose` | | ||
| goals | The goals of all the solutions. | `goal` | | ||
| statuses | The current status of all the solutions. | `status` | | ||
| cleanupStates | The cleanup states of all the solutions. | `cleanupState` | | ||
| summaries | The summary of all the solutions. | `summary` | | ||
| details | The details of all the solutions. | `details` | | ||
| instanceTypes | The Instance types. | `instanceType` | | ||
| databasesAssessedCounts | The count of databases assessed. | `databasesAssessedCount` | | ||
| databaseInstancesAssessedCounts| The count of database instances assessed. | `databaseInstancesAssessedCount` | | ||
| migrationReadyCounts | The count of databases ready for migration. | `migrationReadyCount` | | ||
| groupCounts | The count of groups reported by all the solutions. | `groupCount` | | ||
| assessmentCounts | The count of assessments reported by all the solutions. | `assessmentCount`| | ||
| extendedDetails | The extended details reported by all the solutions. | `extendedDetails`| | ||
|
||
<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). Also for further reference of the properties please refer [Azure Documentation](https://docs.microsoft.com/en-us/rest/api/migrate/projects/solutions/enumerate-solutions) | ||
|
||
## Examples | ||
|
||
### Loop through migrate project solutions by their names | ||
|
||
```ruby | ||
azure_migrate_project_solutions(resource_group: 'RESOURCE_GROUP', project_name: 'PROJECT_NAME').names.each do |name| | ||
describe azure_migrate_project_solution(resource_group: 'RESOURCE_GROUP', project_name: 'PROJECT_NAME', name: name) do | ||
it { should exist } | ||
end | ||
end | ||
``` | ||
|
||
### Test to ensure the migrate project solutions for assessment | ||
|
||
```ruby | ||
describe azure_migrate_project_solutions(resource_group: 'RESOURCE_GROUP', project_name: 'PROJECT_NAME').where(purpose: 'Assessment') do | ||
it { should exist } | ||
end | ||
``` | ||
|
||
## Matchers | ||
|
||
This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our [Universal Matchers page](https://www.inspec.io/docs/reference/matchers/). | ||
|
||
### exists | ||
|
||
```ruby | ||
# Should not exist if no Migrate Project Solutions are present in the project and in the resource group | ||
describe azure_migrate_project_solutions(resource_group: 'RESOURCE_GROUP', project_name: 'PROJECT_NAME') do | ||
it { should_not exist } | ||
end | ||
# Should exist if the filter returns at least one Migrate Project Solutions in the project and in the resource group | ||
describe azure_migrate_project_solutions(resource_group: 'RESOURCE_GROUP', project_name: 'PROJECT_NAME') do | ||
it { should exist } | ||
end | ||
``` | ||
|
||
## Azure Permissions | ||
|
||
Your [Service Principal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal) must be set up with a `contributor` role on the subscription you wish to test. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'azure_generic_resource' | ||
|
||
class AzureMigrateProjectSolution < AzureGenericResource | ||
name 'azure_migrate_project_solution' | ||
desc 'Retrieves and verifies the settings of an Azure Migrate Project Solution' | ||
example <<-EXAMPLE | ||
describe azure_migrate_project_solution(resource_group: 'migrated_vms', project_name: 'zoneA_migrate_project', name: 'zoneA_machines_migrate_solution') do | ||
it { should exist } | ||
end | ||
EXAMPLE | ||
|
||
def initialize(opts = {}) | ||
raise ArgumentError, 'Parameters must be provided in an Hash object.' unless opts.is_a?(Hash) | ||
|
||
opts[:resource_provider] = specific_resource_constraint('Microsoft.Migrate/migrateProjects', opts) | ||
opts[:required_parameters] = %i(project_name) | ||
opts[:resource_path] = [opts[:project_name], 'solutions'].join('/') | ||
super(opts, true) | ||
end | ||
|
||
def to_s | ||
super(AzureMigrateProjectSolution) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'azure_generic_resources' | ||
|
||
class AzureMigrateProjectSolutions < AzureGenericResources | ||
name 'azure_migrate_project_solutions' | ||
desc 'Verifies settings for a collection of Azure Migrate Project Solutions for a Azure Migrate Project in a Resource Group' | ||
example <<-EXAMPLE | ||
describe azure_migrate_project_solutions(resource_group: 'migrated_vms', project_name: 'zoneA_migrate_project') do | ||
it { should exist } | ||
end | ||
EXAMPLE | ||
|
||
def initialize(opts = {}) | ||
raise ArgumentError, 'Parameters must be provided in an Hash object.' unless opts.is_a?(Hash) | ||
|
||
opts[:resource_provider] = specific_resource_constraint('Microsoft.Migrate/migrateProjects', opts) | ||
opts[:required_parameters] = %i(project_name) | ||
opts[:resource_path] = [opts[:project_name], 'solutions'].join('/') | ||
super(opts, true) | ||
return if failed_resource? | ||
|
||
populate_filter_table_from_response | ||
end | ||
|
||
def to_s | ||
super(AzureMigrateProjectSolutions) | ||
end | ||
|
||
private | ||
|
||
def populate_table | ||
@resources.each do |resource| | ||
props = resource[:properties] | ||
@table << resource.merge(props).merge(props[:summary]).merge(props[:details]) | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
test/integration/verify/controls/azure_migrate_project_solution.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
resource_group = input(:resource_group, value: '') | ||
project_name = input(:project_name, value: 'inspec-migrate-integ') | ||
name = input(:name, value: 'Servers-Assessment-ServerAssessment') | ||
|
||
control 'verify settings for Azure Migrate Project Solution' do | ||
describe azure_migrate_project_solution(resource_group: resource_group, project_name: project_name, name: name) do | ||
it { should exist } | ||
its('name') { should eq name } | ||
its('type') { should eq 'Microsoft.Migrate/MigrateProjects/Solutions' } | ||
its('tool') { should eq 'ServerAssessment' } | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
test/integration/verify/controls/azure_migrate_project_solutions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
resource_group = input(:resource_group, value: '') | ||
project_name = input(:project_name, value: 'inspec-migrate-integ') | ||
|
||
control 'verify settings for Azure Migrate Project Solutions' do | ||
describe azure_migrate_project_solutions(resource_group: resource_group, project_name: project_name) do | ||
it { should exist } | ||
its('names') { should include 'Servers-Assessment-ServerAssessment' } | ||
its('types') { should include 'Microsoft.Migrate/MigrateProjects/Solutions' } | ||
its('tools') { should include 'ServerAssessment' } | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
test/unit/resources/azure_migrate_project_solution_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require_relative 'helper' | ||
require 'azure_migrate_project_solution' | ||
|
||
class AzureMigrateProjectSolutionConstructorTest < Minitest::Test | ||
def test_empty_param_not_ok | ||
assert_raises(ArgumentError) { AzureMigrateProjectSolution.new } | ||
end | ||
|
||
# resource_provider should not be allowed. | ||
def test_resource_provider_not_ok | ||
assert_raises(ArgumentError) { AzureMigrateProjectSolution.new(resource_provider: 'some_type') } | ||
end | ||
|
||
def test_resource_group_name_alone_ok | ||
assert_raises(ArgumentError) { AzureMigrateProjectSolution.new(name: 'my-name', resource_group: 'test') } | ||
end | ||
end |
21 changes: 21 additions & 0 deletions
21
test/unit/resources/azure_migrate_project_solutions_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require_relative 'helper' | ||
require 'azure_migrate_project_solutions' | ||
|
||
class AzureMigrateProjectSolutionsConstructorTest < Minitest::Test | ||
# resource_type should not be allowed. | ||
def test_resource_type_not_ok | ||
assert_raises(ArgumentError) { AzureMigrateProjectSolutions.new(resource_provider: 'some_type') } | ||
end | ||
|
||
def tag_value_not_ok | ||
assert_raises(ArgumentError) { AzureMigrateProjectSolutions.new(tag_value: 'some_tag_value') } | ||
end | ||
|
||
def tag_name_not_ok | ||
assert_raises(ArgumentError) { AzureMigrateProjectSolutions.new(tag_name: 'some_tag_name') } | ||
end | ||
|
||
def test_name_not_ok | ||
assert_raises(ArgumentError) { AzureMigrateProjectSolutions.new(name: 'some_name') } | ||
end | ||
end |