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 azure migrate assessments #424

Merged
merged 31 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4c7ca89
support Bignum and Float for create method
sathish-progress Aug 4, 2021
e9a20a3
support azure migrate assessment(s)
sathish-progress Aug 4, 2021
74ae5d7
unit test azure migrate assessment(s)
sathish-progress Aug 4, 2021
2bf1277
integrate test azure migrate assessment(s)
sathish-progress Aug 4, 2021
f1c0d4e
tf support outputs and variables
sathish-progress Aug 4, 2021
1a38568
update docs for migrate assessment(s)
sathish-progress Aug 4, 2021
8d17b24
Merge branch 'master' into support-azure-migrate-assessments
sathish-progress Aug 5, 2021
527df9e
Merge branch 'master' of github.com:inspec/inspec-azure into support-…
sathish-progress Aug 19, 2021
1363fbf
fix azure tf
sathish-progress Aug 19, 2021
5ab1e61
implement to_s
sathish-progress Aug 19, 2021
40c81f8
use populate tabel from response
sathish-progress Aug 19, 2021
892221b
update docs
sathish-progress Aug 19, 2021
78ce9e7
Merge branch 'main' into support-azure-migrate-assessments
sathish-progress Aug 31, 2021
6032a80
Merge branch 'main' of github.com:inspec/inspec-azure into support-az…
sathish-progress Aug 31, 2021
1f6adf5
edits
dkumaras Sep 9, 2021
ee421e1
fix required params doc
sathish-progress Sep 13, 2021
d14856f
Update docs/resources/azure_migrate_assessment.md
sathish-progress Sep 13, 2021
a267ecd
Update docs/resources/azure_migrate_assessment.md
sathish-progress Sep 13, 2021
d27c5b6
Update docs/resources/azure_migrate_assessments.md
sathish-progress Sep 13, 2021
c78f077
Update docs/resources/azure_migrate_assessments.md
sathish-progress Sep 13, 2021
04cec98
fix docs link
sathish-progress Sep 13, 2021
74e8f7b
Ian's comments
dkumaras Sep 13, 2021
e523c42
title case changes
dkumaras Sep 15, 2021
ad22f46
Merge branch 'main' of github.com:inspec/inspec-azure into support-az…
sathish-progress Sep 16, 2021
e80007a
removing changes to azure_migrate_project_database.md file
dkumaras Sep 17, 2021
7a963a0
removed unwanted changes from project db file
dkumaras Sep 17, 2021
a600d5d
removing changes made to docs/resources/azure_migrate_project_databas…
dkumaras Sep 20, 2021
81f2d51
user defined name changes
dkumaras Sep 22, 2021
184013c
Merge branch 'support-azure-migrate-assessments' of github.com:inspec…
sathish-progress Sep 23, 2021
efd0214
Merge branch 'main' of github.com:inspec/inspec-azure into support-az…
sathish-progress Sep 23, 2021
d827add
Merge branch 'main' into support-azure-migrate-assessments
sathish-progress Sep 24, 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,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](docs/resources/azure_migrate_assessment.md)
- [azure_migrate_assessments](docs/resources/azure_migrate_assessments.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
2 changes: 1 addition & 1 deletion docs/resources/azure_generic_resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ where

The following parameters can be passed for targeting a specific Azure resource.

| Name | Description |
| Name |Description |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this change.

|--------------------------------------|----------------------------------------------------------------------------------------------------------|
| resource_group | Azure resource group that the targeted resource has been created in. `MyResourceGroup` |
| name | Name of the Azure resource to test. `MyResourceName` |
Expand Down
102 changes: 102 additions & 0 deletions docs/resources/azure_migrate_assessment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
title: About the azure_migrate_assessment Resource
platform: azure
---

# azure_migrate_assessment

Use the `azure_migrate_assessment` InSpec audit resource to test the properties related to Azure Migrate Assessments.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment is a generic term so it should be lowercase. The same goes for all the other uses of "assessment". It's also singular "assessment" in this resource, but plural in the other resource.


## 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 are 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` is a required parameter, and `resource_group` is an optional parameter.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 52 shows four required parameters, not two.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is done


```ruby
describe azure_migrate_assessment(resource_group: 'MIGRATED_VMS', project_name: 'ZONEA_MIGRATE_ASSESSMENT_PROJECT', group_name: 'ZONEA_MACHINES_GROUP', NAME: 'ZONEA_MACHINES_MIGRATE_ASSESSMENT') do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The placeholder values for the parameters should be more generic. So MIGRATED_VMS can just be RESOURCE_GROUP, ZONEA_MIGRATE_ASSESSMENT_PROJECT can just be PROJECT_NAME, ZONEA_MACHINES_GROUP can just be GROUP_NAME, and ZONEA_MACHINES_MIGRATE_ASSESSMENT should be MIGRATE_ASSESSMENT_NAME.

The same goes for the other code examples.

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(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 to test. |
| resource_group | Azure resource group where 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`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ands can be replaced with commas.


## Properties

| Property | Description |
|-------------------------------|------------------------------------------------------------------|
| id | Path reference to the assessment. |
| name | Unique name of an assessment. |
| type | Object type. `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`, 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/assessment/assessments/get) for other properties available. Any attribute in the response is accessed with the key names separated by dots (`.`).
sathish-progress marked this conversation as resolved.
Show resolved Hide resolved

## Examples

### Test that the Migrate Assessments has a minimum scalingFactor
sathish-progress marked this conversation as resolved.
Show resolved Hide resolved

```ruby
describe azure_migrate_assessment(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 Assessments is found, it will exist
describe azure_migrate_assessment(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 Assessments are not found, it will not exist
describe azure_migrate_assessment(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 set up with a `contributor` role on the subscription you wish to test.
125 changes: 125 additions & 0 deletions docs/resources/azure_migrate_assessments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
title: About the azure_migrate_assessments Resource
platform: azure
---

# azure_migrate_assessments

Use the `azure_migrate_assessments` InSpec audit resource to test the properties related to all Azure Migrate Assessments 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_assessments` resource block returns all Azure Migrate Assessments within a project.

```ruby
describe azure_migrate_assessments(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 assessments. | `id` |
| names | Unique names for all assessments. | `name` |
| types | Type of the objects. | `type` |
| eTags | A list of eTags for all the assessments. | `eTag` |
| properties | A list of Properties for all the assessments. | `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 is 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 are 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 have been created and is valid. | `status` |
| timeRanges | Time ranges of performance data used to recommend a size. | `timeRange` |
| updatedTimestamps | Times when the project is last updated. | `updatedTimestamp`|
| vmUptimes | Specify the durations for which the VMs are up in the on-premises environment.| `vmUptime` |


sathish-progress marked this conversation as resolved.
Show resolved Hide resolved
<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 Assessments by their names

```ruby
azure_migrate_assessments(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 to ensure Migrate Assessments with local redundancy
sathish-progress marked this conversation as resolved.
Show resolved Hide resolved

```ruby
describe azure_migrate_assessments(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 Assessments are present in the project and in the resource group
describe azure_migrate_assessments(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 in the project and in the resource group
describe azure_migrate_assessments(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 set up with a `contributor` role on the subscription you wish to test.
2 changes: 1 addition & 1 deletion libraries/azure_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ def create_method(object, name, value)
# Create the necessary method based on the var that has been passed
# Test the value for its type so that the method can be setup correctly
case value.class.to_s
when 'String', 'Integer', 'TrueClass', 'FalseClass', 'Fixnum', 'Time'
when 'String', 'Integer', 'TrueClass', 'FalseClass', 'Fixnum', 'Time', 'Bignum', 'Float'
object.define_singleton_method name do
value
end
Expand Down
24 changes: 24 additions & 0 deletions libraries/azure_migrate_assessment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'azure_generic_resource'

class AzureMigrateAssessment < AzureGenericResource
name 'azure_migrate_assessment'
desc 'Retrieves and verifies the settings of a container group instance.'
example <<-EXAMPLE
describe azure_migrate_assessment(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
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 group_name name)
opts[:resource_path] = [opts[:project_name], 'groups', opts[:group_name], 'assessments'].join('/')
super(opts, true)
end

def to_s
super(AzureMigrateAssessment)
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_s implementation is missing .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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

class AzureMigrateAssessments < AzureGenericResources
name 'azure_migrate_assessments'
desc 'Verifies settings for a collection of Azure Migrate Assessments in a project'
example <<-EXAMPLE
describe azure_migrate_assessments(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], 'assessments'].join('/')
super(opts, true)
return if failed_resource?

populate_filter_table_from_response
end

def to_s
super(AzureMigrateAssessments)
end

private

def populate_table
@resources.each do |resource|
@table << resource.merge(resource[:properties])
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_s implementation is missing .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

9 changes: 5 additions & 4 deletions terraform/azure.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1340,14 +1340,15 @@ resource "azurerm_policy_assignment" "inspec_compliance_policy_assignment" {
}

resource "azurerm_bastion_host" "abh" {
name = "test_bastion"
location = azurerm_resource_group.rg.location
name = "test_bastion"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
ip_configuration {
name = "configuration"
subnet_id = azurerm_subnet.subnet.id
name = "configuration"
subnet_id = azurerm_subnet.subnet.id
public_ip_address_id = azurerm_public_ip.public_ip_address.id
}
}

}

Expand Down
5 changes: 5 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,8 @@ output "inspec_virtual_wan" {
description = "The resource name of the inspec virtual WAN"
value = azurerm_virtual_wan.inspec-nw-wan.name
}

output "inspec_migrate_project_name" {
description = "The name of the Azure Migrate Project that was setup manually since there is no tf resource"
value = var.inspec_migrate_project_name
}
4 changes: 4 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ variable "inspec_container_group_name" {
default = "inspec_container_trial"
}

variable "inspec_migrate_project_name" {
default = "inspec-migrate-integ117eproject"
}

variable "sample_directory_object" {
default = "adc07321-ef2b-44d5-a210-559aa5f10f2d"
}
Expand Down
Loading