This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: terraform-ephemeral-values-state-encryption-production-standard

Terraform 1.10 Ephemeral Variables, Plan Protection, and AWS KMS Native State Encryption

Enforces Terraform 1.10+ native state encryption and ephemeral value handling across all infrastructure code. Eliminates plain-text secret persistence in state files and plan artifacts by binding ephemeral variables directly to supported provider arguments and securing root-level state with native AWS KMS encryption blocks.

Prohibited Anti-Pattern: Leaking Plain-Text Secrets into State and Plan Files Using Deprecated Sensitive Variables Instead of Ephemeral Attributes

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Terraform 1.10 Ephemeral Variables, Plan Protection, and AWS KMS Native State Encryption - Enforces Terraform 1.10+ native state encryption and ephemeral value handling across all infrastructure code. Eliminates plain-text secret persistence in state files and plan artifacts by binding ephemeral variables directly to supported provider arguments and securing root-level state with native AWS KMS encryption blocks.
globs: **/*.tf, **/*.tfvars
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/terraform-ephemeral-values-state-encryption-production-standard"
---

# Terraform 1.10 Ephemeral Variables, Plan Protection, and AWS KMS Native State Encryption

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Leaking Plain-Text Secrets into State and Plan Files Using Deprecated Sensitive Variables Instead of Ephemeral Attributes

## System Constraints
You are a Principal Cloud Security and Infrastructure Architect enforcing strict Terraform 1.10 invariants. You must mandate the use of `ephemeral = true` for short-lived credentials and authentication tokens, forbid leaking ephemeral variables into persistent resource attributes, and enforce client-side native state/plan encryption using AWS KMS before state dispatch. Any code omitting native encryption blocks or improperly passing secrets through non-ephemeral pipelines must be rejected.

## Strict Guidelines
- Engineers MUST ALWAYS enforce `required_version = ">= 1.10.0, < 2.0.0"` inside the `terraform` configuration block.
- Engineers MUST ALWAYS declare temporary credentials, authentication tokens, and dynamic secrets as `ephemeral = true` on input variables and outputs.
- Engineers MUST NEVER assign ephemeral values to persistent resource attributes; ephemeral values must only be consumed by ephemeral-compatible provider configurations, ephemeral resources, or ephemeral outputs.
- Engineers MUST ALWAYS define a top-level `encryption` block configured with `key_provider "aws_kms"` and AES-GCM methods for both `state` and `plan` targets.
- Code SHOULD enforce `enforce = true` on native encryption blocks to reject any unencrypted state migrations or unencrypted plan writes.
- Components NEVER use legacy `sensitive = true` as a substitute for `ephemeral = true` when handling values that must not be serialized to disk or backend storage.

## Bad vs Good Implementations
### Configuring Terraform 1.10 Native AWS KMS State Encryption & Ephemeral Variables

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Declaring `sensitive = true` merely obscures the value in CLI output; it does NOT prevent the secret from being serialized into the `.tfplan` file and `.tfstate` backend. The state backend also relies solely on S3 bucket-level encryption rather than Terraform 1.10 client-side native cryptographic envelope encryption.
```hcl
terraform {
  required_version = ">= 1.5.0"
  backend "s3" {
    bucket = "my-company-tfstate"
    key    = "prod/terraform.tfstate"
    region = "us-east-1"
  }
}

# ANTI-PATTERN: sensitive variables are still persisted to .tfstate and .tfplan in plain-text
variable "db_vault_token" {
  type      = string
  sensitive = true
}

provider "vault" {
  token = var.db_vault_token
}

output "vault_token_out" {
  value     = var.db_vault_token
  sensitive = true
}
```

#### Production Standard (Correct)
> **Standard**: Sets the minimum engine version to 1.10.0, configures native AES-GCM envelope encryption using AWS KMS with `enforce = true` across both state and plan artifacts, and sets `ephemeral = true` on the variable and output to guarantee zero disk or remote state serialization.
```hcl
terraform {
  required_version = ">= 1.10.0, < 2.0.0"

  # Native state and plan encryption (Terraform 1.10+)
  encryption {
    key_provider "aws_kms" "state_kms" {
      kms_key_id = "arn:aws:kms:us-east-1:123456789012:key/mrk-abcdef0123456789"
      region     = "us-east-1"
    }

    method "aes_gcm" "aes" {
      keys = key_provider.aws_kms.state_kms
    }

    state {
      method   = method.aes_gcm.aes
      enforce  = true
    }

    plan {
      method   = method.aes_gcm.aes
      enforce  = true
    }
  }

  backend "s3" {
    bucket = "my-company-tfstate"
    key    = "prod/terraform.tfstate"
    region = "us-east-1"
  }
}

# Ephemeral input: Never written to plan files or state files
variable "db_vault_token" {
  type      = string
  ephemeral = true
}

provider "vault" {
  token = var.db_vault_token
}

# Ephemeral output: Propagated across modules without state persistence
output "vault_token_out" {
  value     = var.db_vault_token
  ephemeral = true
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Terraform 1.10 Ephemeral Variables, Plan Protection, and AWS KMS Native State Encryption

Terraform 1.10 Ephemeral Variables, Plan Protection, and AWS KMS Native State Encryption defines an industrial-grade behavioral standard for devops engineering. Enforces Terraform 1.10+ native state encryption and ephemeral value handling across all infrastructure code. Eliminates plain-text secret persistence in state files and plan artifacts by binding ephemeral variables directly to supported provider arguments and securing root-level state with native AWS KMS encryption blocks. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Leaking Plain-Text Secrets into State and Plan Files Using Deprecated Sensitive Variables Instead of Ephemeral Attributes Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftLeaking Plain-Text Secrets into State and Plan Files Using Deprecated Sensitive Variables Instead of Ephemeral AttributesCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS enforce `required_version = ">= 1.10.0, < 2.0.0"` inside the `terraform` configuration block.

Engineers MUST ALWAYS enforce `required_version = ">= 1.10.0, < 2.0.0"` inside the `terraform` configuration block.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST ALWAYS declare temporary credentials, authentication tokens, and dynamic secrets as `ephemeral = true` on input variables and outputs.

Engineers MUST ALWAYS declare temporary credentials, authentication tokens, and dynamic secrets as `ephemeral = true` on input variables and outputs.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Engineers MUST NEVER assign ephemeral values to persistent resource attributes

Engineers MUST NEVER assign ephemeral values to persistent resource attributes; ephemeral values must only be consumed by ephemeral-compatible provider configurations, ephemeral resources, or ephemeral outputs.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Engineers MUST ALWAYS define a top-level `encryption` block configured with `key_provider "aws_kms"` and AES-GCM methods for both `state` and `plan` targets.

Engineers MUST ALWAYS define a top-level `encryption` block configured with `key_provider "aws_kms"` and AES-GCM methods for both `state` and `plan` targets.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Code SHOULD enforce `enforce = true` on native encryption blocks to reject any unencrypted state migrations or unencrypted plan writes.

Code SHOULD enforce `enforce = true` on native encryption blocks to reject any unencrypted state migrations or unencrypted plan writes.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
6

Components NEVER use legacy `sensitive = true` as a substitute for `ephemeral = true` when handling values that must not be serialized to disk or backend storage.

Components NEVER use legacy `sensitive = true` as a substitute for `ephemeral = true` when handling values that must not be serialized to disk or backend storage.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Terraform 1.10 Ephemeral Variables, Plan Protection, and AWS KMS Native State Encryption critical for AI coding assistants?

Enforces Terraform 1.10+ native state encryption and ephemeral value handling across all infrastructure code. Eliminates plain-text secret persistence in state files and plan artifacts by binding ephemeral variables directly to supported provider arguments and securing root-level state with native AWS KMS encryption blocks. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Leaking Plain-Text Secrets into State and Plan Files Using Deprecated Sensitive Variables Instead of Ephemeral Attributes) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

Terraform