---
title: ElastiCache nodes not created across multi AZ
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Infrastructure as Code (IaC)
  Security > IaC Security Rules > ElastiCache nodes not created across multi AZ
---

# ElastiCache nodes not created across multi AZ

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

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

{% /callout %}

## Metadata{% #metadata %}

**Id:** `terraform-aws-elasticache-nodes-not-created-across-multi-az` 

**Provider:** AWS

**Platform:** Terraform

**Severity:** Medium

**Category:** Availability

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

- [Provider Reference](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_cluster)

### Description{% #description %}

When configuring AWS ElastiCache clusters with multiple nodes, it is important to distribute nodes across multiple Availability Zones (AZs) by setting the `az_mode` attribute to `"cross-az"`. Failing to do so—such as by omitting the `az_mode` attribute or explicitly setting it to `"single-az"`—means all nodes run in a single AZ, increasing the risk of service disruption if that AZ experiences an outage. For example, a secure Terraform configuration explicitly sets the following:

```
resource "aws_elasticache_cluster" "example" {
  cluster_id    = "cluster-example"
  engine        = "memcached"
  num_cache_nodes = 3
  az_mode       = "cross-az"
}
```

Distributing cache nodes across multiple AZs increases fault tolerance and availability for ElastiCache clusters.

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

```terraform
resource "aws_elasticache_cluster" "negative1" {
  cluster_id           = "cluster-example"
  engine = "memcached"

  num_cache_nodes = 3

  az_mode = "cross-az"
}
```

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

```terraform
resource "aws_elasticache_cluster" "positive1" {
  cluster_id = "cluster-example"
  engine = "memcached"
  num_cache_nodes = 3
}

resource "aws_elasticache_cluster" "positive2" {
  cluster_id = "cluster-example"
  engine = "memcached"
  num_cache_nodes = 3

  az_mode = "single-az"
}
```
