Skip to content

Commit

Permalink
Merge pull request #637 from inspec/support-azure-cache-skus
Browse files Browse the repository at this point in the history
RESOURCE-104 Support azure cache skus
  • Loading branch information
sathish-progress authored Apr 11, 2022
2 parents 954a40a + 983fff0 commit b473a1e
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ The following is a list of static resources.
- [azure_graph_user](docs/resources/azure_graph_user.md)
- [azure_graph_users](docs/resources/azure_graph_users.md)
- [azure_hdinsight_cluster](docs/resources/azure_hdinsight_cluster.md)
- [azure_hpc_cache_skus](https://docs.chef.io/inspec/resources/azure_hpc_cache_skus/)
- [azure_iothub](docs/resources/azure_iothub.md)
- [azure_iothub_event_hub_consumer_group](docs/resources/azure_iothub_event_hub_consumer_group.md)
- [azure_iothub_event_hub_consumer_groups](docs/resources/azure_iothub_event_hub_consumer_groups.md)
Expand Down Expand Up @@ -542,9 +543,9 @@ describe azure_virtual_machine(resource_group: 'RESOURCE_GROUP', name: 'NAME', a
end
```

### Pre-defined Default API Version
### Pre-defined Default Api Version

`default` API version can be used if it is supported by the resource provider.
`default` api version can be used if it is supported by the resource provider.

```ruby
describe azure_generic_resource(resource_provider: 'Microsoft.Compute/virtualMachines', name: 'NAME', api_version: 'DEFAULT') do
Expand Down Expand Up @@ -783,7 +784,8 @@ To run integration tests:
rake test:integration
```

Please note that Graph API resource requires specific privileges granted to your service principal. Please refer to the [Microsoft Documentation](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-integrating-applications#updating-an-application) for information on how to grant these permissions to your application.
Please note that Graph API resource requires specific privileges granted to your service principal.
Please refer to the [Microsoft Documentation](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-integrating-applications#updating-an-application) for information on how to grant these permissions to your application.

To run a control called `azure_virtual_machine` only:

Expand Down
85 changes: 85 additions & 0 deletions docs-chef-io/content/inspec/resources/azure_hpc_cache_skus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
+++
title = "azure_hpc_cache_skus Resource"
platform = "azure"
draft = false
gh_repo = "inspec-azure"

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

Use the `azure_hpc_cache_skus` InSpec audit resource to test the properties related to all Azure HPC Cache SKUs.

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

{{% inspec_azure_common_parameters %}}

## Installation

{{% inspec_azure_install %}}

## Syntax

An `azure_hpc_cache_skus` resource block returns all Azure HPC Cache SKUs.

```ruby
describe azure_hpc_cache_skus do
#...
end
```

## Parameters

## Properties

`resourceTypes`
: A resource types list of the SKU applies to. **Field**: `resourceType`

`names`
: A list of SKU names. **Field**: `name`

`sizes`
: A list of the SKU sizes. **Field**: `size`

`tiers`
: A tiers list of VM in a scale set. **Field**: `tier`

`kind`
: The supported kind list of resources. **Field**: `kind`

{{% inspec_filter_table %}}

## Examples

### Ensure that there are Standard tier HPC Cache SKUs

```ruby
describe azure_hpc_cache_skus.where(tier: 'STANDARD') 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 HPC Cache SKUs are present

describe azure_hpc_cache_skus do
it { should_not exist }
end
# Should exist if the filter returns at least one HPC Cache SKUs

describe azure_hpc_cache_skus do
it { should exist }
end
```

## Azure Permissions

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

class AzureHPCCacheSKUs < AzureGenericResources
name 'azure_hpc_cache_skus'
desc 'Verifies settings for a collection of Azure HPC Storage SKUs'
example <<-EXAMPLE
describe azure_hpc_cache_skus 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/skus', opts)
super(opts, true)
return if failed_resource?

populate_filter_table_from_response
end

def to_s
super(AzureHPCCacheSKUs)
end
end
10 changes: 10 additions & 0 deletions test/integration/verify/controls/azure_hpc_cache_skus.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
describe azure_hpc_cache_skus do
it { should exist }
its('tier') { should eq 'Standard' }
its('size') { should eq 'A0' }
end

describe azure_hpc_cache_skus.where(tier: 'Standard') do
it { should exist }
its('size') { should eq 'A0' }
end
21 changes: 21 additions & 0 deletions test/unit/resources/azure_hpc_cache_skus_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative 'helper'
require 'azure_hpc_cache_skus'

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

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

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

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

0 comments on commit b473a1e

Please sign in to comment.