Skip to content

Atmos attempts to template within TF modules resulting in error #2145

Closed

Description

Describe the Bug

I noticed that when using Atmos on some Terraform modules (vendored or self-written), they would immediately error out:

Error: template: templates-all-atmos-sections:156: function "project" not defined

After some digging, it turns out this happens when the module contains anything that looks like a Go template. i.e. some manifest or variable/output description containing double curly braces. Some Terraform vendors (GCP especially) just do this for specifying the format of values.

output "service_id" {
  value       = google_cloud_run_v2_service.main.id
  description = "Unique Identifier for the created service with format projects/{{project}}/locations/{{location}}/services/{{name}}"
}

Expected Behavior

Atmos Go templating should happen in the abstraction above Terraform modules. Configure Atmos to ignore double curly brace sequences that may occur in Terraform modules.

Steps to Reproduce

  • In the Atmos repo, go to examples/quick-start-simple
  • Modify components/terraform/weather/*.tf, such as adding a description containing double curly braces.
output "url" {
  value = local.url
  description = "URL in the format https://{{domain}}/{{foobar}}"
}
  • Run atmos terraform plan station -s dev
  • Receive vague error occurs about undefined templating function
Error: template: templates-all-atmos-sections:156: function "domain" not defined

Screenshots

No response

Environment

Discovered on:

  • Atmos 1.204.0
  • darwin/arm64

Additional Context

No response

Activity

  1. added
    bug
    on Mar 5, 2026
  2. thejrose1984 commented on May 29, 2026

    @thejrose1984
    Contributor

    Confirmed reproducible on main (commit at HEAD of main)

    Reproduced with the user's exact command after adding the {{ }} description to an output in examples/quick-start-simple/components/terraform/weather/outputs.tf:

    $ atmos terraform plan station -s dev
    # Error
    **Error:** template: templates-all-atmos-sections:184: function "domain" not defined
    

    (Line number differs from the reporter's :156 — depends on the exact YAML structure of the component section — but the error class is identical.)

    One nuance worth flagging: the reproduction requires templates.settings.enabled: true in atmos.yaml. With the default (enabled: false), the templating step is skipped and the .tf description passes through harmlessly. The reporter's steps don't mention enabling templating, so either their atmos.yaml (not shown in the report) has it on, or they reduced the repro and dropped that detail. Either way, the bug fires for any project that has templating enabled — which is the configuration most users running on stack-level Go templates are in.

    Root cause

    The path: terraform plan → ProcessStacks(... processTemplates=true, ...) → block at internal/exec/utils.go:912-996 → templating block at internal/exec/utils.go:779-815.

    In the component-info block, Atmos reads the .tf files with terraform-config-inspect and attaches the parsed module to ComponentSection["component_info"]:

    case cfg.TerraformComponentType:
        componentPath := constructTerraformComponentWorkingDir(atmosConfig, &configAndStacksInfo)
        componentInfo[cfg.ComponentPathSectionName] = componentPath
        terraformConfiguration, diags := tfconfig.LoadModule(componentPath)
        if !diags.HasErrors() {
            componentInfo[terraformConfigKey] = terraformConfiguration
        }
        ...
    configAndStacksInfo.ComponentSection["component_info"] = componentInfo

    terraform-config-inspect returns the variables' and outputs' description fields verbatim. Then a few dozen lines earlier, when processTemplates is true, Atmos serializes the whole ComponentSection to YAML and runs it through Go templating:

    if processTemplates {
        componentSectionStr, err := atmosYaml.ConvertToYAMLPreservingDelimiters(
            configAndStacksInfo.ComponentSection,
            atmosConfig.Templates.Settings.Delimiters,
        )
        ...
        componentSectionProcessed, err := ProcessTmplWithDatasources(
            atmosConfig, &configAndStacksInfo, settingsSectionStruct,
            "templates-all-atmos-sections",
            componentSectionStr,
            ...

    So the description = \"…{{domain}}…\" from the .tf file ends up inside the YAML string being templated, Go's text/template parses {{domain}} as a function call, and fails with function \"domain\" not defined.

    This is consistent with the reporter's analysis: the templating contract is supposed to be "stack manifests only," but the component_info.terraform_config section silently smuggles arbitrary user-authored HCL description strings into the templated input.

    I confirmed describe component station -s dev --format yaml (which doesn't run templating) shows the raw description intact:

    url_doc:
      name: url_doc
      description: URL in the format https://{{domain}}/{{foobar}}

    So the data flow is real — the .tf content is being merged into ComponentSection. The bug is purely on the templating pass.

    Suggested fix directions

    Three reasonable angles, ordered from narrowest to broadest:

    1. Exclude component_info from the YAML that goes into templates-all-atmos-sections. This is the highest-value section to not template — its content is HCL-parsed module metadata, not Atmos stack manifest data, and there is no documented use case for templating descriptions/variable types/output names. Implementation: clone ComponentSection before serializing, delete the component_info key (or just the component_info.terraform_config subkey), serialize, template the result, then re-attach the original component_info. Smallest blast radius. Doesn't change behavior for any stack-manifest-level template usage.

    2. Treat module metadata descriptions as literal strings during templating. Walk terraformConfiguration before attaching it to componentInfo and escape any {{/}} in description/string fields (e.g., via the same delimiter-preservation mechanism the YAML encoder already uses to handle custom delimiters per !terraform.state fails with templated arguments when custom delimiters include quotes #2052). More involved and intrusive; users would lose the ability to intentionally template values inside descriptions, but no one is documented to rely on that.

    3. Drop terraform-config-inspect's output from ComponentSection entirely. component_info.terraform_config is consumed by a handful of places (OPA/JSON Schema validation, describe output). Audit those consumers; if none rely on the parsed module structure being present, move it out of ComponentSection and only attach it to flows that need it. Cleanest architecturally, biggest blast radius.

    (1) is the smallest correct fix and lines up with the documented contract (templating is for stack manifests, not Terraform source). The reporter's expectation — "Atmos Go templating should happen in the abstraction above Terraform modules" — maps directly to (1).

    Related issue

    The same tfconfig.LoadModule path also surfaces in #1864 (component-not-found masking a real HCL parse error); the fix in this area should be careful not to regress that error-handling logic, which now lives in the diags.HasErrors() branch at internal/exec/utils.go:920-980.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions