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

Support migrate assessments machines #434

Merged
merged 13 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ The following is a list of static resources.
- [azure_management_groups](docs/resources/azure_management_groups.md)
- [azure_mariadb_server](docs/resources/azure_mariadb_server.md)
- [azure_mariadb_servers](docs/resources/azure_mariadb_servers.md)
- [azure_migrate_assessment_machine](docs/resources/azure_migrate_assessment_machine.md)
- [azure_migrate_assessment_machines](docs/resources/azure_migrate_assessment_machines.md)
- [azure_monitor_activity_log_alert](docs/resources/azure_monitor_activity_log_alert.md)
- [azure_monitor_activity_log_alerts](docs/resources/azure_monitor_activity_log_alerts.md)
- [azure_monitor_log_profile](docs/resources/azure_monitor_log_profile.md)
Expand Down
106 changes: 106 additions & 0 deletions docs/resources/azure_migrate_assessment_machine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
title: About the azure_migrate_assessment_machine Resource
platform: azure
---

# azure_migrate_assessment_machine

Use the `azure_migrate_assessment_machine` InSpec audit resource to test properties related to an Azure Migrate Assessment Machine.

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

sathish-progress marked this conversation as resolved.
Show resolved Hide resolved
## 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).

sathish-progress marked this conversation as resolved.
Show resolved Hide resolved
## Syntax

`name` is a required parameter and `resource_group` could be provided as an optional parameter.

```ruby
describe azure_migrate_assessment_machine(resource_group: 'migrated_vms', project_name: 'zoneA_migrate_assessment_project', group_name: 'zoneA_machines_group', name: 'zoneA_machines_migrate_assessment') do
it { should exist }
its('name') { should cmp 'zoneA_machines_migrate_assessment' }
its('type') { should cmp 'Microsoft.Migrate/assessmentprojects/groups/assessments' }
end
```

```ruby
describe azure_migrate_assessment_machine(resource_group: 'migrated_vms', project_name: 'zoneA_migrate_assessment_project', group_name: 'zoneA_machines_group', name: 'zoneA_machines_migrate_assessment') do
it { should exist }
end
```
## Parameters

| Name | Description |
|----------------|----------------------------------------------------------------------------------|
| name | Name of the Azure Migrate Assessment Machine to test. |
| resource_group | Azure resource group that the targeted resource resides in. `MyResourceGroup` |
| project_name | Azure Migrate Assessment Project. |
| group_name | Unique name of a group within a project. |

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

## Properties

| Property | Description |
|-------------------------------|------------------------------------------------------------------|
| id | Path reference to the assessment. |
| name | Unique name of an assessment. |
| type | Type of the object. `Microsoft.Migrate/assessmentProjects/groups/assessments` |
| eTag | For optimistic concurrency control. |
| properties | Properties of the assessment. |
| properties.azureDiskType | Storage type selected for this disk. |
| properties.currency | Currency to report prices in. |
| properties.sizingCriterion | Assessment sizing criterion. |
| properties.reservedInstance | Azure reserved instance. |


For properties applicable to all resources, such as `type`, `name`, `id`, `properties`, refer to [`azure_generic_resource`](azure_generic_resource.md#properties).

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

## Examples

### Test that the Migrate Assessment Machine has a minimum scalingFactor.

```ruby
describe azure_migrate_assessment_machine(resource_group: 'migrated_vms', project_name: 'zoneA_migrate_assessment_project', group_name: 'zoneA_machines_group', name: 'zoneA_machines_migrate_assessment') do
its('properties.scalingFactor') { should eq 1.0 }
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 Assessment Machine is found it will exist
describe azure_migrate_assessment_machine(resource_group: 'migrated_vms', project_name: 'zoneA_migrate_assessment_project', group_name: 'zoneA_machines_group', name: 'zoneA_machines_migrate_assessment') do
it { should exist }
end

# if Migrate Assessment Machine is not found it will not exist
describe azure_migrate_assessment_machine(resource_group: 'migrated_vms', project_name: 'zoneA_migrate_assessment_project', group_name: 'zoneA_machines_group', name: 'zoneA_machines_migrate_assessment') 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.
127 changes: 127 additions & 0 deletions docs/resources/azure_migrate_assessment_machines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
title: About the azure_migrate_assessment_machines Resource
platform: azure
---

# azure_migrate_assessment_machines

Use the `azure_migrate_assessment_machines` InSpec audit resource to test properties related to all Azure Migrate Assessment Machines 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` can be defined as a resource parameter.
If not provided, the latest version will be used.
For more information, refer to [`azure_generic_resource`](azure_generic_resource.md).

Unless defined, `azure_cloud` global endpoint, and default values for the http client will be used.
For more information, refer to the resource pack [README](../../README.md).

## Availability

### Installation

This resource is available in the [InSpec Azure resource pack](https://github.com/inspec/inspec-azure).
For an example `inspec.yml` file and how to set up your Azure credentials, refer to resource pack [README](../../README.md#Service-Principal).

## Syntax

An `azure_migrate_assessment_machines` resource block returns all Azure Migrate Assessment Machines within a project.

```ruby
describe azure_migrate_assessment_machines(resource_group: 'migrated_vms', project_name: 'zoneA_migrate_assessment_project') do
#...
end
```

## Parameters
| Name | Description |
|----------------|----------------------------------------------------------------------------------|
| resource_group | Azure resource group that the targeted resource resides in. `MyResourceGroup` |
| project_name | Azure Migrate Assessment 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 Assessment Machines. | `id` |
| names | Unique names for all Assessment Machines. | `name` |
| types | Type of the objects. | `type` |
| eTags | A list of eTags for all the Assessment Machines. | `eTag` |
| properties | A list of Properties for all the Assessment Machines. | `properties` |
| azureDiskTypes | Storage type selected for the disk of all the assessments. | `azureDiskType` |
| azureHybridUseBenefits | AHUB discount on windows virtual machines of all the assessments. | `azureHybridUseBenefit`|
| azureLocations | Target Azure locations for which the machines should be assessed. | `azureLocation` |
| azureOfferCodes | Offer codes according to which cost estimation is done. | `azureOfferCode` |
| azurePricingTiers | Pricing tiers for Size evaluation. | `azurePricingTier`|
| azureStorageRedundancies | Storage Redundancy types offered by Azure. | `azureStorageRedundancy`|
| azureVmFamilies | List of azure VM families. | `azureVmFamilies`|
| confidenceRatingInPercentages | Confidence rating percentages for assessment. | `confidenceRatingInPercentage`|
| createdTimestamps | Time when this project was created. | `createdTimestamp` |
| currencies | Currencies to report prices in. | `currency` |
| discountPercentages | Custom discount percentages to be applied on final costs. | `discountPercentage`|
| eaSubscriptionIds | Enterprise agreement subscription arm ids. | `eaSubscriptionId`|
| monthlyBandwidthCosts | Monthly network cost estimates for the machines. | `monthlyBandwidthCost`|
| monthlyComputeCosts | Monthly compute cost estimates for the machines. | `monthlyComputeCost`|
| monthlyPremiumStorageCosts | Monthly premium storage cost estimates for the machines. | `monthlyPremiumStorageCost`|
| monthlyStandardSSDStorageCosts | Monthly standard SSD storage cost estimates for the machines. | `monthlyStandardSSDStorageCost`|
| monthlyStorageCosts | Monthly storage cost estimates for the machines. | `monthlyStorageCost` |
| numberOfMachines | Number of assessed machines part of the assessments. | `numberOfMachines` |
| percentiles | Percentiles of performance data used to recommend Azure size. | `percentile` |
| perfDataEndTimes | End times to consider performance data for assessments. | `perfDataEndTime` |
| perfDataStartTimes | Start times to consider performance data for assessments. | `perfDataStartTime` |
| pricesTimestamps | Times when the Azure Prices were queried. | `pricesTimestamp` |
| reservedInstances | Azure reserved instances. | `reservedInstance`
| scalingFactors | Scaling factors used over utilization data to add a performance buffer for new machines to be created in Azure.| `scalingFactor` |
| sizingCriterions | Assessment sizing criterions. | `sizingCriterion` |
| stages | User configurable setting that describes the status of the assessments.| `stage` |
| statuses | Whether the assessments has been created and is valid. | `status` |
| timeRanges | Time ranges of performance data used to recommend a size. | `timeRange` |
| updatedTimestamps | Times when the project was last updated. | `updatedTimestamp`|
| vmUptimes | Specify the durations for which the VMs are up in the on-premises environment.| `vmUptime` |


<superscript>*</superscript> For information on how to use filter criteria on plural resources refer to [FilterTable usage](https://github.com/inspec/inspec/blob/master/dev-docs/filtertable-usage.md).

## Examples

### Loop through Migrate Assessment Machines by their names.

```ruby
azure_migrate_assessment_machines(resource_group: 'migrated_vms', project_name: 'zoneA_migrate_assessment_project').names.each do |name|
describe azure_container_group(resource_group: 'migrated_vms', project_name: 'zoneA_migrate_assessment_project', group_name: 'zoneA_machines_group', name: name) do
it { should exist }
end
end
```
### Test that there are Migrate Assessment Machines with local redundancy.

```ruby
describe azure_migrate_assessment_machines(resource_group: 'migrated_vms', project_name: 'zoneA_migrate_assessment_project').where(azureStorageRedundancy: 'LocallyRedundant') 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 Assessment Machines are present in the project and in the resource group
describe azure_migrate_assessment_machines(resource_group: 'migrated_vms', project_name: 'zoneA_migrate_assessment_project') do
it { should_not exist }
end

# Should exist if the filter returns at least one Migrate Assessment Machines in the project and in the resource group
describe azure_migrate_assessment_machines(resource_group: 'migrated_vms', project_name: 'zoneA_migrate_assessment_project') do
it { should exist }
end
```
## Azure Permissions

Your [Service Principal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal) must be setup with a `contributor` role on the subscription you wish to test.
24 changes: 24 additions & 0 deletions libraries/azure_migrate_assessment_machine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'azure_generic_resource'

class AzureMigrateAssessmentMachine < AzureGenericResource
name 'azure_migrate_assessment_machine'
desc 'Verifies settings for a collection of Azure Migrate Assessments in a project'
example <<-EXAMPLE
describe azure_migrate_assessment_machine(resource_group: 'migrated_vms', project_name: 'zoneA_migrate_assessment_project', name: '') 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/assessmentProjects', opts)
opts[:required_parameters] = %i(project_name)
opts[:resource_path] = [opts[:project_name], 'machines'].join('/')
super(opts, true)
end

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

class AzureMigrateAssessmentMachines < AzureGenericResources
name 'azure_migrate_assessment_machines'
desc 'Verifies settings for a collection of Azure Migrate Assessments in a project'
example <<-EXAMPLE
describe azure_migrate_assessment_machines(resource_group: 'migrated_vms', project_name: 'zoneA_migrate_assessment_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/assessmentProjects', opts)
opts[:required_parameters] = %i(project_name)
opts[:resource_path] = [opts[:project_name], 'machines'].join('/')
super(opts, true)
return if failed_resource?

populate_filter_table_from_response
end

def to_s
super(AzureMigrateAssessmentMachines)
end

private

def populate_table
@resources.each do |resource|
@table << resource.merge(resource[:properties])
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
resource_group = input(:resource_group, value: '')
project_name = input(:inspec_migrate_project_name, value: '')
# either way these are manual values since there is no terraform resource available
name = 'inspec-migrate-test-assement'

control 'verify a azure migrate assessment machine' do
describe azure_migrate_assessment_machine(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/assessmentprojects/groups/assessments' }
its('properties.azurePricingTier') { should eq 'Standard' }
its('properties.azureStorageRedundancy') { should eq 'LocallyRedundant' }
its('properties.groupType') { should eq 'Import' }
its('properties.scalingFactor') { should eq 1.0 }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
resource_group = input(:resource_group, value: '')
project_name = input(:inspec_migrate_project_name, value: '')
name = 'inspec-migrate-test-assement'

control 'verify all azure migrate assessments in a project' do
describe azure_migrate_assessment_machines(resource_group: resource_group, project_name: project_name) do
it { should exist }
its('names') { should include name }
its('types') { should include 'Microsoft.Migrate/assessmentprojects/groups/assessments' }
its('azurePricingTiers') { should include 'Standard' }
its('azureStorageRedundancies') { should include 'LocallyRedundant' }
its('groupTypes') { should include 'Import' }
its('scalingFactors') { should include 1.0 }
end
end
17 changes: 17 additions & 0 deletions test/unit/resources/azure_migrate_assessment_machine_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require_relative 'helper'
require 'azure_migrate_assessment_machine'

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

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

def test_resource_group_name_alone_ok
assert_raises(ArgumentError) { AzureMigrateAssessmentMachine.new(name: 'my-name', resource_group: 'test') }
end
end
21 changes: 21 additions & 0 deletions test/unit/resources/azure_migrate_assessment_machines_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative 'helper'
require 'azure_migrate_assessment_machines'

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

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

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

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