diff --git a/plugins/modules/elasticache_subnet_group.py b/plugins/modules/elasticache_subnet_group.py index 5e813b64ad1..eda678205d0 100644 --- a/plugins/modules/elasticache_subnet_group.py +++ b/plugins/modules/elasticache_subnet_group.py @@ -34,6 +34,7 @@ subnets: description: - List of subnet IDs that make up the ElastiCache subnet group. + - At least one subnet must be provided when creating an ElastiCache subnet group. type: list elements: str author: @@ -140,14 +141,15 @@ def get_subnet_group(name): def create_subnet_group(name, description, subnets): + if not subnets: + module.fail_json(msg='At least one subnet must be provided when creating a subnet group') + if module.check_mode: return True try: if not description: description = name - if not subnets: - subnets = [] client.create_cache_subnet_group( aws_retry=True, CacheSubnetGroupName=name, diff --git a/tests/integration/targets/elasticache_subnet_group/tasks/main.yml b/tests/integration/targets/elasticache_subnet_group/tasks/main.yml index cc82948a1ce..ca94dc11f2c 100644 --- a/tests/integration/targets/elasticache_subnet_group/tasks/main.yml +++ b/tests/integration/targets/elasticache_subnet_group/tasks/main.yml @@ -13,6 +13,48 @@ security_token: '{{ security_token | default(omit) }}' region: '{{ aws_region }}' block: + + # ============================================================ + + - name: Create Subnet Group with no subnets - check_mode + elasticache_subnet_group: + state: present + name: '{{ group_name }}' + check_mode: True + register: create_group + ignore_errors: True + + - name: Check result - Create Subnet Group with no subnets - check_mode + assert: + that: + - create_group is failed + # Check we caught the issue before trying to create + - '"CreateCacheSubnetGroup" not in create_group.resource_actions' + # Check that we don't refer to the boto3 parameter + - '"SubnetIds" not in create_group.msg' + # Loosely check the message + - '"subnet" in create_group.msg' + - '"At least" in create_group.msg' + + - name: Create Subnet Group with no subnets + elasticache_subnet_group: + state: present + name: '{{ group_name }}' + register: create_group + ignore_errors: True + + - name: Check result - Create Subnet Group with no subnets + assert: + that: + - create_group is failed + # Check we caught the issue before trying to create + - '"CreateCacheSubnetGroup" not in create_group.resource_actions' + # Check that we don't refer to the boto3 parameter + - '"SubnetIds" not in create_group.msg' + # Loosely check the message + - '"subnet" in create_group.msg' + - '"At least" in create_group.msg' + # ============================================================ # Setup infra needed for tests - name: create a VPC @@ -55,6 +97,7 @@ subnet_id_b: '{{ vpc_subnet_create.results[1].subnet.id }}' subnet_id_c: '{{ vpc_subnet_create.results[2].subnet.id }}' subnet_id_d: '{{ vpc_subnet_create.results[3].subnet.id }}' + # ============================================================ - name: Create Subnet Group - check_mode