Skip to content

Commit

Permalink
Add additional tests and documentation around new return values
Browse files Browse the repository at this point in the history
  • Loading branch information
tremble committed Sep 23, 2021
1 parent dc4cd6e commit aac8190
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 5 deletions.
26 changes: 21 additions & 5 deletions plugins/modules/redshift_subnet_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,33 @@

RETURN = r'''
cluster_subnet_group:
description: dictionary containing Redshift subnet group information
description: A dictionary containing information about the Redshift subnet group.
returned: success
type: dict
contains:
name:
description: name of the Redshift subnet group
returned: success
description: Name of the Redshift subnet group.
returned: when the cache subnet group exists
type: str
sample: "redshift_subnet_group_name"
vpc_id:
description: Id of the VPC where the subnet is located
returned: success
description: Id of the VPC where the subnet is located.
returned: when the cache subnet group exists
type: str
sample: "vpc-aabb1122"
description:
description: The description of the cache subnet group.
returned: when the cache subnet group exists
type: str
sample: Redshift subnet
subnet_ids:
description: The IDs of the subnets beloging to the Redshift subnet group.
returned: when the cache subnet group exists
type: list
elements: str
sample:
- subnet-aaaaaaaa
- subnet-bbbbbbbb
'''

try:
Expand All @@ -90,6 +103,7 @@
from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict


def get_subnet_group(name):
Expand All @@ -112,8 +126,10 @@ def get_subnet_group(name):
cluster_subnet_groups=camel_dict_to_snake_dict(groups),
)

tags = boto3_tag_list_to_ansible_dict(groups[0]['Tags'])
subnet_group = camel_dict_to_snake_dict(groups[0])

subnet_group['tags'] = tags
subnet_group['name'] = subnet_group['cluster_subnet_group_name']

subnet_ids = list(s['subnet_identifier'] for s in subnet_group['subnets'])
Expand Down
110 changes: 110 additions & 0 deletions tests/integration/targets/redshift_subnet_group/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@
- '"vpc_id" in create_group.group'
- create_group.group.name == group_name
- create_group.group.vpc_id == vpc_id
- '"cluster_subnet_group" in create_group'
- '"description" in create_group.cluster_subnet_group'
- '"subnet_ids" in create_group.cluster_subnet_group'
- '"vpc_id" in create_group.cluster_subnet_group'
- create_group.cluster_subnet_group.name == group_name
- create_group.cluster_subnet_group.description == description_default
- subnet_id_a in create_group.cluster_subnet_group.subnet_ids
- subnet_id_b in create_group.cluster_subnet_group.subnet_ids
- subnet_id_c not in create_group.cluster_subnet_group.subnet_ids
- subnet_id_d not in create_group.cluster_subnet_group.subnet_ids
- create_group.cluster_subnet_group.vpc_id == vpc_id

- name: Create Subnet Group - idempotency
redshift_subnet_group:
Expand All @@ -122,6 +133,17 @@
- '"vpc_id" in create_group.group'
- create_group.group.name == group_name
- create_group.group.vpc_id == vpc_id
- '"cluster_subnet_group" in create_group'
- '"description" in create_group.cluster_subnet_group'
- '"subnet_ids" in create_group.cluster_subnet_group'
- '"vpc_id" in create_group.cluster_subnet_group'
- create_group.cluster_subnet_group.name == group_name
- create_group.cluster_subnet_group.description == description_default
- subnet_id_a in create_group.cluster_subnet_group.subnet_ids
- subnet_id_b in create_group.cluster_subnet_group.subnet_ids
- subnet_id_c not in create_group.cluster_subnet_group.subnet_ids
- subnet_id_d not in create_group.cluster_subnet_group.subnet_ids
- create_group.cluster_subnet_group.vpc_id == vpc_id

# ============================================================

Expand All @@ -146,6 +168,17 @@
- '"vpc_id" in update_description.group'
- update_description.group.name == group_name
- update_description.group.vpc_id == vpc_id
- '"cluster_subnet_group" in update_description'
- '"description" in update_description.cluster_subnet_group'
- '"subnet_ids" in update_description.cluster_subnet_group'
- '"vpc_id" in update_description.cluster_subnet_group'
- update_description.cluster_subnet_group.name == group_name
- update_description.cluster_subnet_group.description == description_updated
- subnet_id_a in update_description.cluster_subnet_group.subnet_ids
- subnet_id_b in update_description.cluster_subnet_group.subnet_ids
- subnet_id_c not in update_description.cluster_subnet_group.subnet_ids
- subnet_id_d not in update_description.cluster_subnet_group.subnet_ids
- update_description.cluster_subnet_group.vpc_id == vpc_id

- name: Update Subnet Group Description - idempotency
redshift_subnet_group:
Expand All @@ -168,6 +201,17 @@
- '"vpc_id" in update_description.group'
- update_description.group.name == group_name
- update_description.group.vpc_id == vpc_id
- '"cluster_subnet_group" in update_description'
- '"description" in update_description.cluster_subnet_group'
- '"subnet_ids" in update_description.cluster_subnet_group'
- '"vpc_id" in update_description.cluster_subnet_group'
- update_description.cluster_subnet_group.name == group_name
- update_description.cluster_subnet_group.description == description_updated
- subnet_id_a in update_description.cluster_subnet_group.subnet_ids
- subnet_id_b in update_description.cluster_subnet_group.subnet_ids
- subnet_id_c not in update_description.cluster_subnet_group.subnet_ids
- subnet_id_d not in update_description.cluster_subnet_group.subnet_ids
- update_description.cluster_subnet_group.vpc_id == vpc_id

# ============================================================

Expand All @@ -192,6 +236,17 @@
- '"vpc_id" in update_subnets.group'
- update_subnets.group.name == group_name
- update_subnets.group.vpc_id == vpc_id
- '"cluster_subnet_group" in update_subnets'
- '"description" in update_subnets.cluster_subnet_group'
- '"subnet_ids" in update_subnets.cluster_subnet_group'
- '"vpc_id" in update_subnets.cluster_subnet_group'
- update_subnets.cluster_subnet_group.name == group_name
- update_subnets.cluster_subnet_group.description == description_updated
- subnet_id_a not in update_subnets.cluster_subnet_group.subnet_ids
- subnet_id_b not in update_subnets.cluster_subnet_group.subnet_ids
- subnet_id_c in update_subnets.cluster_subnet_group.subnet_ids
- subnet_id_d in update_subnets.cluster_subnet_group.subnet_ids
- update_subnets.cluster_subnet_group.vpc_id == vpc_id

- name: Update Subnet Group subnets - idempotency
redshift_subnet_group:
Expand All @@ -214,6 +269,17 @@
- '"vpc_id" in update_subnets.group'
- update_subnets.group.name == group_name
- update_subnets.group.vpc_id == vpc_id
- '"cluster_subnet_group" in update_subnets'
- '"description" in update_subnets.cluster_subnet_group'
- '"subnet_ids" in update_subnets.cluster_subnet_group'
- '"vpc_id" in update_subnets.cluster_subnet_group'
- update_subnets.cluster_subnet_group.name == group_name
- update_subnets.cluster_subnet_group.description == description_updated
- subnet_id_a not in update_subnets.cluster_subnet_group.subnet_ids
- subnet_id_b not in update_subnets.cluster_subnet_group.subnet_ids
- subnet_id_c in update_subnets.cluster_subnet_group.subnet_ids
- subnet_id_d in update_subnets.cluster_subnet_group.subnet_ids
- update_subnets.cluster_subnet_group.vpc_id == vpc_id

# ============================================================

Expand Down Expand Up @@ -259,6 +325,17 @@
- '"vpc_id" in create_group.group'
- create_group.group.name == group_name
- create_group.group.vpc_id == vpc_id
- '"cluster_subnet_group" in create_group'
- '"description" in create_group.cluster_subnet_group'
- '"subnet_ids" in create_group.cluster_subnet_group'
- '"vpc_id" in create_group.cluster_subnet_group'
- create_group.cluster_subnet_group.name == group_name
- create_group.cluster_subnet_group.description == group_name
- subnet_id_a in create_group.cluster_subnet_group.subnet_ids
- subnet_id_b not in create_group.cluster_subnet_group.subnet_ids
- subnet_id_c not in create_group.cluster_subnet_group.subnet_ids
- subnet_id_d not in create_group.cluster_subnet_group.subnet_ids
- create_group.cluster_subnet_group.vpc_id == vpc_id

- name: Create minimal Subnet Group - idempotency
redshift_subnet_group:
Expand All @@ -278,6 +355,17 @@
- '"vpc_id" in create_group.group'
- create_group.group.name == group_name
- create_group.group.vpc_id == vpc_id
- '"cluster_subnet_group" in create_group'
- '"description" in create_group.cluster_subnet_group'
- '"subnet_ids" in create_group.cluster_subnet_group'
- '"vpc_id" in create_group.cluster_subnet_group'
- create_group.cluster_subnet_group.name == group_name
- create_group.cluster_subnet_group.description == group_name
- subnet_id_a in create_group.cluster_subnet_group.subnet_ids
- subnet_id_b not in create_group.cluster_subnet_group.subnet_ids
- subnet_id_c not in create_group.cluster_subnet_group.subnet_ids
- subnet_id_d not in create_group.cluster_subnet_group.subnet_ids
- create_group.cluster_subnet_group.vpc_id == vpc_id

# ============================================================

Expand All @@ -301,6 +389,17 @@
- '"vpc_id" in update_complex.group'
- update_complex.group.name == group_name
- update_complex.group.vpc_id == vpc_id
- '"cluster_subnet_group" in update_complex'
- '"description" in update_complex.cluster_subnet_group'
- '"subnet_ids" in update_complex.cluster_subnet_group'
- '"vpc_id" in update_complex.cluster_subnet_group'
- update_complex.cluster_subnet_group.name == group_name
- update_complex.cluster_subnet_group.description == description_updated
- subnet_id_a in update_complex.cluster_subnet_group.subnet_ids
- subnet_id_b in update_complex.cluster_subnet_group.subnet_ids
- subnet_id_c not in update_complex.cluster_subnet_group.subnet_ids
- subnet_id_d not in update_complex.cluster_subnet_group.subnet_ids
- update_complex.cluster_subnet_group.vpc_id == vpc_id

- name: Full Update Subnet Group - idempotency
redshift_subnet_group:
Expand All @@ -322,6 +421,17 @@
- '"vpc_id" in update_complex.group'
- update_complex.group.name == group_name
- update_complex.group.vpc_id == vpc_id
- '"cluster_subnet_group" in update_complex'
- '"description" in update_complex.cluster_subnet_group'
- '"subnet_ids" in update_complex.cluster_subnet_group'
- '"vpc_id" in update_complex.cluster_subnet_group'
- update_complex.cluster_subnet_group.name == group_name
- update_complex.cluster_subnet_group.description == description_updated
- subnet_id_a in update_complex.cluster_subnet_group.subnet_ids
- subnet_id_b in update_complex.cluster_subnet_group.subnet_ids
- subnet_id_c not in update_complex.cluster_subnet_group.subnet_ids
- subnet_id_d not in update_complex.cluster_subnet_group.subnet_ids
- update_complex.cluster_subnet_group.vpc_id == vpc_id

# ============================================================

Expand Down

0 comments on commit aac8190

Please sign in to comment.