Skip to content

feat(terraform): add CKV_AWS_394 for unconstrained aws_availability_zones data source - #7658

Open
madhavvishnubhatta wants to merge 1 commit into
bridgecrewio:mainfrom
madhavvishnubhatta:feat/ckv-aws-394-availability-zones
Open

feat(terraform): add CKV_AWS_394 for unconstrained aws_availability_zones data source#7658
madhavvishnubhatta wants to merge 1 commit into
bridgecrewio:mainfrom
madhavvishnubhatta:feat/ckv-aws-394-availability-zones

Conversation

@madhavvishnubhatta

Copy link
Copy Markdown

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Description

Adds a new check, CKV_AWS_394, that flags a Terraform aws_availability_zones data source when it does not constrain which zones are returned. An unconstrained data source (e.g. data "aws_availability_zones" "available" {}) returns every AZ in the region, so configuration that relied on a fixed AZ count silently changes behavior when AWS adds a new AZ to the region — with no code change on the user's side.

This is the same class of risk as the existing WhoAMI check (CKV_AWS_386), which flags an under-constrained aws_ami data source, so there is precedent for scanning data blocks this way. The check targets the root cause (the unconstrained data source) rather than downstream count/for_each usage.

Fixes #7657

New/Edited policies

Description

The check fails an aws_availability_zones data block unless it pins zone
identity. Identity-pinning arguments are:

  • exclude_names
  • exclude_zone_ids
  • a filter on zone-name or zone-id

Arguments that constrain zone attributes rather than identity do NOT prevent
a newly-added zone from appearing and therefore do NOT satisfy the check on
their own: state, all_availability_zones, a filter on opt-in-status,
and grouping filters such as group-name / group-long-name (a new AZ joins
the existing group and still appears).

Docs:

Fix

Constrain the data source so its result set is deterministic, e.g.:

data "aws_availability_zones" "available" {
  exclude_names = ["us-east-1e"]
}

or filter on zone identity:

data "aws_availability_zones" "available" {
  filter {
    name   = "zone-name"
    values = ["us-east-1a", "us-east-1b", "us-east-1c"]
  }
}

Users with a verified downstream mitigation (e.g. a length-guarded
count/for_each) can suppress per-block:

# checkov:skip=CKV_AWS_394: <reason>

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my feature, policy, or fix is effective and works
  • New and existing tests pass locally with my changes

…ones data source

Add a data-block check that fails an aws_availability_zones data source
unless it pins zone identity via exclude_names, exclude_zone_ids, or an
identity-based filter (zone-name / zone-id). Attribute-only constraints
such as state or opt-in-status, and grouping filters like group-name, do
not prevent a newly-added AZ from appearing and therefore fail.

This mirrors the WhoAMI check (CKV_AWS_386), which flags an
under-constrained aws_ami data source, and targets the root cause rather
than downstream count/for_each usage. Users with a verified downstream
mitigation can suppress per-block via
@madhavvishnubhatta
madhavvishnubhatta marked this pull request as draft August 24, 2026 15:55
@madhavvishnubhatta
madhavvishnubhatta marked this pull request as ready for review August 24, 2026 16:01
@madhavvishnubhatta
madhavvishnubhatta marked this pull request as draft August 24, 2026 16:02
@madhavvishnubhatta
madhavvishnubhatta marked this pull request as ready for review August 25, 2026 09:18
@Saarett

Saarett commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Hello @madhavvishnubhatta , thank you for the contribution. Please pull latest dev and push it so we can re-run the tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add check: flag aws_availability_zones data source that does not pin zone identity

2 participants