Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
title: About the aws_network_manager_customer_gateway_association Resource
platform: aws
---

# aws_network_manager_customer_gateway_association

Use the `aws_network_manager_customer_gateway_association` InSpec audit resource to test properties of a single specific AWS Network Manager customer gateway association.

The `AWS::NetworkManager::CustomerGatewayAssociation` resource specifies an association between a customer gateway, a device, and optionally, a link.

## Syntax

Ensure that the customer gateway association exists.

describe aws_network_manager_customer_gateway_association(global_network_id: 'GLOBAL_NETWORK_ID', customer_gateway_arn: 'CUSTOMER_GATEWAY_ARN') do
it { should exist }
end

## Parameters

`global_network_id` _(required)_

The ID of the global network.

`customer_gateway_arn` _(required)_

The Amazon Resource Name (ARN) of the customer gateway.

For additional information, see the [AWS documentation on AWS Network Manager Customer Gateway Association.](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-networkmanager-customergatewayassociation.html).

## Properties

| Property | Description |
| --- | --- |
| customer_gateway_arn | The Amazon Resource Name (ARN) of the customer gateway. |
| global_network_id | The ID of the global network. |
| device_id | The ID of the device.|
| link_id | The ID of the link. |
| state | The association state. |

## Examples

### Ensure a customer gateway arn is available.

describe aws_network_manager_customer_gateway_association(global_network_id: 'GLOBAL_NETWORK_ID', customer_gateway_arn: 'CUSTOMER_GATEWAY_ARN') do
its('customer_gateway_arn') { should eq 'CustomerGatewayARN' }
end

### Ensure that the state is `active`.

describe aws_network_manager_customer_gateway_association(global_network_id: 'GLOBAL_NETWORK_ID', customer_gateway_arn: 'CUSTOMER_GATEWAY_ARN') do
its('state') { should eq 'AVAILABLE' }
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/).

The controls will pass if the `get` method returns at least one result.

### exist

Use `should` to test that the entity exists.

describe aws_network_manager_customer_gateway_association(global_network_id: 'GLOBAL_NETWORK_ID', customer_gateway_arn: 'CUSTOMER_GATEWAY_ARN') do
it { should exist }
end

Use `should_not` to test the entity does not exist.

describe aws_network_manager_customer_gateway_association(global_network_id: 'GLOBAL_NETWORK_ID', customer_gateway_arn: 'CUSTOMER_GATEWAY_ARN') do
it { should_not exist }
end

### be_available

Use `should` to check if the entity is available.

describe aws_network_manager_customer_gateway_association(global_network_id: 'GLOBAL_NETWORK_ID', customer_gateway_arn: 'CUSTOMER_GATEWAY_ARN') do
it { should be_available }
end

## AWS Permissions

Your [Principal](https://docs.aws.amazon.com/IAM/latest/UserGuide/intro-structure.html#intro-structure-principal) will need the `NetworkManager:Client:GetCustomerGatewayAssociationsResponse` action with `Effect` set to `Allow`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
title: About the aws_network_manager_customer_gateway_associations Resource
platform: aws
---

# aws_network_manager_customer_gateway_associations

Use the `aws_network_manager_customer_gateway_associations` InSpec audit resource to test properties of multiple AWS Network Manager customer gateway associations.

The `AWS::NetworkManager::CustomerGatewayAssociation` resource specifies an association between a customer gateway, a device, and optionally, a link.

## Syntax

Ensure that the customer gateway association exists.

describe aws_network_manager_customer_gateway_associations(global_network_id: "GLOBAL_NETWORK_ID") do
it { should exist }
end

## Parameters

`global_network_id` _(required)_

The ID of the global network.

For additional information, see the [AWS documentation on AWS Network Manager Customer Gateway Association.](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-networkmanager-customergatewayassociation.html).

## Properties

| Property | Description | Field |
| --- | --- | --- |
| customer_gateway_arns | The Amazon Resource Name (ARN) of the customer gateway. | customer_gateway_arn |
| global_network_ids | The ID of the global network. | global_network_id |
| device_ids | The ID of the device.| device_id |
| link_ids | The ID of the link. | link_id |
| states | The association state. | state |

## Examples

### Ensure a customer gateway arn is available.

describe aws_network_manager_customer_gateway_association(global_network_id: 'GLOBAL_NETWORK_ID') do
its('customer_gateway_arns') { should include 'CustomerGatewayARN' }
end

### Ensure that the state is `active`.
describe aws_network_manager_customer_gateway_association(global_network_id: 'GLOBAL_NETWORK_ID') do
its('states') { should include 'AVAILABLE' }
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/).

The controls will pass if the `get` method returns at least one result.

### exist

Use `should` to test that the entity exists.

describe aws_network_manager_customer_gateway_association(global_network_id: 'GLOBAL_NETWORK_ID') do
it { should exist }
end

Use `should_not` to test the entity does not exist.

describe aws_network_manager_customer_gateway_association(global_network_id: "dummy") do
it { should_not exist }
end

## AWS Permissions

Your [Principal](https://docs.aws.amazon.com/IAM/latest/UserGuide/intro-structure.html#intro-structure-principal) will need the `NetworkManager:Client:GetCustomerGatewayAssociationsResponse` action with `Effect` set to `Allow`.
42 changes: 42 additions & 0 deletions libraries/aws_network_manager_customer_gateway_association.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

require 'aws_backend'

class AWSNetworkManagerCustomerGatewayAssociation < AwsResourceBase
name 'aws_network_manager_customer_gateway_association'
desc 'Gets the association information for customer gateways that are associated with devices and links in your global network.'

example "
describe aws_network_manager_customer_gateway_association(global_network_id: 'GlobalNetworkID', customer_gateway_arn: 'CustomerGatewayARN') do
it { should exist }
end
"

def initialize(opts = {})
opts = { global_network_id: opts } if opts.is_a?(String)
opts = { customer_gateway_arn: opts } if opts.is_a?(String)
super(opts)
validate_parameters(required: %i(global_network_id customer_gateway_arn))
raise ArgumentError, "#{@__resource_name__}: global_network_id must be provided" unless opts[:global_network_id] && !opts[:global_network_id].empty?
raise ArgumentError, "#{@__resource_name__}: customer_gateway_arn must be provided" unless opts[:customer_gateway_arn] && !opts[:customer_gateway_arn].empty?
@display_name = opts[:customer_gateway_arn]
catch_aws_errors do
resp = @aws.network_manager_client.get_customer_gateway_associations({ global_network_id: opts[:global_network_id], customer_gateway_arns: [opts[:customer_gateway_arn]] })
@res = resp.customer_gateway_associations[0].to_h
create_resource_methods(@res)
end
end

def customer_gateway_arn
return nil unless exists?
@res[:customer_gateway_arn]
end

def exists?
!@res.nil? && !@res.empty?
end

def to_s
"Customer Gateway ARN: #{@display_name}"
end
end
55 changes: 55 additions & 0 deletions libraries/aws_network_manager_customer_gateway_associations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

require 'aws_backend'

class AWSNetworkManagerCustomerGatewayAssociations < AwsResourceBase
name 'aws_network_manager_customer_gateway_associations'
desc 'Gets the association information for customer gateways that are associated with devices and links in your global network.'

example "
describe aws_network_manager_customer_gateway_associations(global_network_id: 'GlobalNetworkID') do
it { should exist }
end
"

attr_reader :table

FilterTable.create
.register_column(:customer_gateway_arns, field: :customer_gateway_arn)
.register_column(:global_network_ids, field: :global_network_id)
.register_column(:device_ids, field: :device_id)
.register_column(:link_ids, field: :link_id)
.register_column(:states, field: :state)
.register_column(:tags, field: :tags)
.install_filter_methods_on_resource(self, :table)

def initialize(opts = {})
super(opts)
validate_parameters(required: %i(global_network_id))
@query_params = {}
raise ArgumentError, "#{@__resource_name__}: global_network_id must be provided" unless opts[:global_network_id] && !opts[:global_network_id].empty?
@query_params[:global_network_id] = opts[:global_network_id]
@table = fetch_data
end

def fetch_data
rows = []
@query_params[:max_results] = 100
loop do
catch_aws_errors do
@api_response = @aws.network_manager_client.get_customer_gateway_associations(@query_params)
end
return rows if !@api_response || @api_response.empty?
@api_response.customer_gateway_associations.each do |resp|
rows += [{ customer_gateway_arn: resp.customer_gateway_arn,
global_network_id: resp.global_network_id,
device_id: resp.device_id,
link_id: resp.link_id,
state: resp.state }]
end
break unless @api_response.next_token
@query_params[:next_token] = @api_response.next_token
end
rows
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
skip_control 'aws-network-manager-customer-gateway-association-1.0' do
impact 1.0
title 'Test the properties of the aws network manager customer gateway association.'

describe aws_network_manager_customer_gateway_association(global_network_id: "GlobalNetworkID", customer_gateway_arn: 'CustomerGatewayARN') do
it { should exist }
end

describe aws_network_manager_customer_gateway_association(global_network_id: "GlobalNetworkID", customer_gateway_arn: 'CustomerGatewayARN') do
its('customer_gateway_arn') { should eq 'CustomerGatewayARN' }
its('global_network_id') { should eq 'GlobalNetworkID' }
its('device_id') { should eq 'DeviceID' }
its('link_id') { should eq 'LinkID' }
its('state') { should eq 'State' }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
skip_control 'aws-network-manager-customer-gateway-associations-1.0' do
impact 1.0
title 'Test the properties of the aws network manager customer gateway associations.'

describe aws_network_manager_customer_gateway_associations(global_network_id: "GlobalNetworkID") do
it { should exist }
end

describe aws_network_manager_customer_gateway_associations(global_network_id: "GlobalNetworkID") do
its('customer_gateway_arns') { should include 'CustomerGatewayARN' }
its('global_network_ids') { should include 'GlobalNetworkID' }
its('device_ids') { should include 'DeviceID' }
its('link_ids') { should include 'LinkID' }
its('states') { should include 'State' }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require 'helper'
require 'aws_network_manager_customer_gateway_association'
require 'aws-sdk-core'

class AWSNetworkManagerCustomerGatewayAssociationConstructorTest < Minitest::Test

def test_empty_params_not_ok
assert_raises(ArgumentError) { AWSNetworkManagerCustomerGatewayAssociation.new(global_network_id: '', customer_gateway_arn: '', client_args: { stub_responses: true }) }
end

def test_empty_param_arg_not_ok
assert_raises(ArgumentError) { AWSNetworkManagerCustomerGatewayAssociation.new(global_network_id: '', customer_gateway_arn: '', client_args: { stub_responses: true }) }
end

def test_rejects_unrecognized_params
assert_raises(ArgumentError) { AWSNetworkManagerCustomerGatewayAssociation.new(unexpected: 9) }
end
end

class AWSNetworkManagerCustomerGatewayAssociationSuccessPathTest < Minitest::Test

def setup
data = {}
data[:method] = :get_customer_gateway_associations
mock_data = {}
mock_data[:customer_gateway_arn] = 'test1'
mock_data[:global_network_id] = 'test1'
mock_data[:device_id] = 'test1'
mock_data[:link_id] = 'test1'
mock_data[:state] = 'test1'
data[:data] = { customer_gateway_associations: [mock_data] }
data[:client] = Aws::NetworkManager::Client
@resp = AWSNetworkManagerCustomerGatewayAssociation.new(global_network_id: 'test1', customer_gateway_arn: 'test1', client_args: { stub_responses: true }, stub_data: [data])
end

def test_customer_gateway_associations_configs_exists
assert @resp.exists?
end

def test_customer_gateway_arn
assert_equal(@resp.customer_gateway_arn, 'test1')
end

def test_global_network_id
assert_equal(@resp.global_network_id, 'test1')
end

def test_device_id
assert_equal(@resp.device_id, 'test1')
end

def test_link_id
assert_equal(@resp.link_id, 'test1')
end

def test_state
assert_equal(@resp.state, 'test1')
end
end
Loading