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

adding pipeline resource #441

Merged
merged 13 commits into from
Nov 12, 2021
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ The following is a list of static resources.
- [azure_data_factory](docs/resources/azure_data_factory.md)
- [azure_data_factory_linked_service](docs/resources/azure_data_factory_linked_service.md)
- [azure_data_factory_linked_services](docs/resources/azure_data_factory_linked_services.md)
- [azure_data_factory_pipeline](docs/resources/azure_data_factory_pipeline.md)
- [azure_data_factory_pipelines](docs/resources/azure_data_factory_pipelines.md)
- [azure_db_migration_service](docs/resources/azure_db_migration_service.md)
- [azure_db_migration_services](docs/resources/azure_db_migration_services.md)
- [azure_ddos_protection_resource](docs/resources/azure_ddos_protection_resource.md)
Expand Down
85 changes: 85 additions & 0 deletions docs/resources/azure_data_factory_pipeline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
title: About the azure_data_factory_pipeline Resource
platform: azure
---

# azure_data_factory_pipeline

Use the `azure_data_factory_pipeline` InSpec audit resource to test properties of an Azure pipeline.

## 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).
For api related info : [`Azure pipeline Docs`](https://docs.microsoft.com/en-us/rest/api/datafactory/pipelines/get).


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

`resource_group` and `pipeline_name`, `factory_name` must be given as parameters.

```ruby
describe azure_data_factory_pipeline(resource_group: 'RESOURCE_GROUP', factory_name: 'FACTORY_NAME', pipeline_name: 'PIPELINE_NAME') do
#...
end
```

## Parameters

| Name | Description |
|--------------------------------|-----------------------------------------------------------------------------------|
| resource_group | Azure resource group that the targeted resource resides in. `MyResourceGroup` |
| factory_name | Name for the data factory that you want to create your pipeline in.. |
| pipeline_name | The pipeline name. |

All the parameter sets needs be provided for a valid query:
- `resource_group` , `factory_name` and `pipeline_name`
## Properties

| Name | Description |
|--------------------------------|----------------------------------------------------------------------------------|
| name | Name of the Azure resource to test. |
| id | The pipeline type. |
| properties | The properties of the Resource. |

## Examples

### Test That A Pipeline Exists

```ruby
describe azure_data_factory_pipeline(resource_group: 'RESOURCE_GROUP', factory_name: 'FACTORY_NAME', pipeline_name: 'PIPELINE_NAME') do
it { should exist }
end
```

### Test That A Pipeline Does Not Exist

```ruby
describe azure_data_factory_pipeline(resource_group: 'RESOURCE_GROUP', factory_name: 'FACTORY_NAME', pipeline_name: 'PIPELINE_NAME') do
it { should_not exist }
end
```

### Test Properties Of A Pipeline

```ruby
describe azure_data_factory_pipeline(resource_group: 'RESOURCE_GROUP', factory_name: 'FACTORY_NAME', pipeline_name: 'PIPELINE_NAME') do
its('name') { should eq 'PIPELINE_NAME' }
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.
77 changes: 77 additions & 0 deletions docs/resources/azure_data_factory_pipelines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
title: About the azure_data_factory_pipelines Resource
platform: azure
---

# azure_data_factory_pipelines

Use the `azure_data_factory_pipelines` InSpec audit resource to test properties related to pipeline for a resource group or the entire subscription.

## 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).
For api related info : [`Azure pipeline Docs`](https://docs.microsoft.com/en-us/rest/api/datafactory/pipelines/list-by-factory).
## 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_data_factory_pipelines` resource block returns all Azure pipeline, either within a resource group (if provided), or within an entire subscription.

```ruby
describe azure_data_factory_pipelines(resource_group: 'RESOURCE_GROUP', factory_name: 'FACTORY_NAME') do
#...
end
```

`resource_group` and `factory_name` must be given as parameters.

## Parameters

| Name | Description |
|--------------------------------|-----------------------------------------------------------------------------------|
| resource_group | Azure resource group that the targeted resource resides in. |
| factory_name | Azure Factory Name for which pipeline are being retrived.|

## Properties

| Property | Description | Filter Criteria<superscript>*</superscript> |
|-----------------|---------------------------------------------------------|-----------------|
| names | A list of the unique resource names. | `name` |
| ids | A list of pipeline IDs . | `id` |
| properties | A list of properties for the resource | `properties` |

<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

### Test If Any Pipeline Exist In The Resource Group

```ruby
describe azure_data_factory_pipelines(resource_group: 'RESOURCE_GROUP', factory_name: 'FACTORY_NAME') do
it { should exist }
its('names') { should include 'pipeline_name' }
end
```

### Test that there aren't any pipeline in a resource group

```ruby
# Should not exist if no pipeline are in the resource group
describe azure_data_factory_pipelines(resource_group: 'example', factory_name: 'fake') 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.
31 changes: 31 additions & 0 deletions libraries/azure_data_factory_pipeline.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'azure_generic_resource'

class AzureDataFactoryPipeline < AzureGenericResource
name 'azure_data_factory_pipeline'
desc 'Verifies settings for Azure data factory pipeline '
example <<-EXAMPLE
describe azure_data_factory_pipeline(resource_group: resource_group, factory_name: factory_name, pipeline_name: pipeline_name) do
it { should exist }
end
EXAMPLE

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 for the resource:
# GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
# providers/Microsoft.DataFactory/factories/{factoryName}/pipelines/{pipelineName}?api-version=2018-06-01
#
opts[:resource_provider] = specific_resource_constraint('Microsoft.DataFactory/factories', opts)
opts[:required_parameters] = %i(factory_name)
opts[:resource_path] = [opts[:factory_name], 'pipelines'].join('/')
opts[:resource_identifiers] = %i(pipeline_name)
# static_resource parameter must be true for setting the resource_provider in the backend.
super(opts, true)
end

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

class AzureDataFactoryPipelines < AzureGenericResources
name 'azure_data_factory_pipelines'
desc 'List azure pipelines by data factory.'
example <<-EXAMPLE
describe azure_data_factory_pipelines(resource_group: 'example', factory_name: 'fn') do
it { should exist }
end
EXAMPLE

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 for the resource:
# GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
# providers/Microsoft.DataFactory/factories/{factoryName}/pipelines?api-version=2018-06-01
opts[:resource_provider] = specific_resource_constraint('Microsoft.DataFactory/factories', opts)
opts[:required_parameters] = %i(factory_name)
opts[:resource_path] = [opts[:factory_name], 'pipelines'].join('/')
# 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

# FilterTable is populated at the very end due to being an expensive operation.
populate_filter_table_from_response
end

def to_s
super(AzureDataFactoryPipelines)
end

private

def populate_table
@resources.each do |resource|
@table << resource.merge(resource[:properties])
end
end
end
5 changes: 5 additions & 0 deletions terraform/azure.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,11 @@ resource "azurerm_data_factory" "adf" {
resource_group_name = azurerm_resource_group.rg.name
}

resource "azurerm_data_factory_pipeline" "df_pipeline" {
name = "example-pipeline"
resource_group_name = azurerm_resource_group.rg.name
data_factory_name = azurerm_data_factory.adf.name
}
resource "azurerm_data_factory_linked_service_mysql" "dflsmsql" {
name = "dflsm-sql"
resource_group_name = azurerm_resource_group.rg.name
Expand Down
5 changes: 5 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@ output "df_name" {
output "df_location" {
value = azurerm_data_factory.adf.location
}

output "df_pipeline_name" {
value = azurerm_data_factory_pipeline.df_pipeline.name
}

output "inspec_db_migration_service_name" {
value = var.inspec_db_migration_service.name
}
Expand Down
19 changes: 19 additions & 0 deletions test/integration/verify/controls/azure_data_factory_pipeline.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
resource_group = input('resource_group', value: nil)
factory_name = input('df_name', value: nil)
pipelines_name = input('df_pipeline_name', value: nil)
control 'azure_data_factory_pipeline' do

describe azure_data_factory_pipeline(resource_group: resource_group, factory_name: factory_name, pipeline_name: pipelines_name) do
it { should exist }
its('name') { should eq pipelines_name }
its('type') { should eq 'Microsoft.DataFactory/factories/pipelines' }
end

describe azure_data_factory_pipeline(resource_group: resource_group, factory_name: 'fake', pipeline_name: pipelines_name) do
it { should_not exist }
end

describe azure_data_factory_pipeline(resource_group: 'fake', factory_name: factory_name, pipeline_name: pipelines_name) do
it { should_not exist }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource_group = input('resource_group', value: nil)
factory_name = input('df_name', value: nil)
pipelines_name = input('df_pipeline_name', value: nil)

control 'azure_data_factory_pipelines' do
describe azure_data_factory_pipelines(resource_group: resource_group, factory_name: factory_name) do
it { should exist }
its('names') { should include pipelines_name }
its('types') { should include 'Microsoft.DataFactory/factories/pipelines' }
end
end
17 changes: 17 additions & 0 deletions test/unit/resources/azure_data_factory_pipeline_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require_relative 'helper'
require 'azure_data_factory_pipeline'

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

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

def test_resource_group
assert_raises(ArgumentError) { AzureDataFactoryPipeline.new(name: 'my-name') }
end
end
25 changes: 25 additions & 0 deletions test/unit/resources/azure_data_factory_pipelines_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require_relative 'helper'
require 'azure_data_factory_pipelines'

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

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

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

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

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