Skip to content

fix: emit drift metadata block on plan parse errors#144

Merged
Kevin (kevcube) merged 1 commit into
cloudposse:mainfrom
9spokes:fix/drift-metadata-on-parse-error
Jul 2, 2026
Merged

fix: emit drift metadata block on plan parse errors#144
Kevin (kevcube) merged 1 commit into
cloudposse:mainfrom
9spokes:fix/drift-metadata-on-parse-error

Conversation

@AleksandrMatveev

Copy link
Copy Markdown
Contributor

what

  • Add {{template "metadata" .}} to the when_parse_error branch of the drift-detection issue markdown in config/summary.yaml.
  • This makes the hidden json metadata block present on failure issues that originate from a Terraform/atmos parse error, not just on successful/drift plans.

why

  • The companion cloudposse/github-action-atmos-terraform-drift-detection action only reconciles issues whose body contains a parseable ```json metadata block — it derives its matching key (<stack>-<component>) from that block and filters out any issue where getMetadataFromIssueBody(body) returns null.
  • The main terraform.plan.template already appends {{template "metadata" .}} to its issue section, but the when_parse_error template (used when Terraform/atmos fails before producing a parseable plan — e.g. an OIDC/cloud-auth timeout or other early/network error) did not.
  • As a result, "Failure Detected" issues created from early failures carried no metadata block, so the drift-detection action could never match them to a component and never auto-closed them once the component recovered. These issues accumulate open indefinitely.
  • All template vars used by the metadata template (component, stack, componentPath, commitSHA) are already passed to tfcmt in both invocations, so they render correctly in the parse-error path. The change is a single line and does not affect the non-drift (PR comment) output.
  • Verified in production over several days: pre-existing orphaned failure issues became closeable, and newly-created failure issues are now auto-closed by subsequent successful runs.

references

  • Reconcile filter that requires the metadata block: cloudposse/github-action-atmos-terraform-drift-detectionsrc/action.js (mapOpenGitHubIssuesToComponents) and src/models/stacks_from_issues.js (getMetadataFromIssueBody).

Append `{{template "metadata" .}}` to the `when_parse_error`
issue-markdown output so "Failure Detected" issues created from early
failures (e.g. OIDC/AWS auth timeouts) carry the json metadata block.

Without it the drift-detection reconcile action cannot match the issue
to a component and never auto-closes it once the component recovers.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR ensures drift-detection “Failure Detected” GitHub issues include the hidden JSON metadata block even when Terraform/atmos fails early (plan parse errors), allowing the companion drift-detection action to reliably match and auto-close recovered components.

Changes:

  • Appends {{template "metadata" .}} to the when_parse_error drift-mode issue markdown branch in config/summary.yaml.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kevcube Kevin (kevcube) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM makes sense to me.

@kevcube Kevin (kevcube) added enhancement New feature or request minor New features that do not break anything feature New functionality labels Jul 2, 2026
@kevcube
Kevin (kevcube) merged commit 9ba7d4f into cloudposse:main Jul 2, 2026
7 of 21 checks passed
@kevcube

Copy link
Copy Markdown
Member

Thanks for the contribution AleksandrMatveev s

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

Changes Found for foobar/changes in plat-ue2-sandbox


create

Plan: 1 to add, 0 to change, 0 to destroy.
To reproduce this locally, run:

atmos terraform plan foobar/changes -s plat-ue2-sandbox

Create

+ random_id.foo[0]
Terraform Plan Summary
  # random_id.foo[0] will be created
  + resource "random_id" "foo" {
      + b64_std     = (known after apply)
      + b64_url     = (known after apply)
      + byte_length = 8
      + dec         = (known after apply)
      + hex         = (known after apply)
      + id          = (known after apply)
      + keepers     = {
          + "seed" = "foo-plat-ue2-sandbox-blue"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Warning: Test warning summary

  with data.validation_warning.warn[0],
  on main.tf line 20, in data "validation_warning" "warn":
  20: data "validation_warning" "warn" {

Test warning details

Warning

Warning: Test warning summary

  with data.validation_warning.warn[0],
  on main.tf line 20, in data "validation_warning" "warn":
  20: data "validation_warning" "warn" {

Test warning details

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

Labels

enhancement New feature or request feature New functionality minor New features that do not break anything plat-ue2-sandbox-foobar_changes/add-or-update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants