Skip to content

design(terraform): reconcile — plan drift as a PR today, HCL regeneration through import blocks later #2089

Description

@lex00

Sub-issue 8 of #2081. Not blocked, filed for later.

Reconcile is the middle setting on the dial (docs/src/content/docs/concepts/lifecycle-models.mdx, "The dial"): observe reports, reconcile pulls live reality back into source, authoritative pushes source into the cloud. docs/src/content/docs/guide/reconciling-lifecycle.mdx covers the cloud-to-code direction, and lexicons/temporal/src/composites/reconcile-op.ts implements it as Snapshot, Plan, Reconcile, where reconcilePr regenerates TypeScript via chant import --from <env> and opens a PR whose diff is the regenerated source.

That mechanism does not carry over. The terraform lexicon does not synthesize HCL and has no typed model to regenerate from, so chant import has nothing to emit. Cloud-to-code here means writing HCL someone else authored, in their style and their module layout. There is no path from live state to .tf that chant owns.

The v1 is what #2087 already covers: TerraformWatchOp with findingMode: "issue" or "pull-request", carrying the -no-color human plan. A human reads it and decides whether source or the cloud is wrong.

The candidate later path is Terraform's own generator. terraform plan -generate-config-out=<file> with import {} blocks (Terraform 1.5 and up) emits HCL for resources present in the cloud but absent from state. That fits a reconcilePr-shaped activity: run the generator, commit the generated file plus the import blocks, open a PR. The output is a starting point rather than finished code, which is the right thing to put in front of a reviewer.

Open questions:

  • Where do the import {} blocks come from? Terraform will not enumerate unmanaged resources; something has to name the addresses and cloud ids first.
  • Which cloud does the enumeration? Reusing the aws/gcp/azure lexicons' live reads is one option and drags in a cross-lexicon dependency.
  • Where does the generated file land in someone else's module layout, and who decides?
  • Does the ownership answer hold? Everything reconciled in is by definition not in state yet, so it reports unknown until the import lands.
  • Is this a terraform-lexicon concern at all, or a chant import backend?

What would turn this into an implementable issue: a decision on the enumeration source (question 2), and one worked end-to-end example on a small AWS root showing generated HCL plus import blocks that terraform plan accepts as a no-op afterwards.

Activity

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

    area:lifecycleplan/diff/apply/observe/drift/prune/search --livearea:terraformTerraform lexicondesignDesign or research note, no deliverable yet

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions