For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/terraform-aws-efs-without-kms.md. A documentation index is available at /llms.txt.
This product is not supported for your selected Datadog site. ().

Metadata

Id: terraform-aws-efs-without-kms

Provider: AWS

Platform: Terraform

Severity: Low

Category: Encryption

Learn More

Description

This check ensures that Amazon Elastic File System (EFS) resources are configured with encryption enabled using a customer-managed KMS key specified via the kms_key_id attribute, rather than defaulting to AWS-managed keys. If only encrypted = true is set without specifying a kms_key_id, sensitive data stored in EFS will use default AWS-managed encryption keys, reducing control over key rotation and access management. Failure to use a customer-managed key increases the risk of unauthorized data access and may not meet stringent compliance requirements for sensitive workloads.

Compliant Code Examples

resource "aws_efs_file_system" "negative1" {
  creation_token = "my-product"
  encrypted = true
  kms_key_id = "1234abcd-12ab-34cd-56ef-1234567890ab"

  tags = {
    Name = "MyProduct"
  }
}
# kms_key_id references a CMK created in the same plan (aws_kms_key.example.arn),
# so it's unresolved pre-apply and absent from planned_values.values in
# negative2.json (a real `terraform plan` for this exact configuration). The
# rule confirms via _dd_tfplan_meta.configuration_expressions that
# kms_key_id was actually configured (just unresolved), so it correctly
# stays silent instead of treating this as an unencrypted file system.
resource "aws_kms_key" "example" {
  description = "CMK for EFS file system encryption"
}

resource "aws_efs_file_system" "cmk_reference" {
  creation_token = "my-product"
  encrypted      = true
  kms_key_id     = aws_kms_key.example.arn

  tags = {
    Name = "MyProduct"
  }
}

Non-Compliant Code Examples

resource "aws_efs_file_system" "positive1" {
  creation_token = "my-product"
  encrypted = true

  tags = {
    Name = "MyProduct"
  }
}