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 project #443

Merged
merged 9 commits into from
Nov 15, 2021
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ The following is a list of static resources.
- [azure_migrate_assessment_projects](docs/resources/azure_migrate_assessment_projects.md)
- [azure_migrate_assessment_group](docs/resources/azure_migrate_assessment_group.md)
- [azure_migrate_assessment_groups](docs/resources/azure_migrate_assessment_groups.md)
- [azure_migrate_project](docs/resources/azure_migrate_project.md)
- [azure_migrate_project_database](docs/resources/azure_migrate_project_database.md)
- [azure_migrate_project_databases](docs/resources/azure_migrate_project_databases.md)
- [azure_migrate_project_event](docs/resources/azure_migrate_project_event.md)
Expand Down
100 changes: 100 additions & 0 deletions docs/resources/azure_migrate_project.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
title: About the azure_migrate_project Resource
platform: azure
---

# azure_migrate_project

Use the `azure_migrate_project` InSpec audit resource to test properties related to an Azure Migrate 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

`name` and `resource_group` is a required parameter.

```ruby
describe azure_migrate_project(resource_group: 'RESOURCE_GROUP', name: 'PROJECT_NAME') do
it { should exist }
its('name') { should eq 'zoneA_migrate_project' }
its('type') { should eq 'Microsoft.Migrate/MigrateProjects' }
end
```

```ruby
describe azure_migrate_project(resource_group: 'RESOURCE_GROUP', name: 'PROJECT_NAME') do
it { should exist }
end
```

## Parameters

| Name | Description |
|----------------|----------------------------------------------------------------------------------|
| name | Name of the Azure migrate projectto test. |
| resource_group | Azure resource group that the targeted resource resides in. |

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

## Properties

| Property | Description |
|--------------------------|------------------------------------------------------------------|
| id | Path reference to the Migrate Project. |
| eTag | The eTag for concurrency control. |
| name | Unique name of an Migrate Project. |
| type | Type of the object. `Microsoft.Migrate/MigrateProject` |
| properties | The nested properties. |

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 the [Azure documentation](https://docs.microsoft.com/en-us/rest/api/migrate/projects/migrate-projects/get-migrate-project) for other available properties.
Any attribute in the response nested within properties may be accessed with the key names separated by dots (`.`) and attributes nested in the assessment data is pluralized and listed as collection.

## Examples

### Test That The migrate projectHas Server Instance Type.

```ruby
describe azure_migrate_project(resource_group: 'RESOURCE_GROUP', name: 'PROJECT_NAME') do
its('properties.summary.servers.instanceType') { should eq 'Servers' }
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 projectis found it exists
describe azure_migrate_project(resource_group: 'RESOURCE_GROUP', name: 'PROJECT_NAME') do
it { should exist }
end

# If migrate project is not found it does not exist
describe azure_migrate_project(resource_group: 'RESOURCE_GROUP', name: 'PROJECT_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 setup with a `contributor` role on the subscription you wish to test.
22 changes: 22 additions & 0 deletions libraries/azure_migrate_project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'azure_generic_resource'

class AzureMigrateProject < AzureGenericResource
name 'azure_migrate_project'
desc 'Retrieves and verifies the settings of an Azure Migrate Project.'
example <<-EXAMPLE
describe azure_migrate_project(resource_group: 'migrated_vms', 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/migrateProjects', opts)
super(opts, true)
end

def to_s
super(AzureMigrateProject)
end
end
12 changes: 12 additions & 0 deletions test/integration/verify/controls/azure_migrate_project.rb
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')

control 'test the properties of an azure migrate project' do
describe azure_migrate_project(resource_group: resource_group, name: project_name) do
it { should exist }
its('name') { should eq project_name }
its('type') { should eq 'Microsoft.Migrate/MigrateProjects' }
its('properties.registeredTools') { should include 'ServerAssessment' }
its('properties.summary.servers.instanceType') { should eq 'Servers' }
end
end
17 changes: 17 additions & 0 deletions test/unit/resources/azure_migrate_project_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require_relative 'helper'
require 'azure_migrate_project'

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

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

def test_resource_group_name_alone_ok
assert_raises(ArgumentError) { AzureMigrateProject.new(resource_group: 'test') }
end
end