---
title: ElastiCache without VPC
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Infrastructure as Code (IaC)
  Security > IaC Security Rules > ElastiCache without VPC
---

# ElastiCache without VPC

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ().
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**Id:** `5527dcfc-94f9-4bf6-b7d4-1b78850cf41f`

**Cloud Provider:** AWS

**Platform:** Ansible

**Severity:** Low

**Category:** Networking and Firewall

#### Learn More{% #learn-more %}

- [Provider Reference](https://docs.ansible.com/ansible/latest/collections/community/aws/elasticache_module.html#parameter-cache_subnet_group)

### Description{% #description %}

ElastiCache clusters must be launched in a VPC to provide network isolation and reduce the risk of unauthorized access to cached data or lateral movement within your environment.

In Ansible playbooks, tasks using the `community.aws.elasticache` or `elasticache` modules must set the `cache_subnet_group` property to the name of an existing ElastiCache subnet group. A task where `cache_subnet_group` is undefined or null is flagged because omission typically results in resources being created outside a VPC or without the intended subnet isolation.

Secure Ansible example:

```yaml
- name: Create ElastiCache cluster in VPC
  community.aws.elasticache:
    name: my-cache
    engine: redis
    cache_subnet_group: my-cache-subnet-group
```

## Compliant Code Examples{% #compliant-code-examples %}

```yaml
- name: Basic example2
  community.aws.elasticache:
    name: "test-please-delete"
    state: present
    engine: memcached
    cache_engine_version: 1.4.14
    node_type: cache.m1.small
    num_nodes: 1
    cache_port: 11211
    cache_subnet_group: default
    zone: us-east-1d
```

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```yaml
- name: Basic example
  community.aws.elasticache:
    name: "test-please-delete"
    state: present
    engine: memcached
    cache_engine_version: 1.4.14
    node_type: cache.m1.small
    num_nodes: 1
    cache_port: 11211
    cache_security_groups:
      - default
    zone: us-east-1d
```
