| paths |
|
|---|
As an AI Agent operating in this repository, you MUST strictly adhere to the following Terraform coding standards. Do not deviate from these rules under any circumstances.
- Attribute Order: You MUST declare resource attributes in this exact top-down order to ensure consistency:
countdepends_onfor_eachsourceversiontriggers- All other attributes
- Explicit Dependencies: You MUST always explicitly state
depends_onblocks for resources and modules, even if Terraform can infer the dependency graph natively. - Ternary Operations: You MUST wrap all ternary operations in parentheses.
- Correct:
attribute = (var.is_enabled ? true : false) - Incorrect:
attribute = var.is_enabled ? true : false
- Correct:
- Embedded Scripts: Avoid embedded scripts if possible (use
file()ortemplatefile()). If embedding is required, you MUST use heredoc syntax (<<-EOT).
- Locals Mapping: ALL variables (
var.*) MUST be immediately mapped to alocals {}block in the root of the module (usuallymain.tf). - Resource Referencing: Resources MUST ONLY reference
local.*. You MUST NEVER referencevar.*directly inside aresourceormoduleblock.
- Count as a Feature Flag: You MUST ONLY use
countas a boolean feature flag to turn a resource on or off (0or1).- Correct:
count = (local.create_resource ? 1 : 0)
- Correct:
- Never Iterate with Count: You MUST NEVER use
countto iterate over lists and create multiple instances of a resource. This causes cascading dependency destructions when list orders change. Usefor_eachinstead.
Understand the distinction between XMod (External), LMod (Local), and IMod (Implementation) modules.
- No Nesting Local Modules: You MUST NEVER nest an LMod (Local Module) inside another LMod. Treat LMods like function calls orchestrated by the Implementation Module (IMod).
- Module Tiers (Max 3 Levels):
- Core Modules: Call only resources. NEVER call other modules.
- Primary Modules: Call only Core Modules (exceptions allowed for
local_file,random, orterraform_data). NEVER call raw API resources. - Secondary Modules: Call only Primary Modules. Represents large systems.
- Highly Opinionated Selectors: Favor providing pre-defined configurations in
locals(e.g.,prod-node-config) rather than exposing raw, granular resource parameters via variables.
- Script Paths: When using
remote-execor connection strings, you MUST ALWAYS explicitly set thescript_pathattribute to avoid SELinux execution blocks in/tmp. - SSH Agent Only: Modules MUST NOT generate or accept private SSH keys or passwords as variables unless strictly necessary for a specific cloud-init sequence. Assume the user relies on a local SSH agent.
When writing tests, adhere to these conceptual boundaries:
- Unit Test: Tests a single Local Module (LMod) in isolation.
- Integration Test: Tests the interaction between two or more LMods.
- E2E Test: Tests the entire Implementation Module (IMod) with real provider interactions.