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

Resource 106 hpc asc operations #649

Merged
merged 7 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ The following is a list of static resources.
- [azure_graph_user](https://docs.chef.io/inspec/resources/azure_graph_user/)
- [azure_graph_users](https://docs.chef.io/inspec/resources/azure_graph_users/)
- [azure_hdinsight_cluster](https://docs.chef.io/inspec/resources/azure_hdinsight_cluster/)
- [azure_hpc_asc_operation](https://docs.chef.io/inspec/resources/azure_hpc_asc_operation/)
- [azure_iothub](https://docs.chef.io/inspec/resources/azure_iothub/)
- [azure_iothub_event_hub_consumer_group](https://docs.chef.io/inspec/resources/azure_iothub_event_hub_consumer_group/)
- [azure_iothub_event_hub_consumer_groups](https://docs.chef.io/inspec/resources/azure_iothub_event_hub_consumer_groups/)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
+++
title = "azure_hpc_asc_operation Resource"
platform = "azure"
draft = false
gh_repo = "inspec-azure"

[menu.inspec]
title = "azure_hpc_asc_operation"
identifier = "inspec/resources/azure/azure_hpc_asc_operation Resource"
parent = "inspec/resources/azure"
+++

Use the `azure_hpc_asc_operation` InSpec audit resource to test properties related to an Azure HPC ASC Operation.

## Azure REST API Version, Endpoint, and HTTP Client Parameters

{{% inspec_azure_common_parameters %}}

## Installation

{{% inspec_azure_install %}}

## Syntax

`name`, `cache_name`, `resource_group` is a required parameter.

```ruby
describe azure_hpc_asc_operation(location: 'LOCATION', operation_id: 'OPERATION_ID') do
it { should exist }
its('type') { should eq 'Microsoft.StorageCache/Cache/StorageTarget' }
its('location') { should eq 'East US' }
end
```

```ruby
describe azure_hpc_asc_operation(location: 'LOCATION', operation_id: 'OPERATION_ID') do
it { should exist }
end
```

## Parameters

`location` _(required)_
: The name of the region used to look up the operation.

`operation_id` _(required)_
: The operation id which uniquely identifies the asynchronous operation.

## Properties

`id`
: The operation Id.

`name`
: The operation name.

`startTime`
: The start time of the operation.

`status`
: The status of the operation.

`endTime`
: The end time of the operation.

For properties applicable to all resources, such as `type`, `name`, `id`, `properties`, refer to [`azure_generic_resource`]({{< relref "azure_generic_resource.md#properties" >}}).

Also, refer to [Azure documentation](https://docs.microsoft.com/en-us/rest/api/storagecache/asc-operations/get#ascoperation) for other properties available.

## Examples

**Test that the HPC ASC Operation is Succeeded.**

```ruby
describe azure_hpc_asc_operation(location: 'LOCATION', operation_id: 'OPERATION_ID') do
its('status') { should eq 'Succeeded' }
end
```

## Matchers

{{% inspec_matchers_link %}}

### exists

```ruby
# If a HPC ASC Operation is found it will exist
describe azure_hpc_asc_operation(location: 'LOCATION', operation_id: 'OPERATION_ID') do
it { should exist }
end
# if HPC ASC Operation is not found it will not exist
describe azure_hpc_asc_operation(location: 'LOCATION', operation_id: 'OPERATION_ID') do
it { should_not exist }
end
```

## Azure Permissions

{{% azure_permissions_service_principal role="reader" %}}
24 changes: 24 additions & 0 deletions libraries/azure_hpc_asc_operation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'azure_generic_resource'

class AzureHPCASCOperation < AzureGenericResource
name 'azure_hpc_asc_operation'
desc 'Retrieves and verifies the settings of an Azure HPC ASC Operation'
example <<-EXAMPLE
describe azure_hpc_asc_operation(location: 'westus', operation_id: 'testoperationid') 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.StorageCache/locations', opts)
opts[:required_parameters] = %i(location operation_id)
opts[:resource_path] = [opts[:location], 'ascOperations', opts[:operation_id]].join('/')
super(opts, true)
end

def to_s
super(AzureHPCASCOperations)
end
end
9 changes: 9 additions & 0 deletions test/integration/verify/controls/azure_hpc_asc_operation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
location = input(:location, value: '')

control 'Verify settings of an Azure HPC ASC Operation' do
describe azure_hpc_asc_operation(location: location, operation_id: 'testoperation') do
it { should exist }
its('name') { should eq 'testoperation' }
its('status') { should eq 'Succeeded' }
end
end
17 changes: 17 additions & 0 deletions test/unit/resources/azure_hpc_asc_operation_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require_relative 'helper'
require 'azure_hpc_asc_operation'

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

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

def test_resource_group_name_alone_not_ok
assert_raises(ArgumentError) { AzureHPCASCOperation.new(resource_group: 'test') }
end
end