Skip to content

feat: Native CI/CD integration for Terraform plan/apply/deploy lifecycle - #2079

Merged
Igor Rodionov (goruha) merged 243 commits into
mainfrom
goruha/native-ci-terraform-plan
Mar 16, 2026
Merged

Igor Rodionov (goruha) merged 243 commits into
mainfrom
goruha/native-ci-terraform-plan

Conversation

@goruha

@goruha Igor Rodionov (goruha) commented Feb 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds first-class CI/CD support directly into the Atmos CLI. Running atmos terraform plan vpc -s prod in GitHub Actions now automatically produces rich job summaries, commit status checks, output variables, and stored planfile verification — no external actions required. The same command works identically locally and in CI.

What's Included

CI Framework (pkg/ci/)

  • Provider registry with auto-detection of CI environment (GitHub Actions, generic CI)
  • Plugin architecture for command-specific CI behaviors (Terraform plugin)
  • Lifecycle hooks: before.terraform.{plan,apply,deploy} / after.terraform.{plan,apply,deploy}
  • Configuration via ci: section in atmos.yaml with per-feature toggles

GitHub Provider (pkg/ci/providers/github/)

  • Job summaries written to $GITHUB_STEP_SUMMARY with resource badges, collapsible diffs, and destruction warnings
  • Commit status checks via Status API — shows "Plan in progress" while running, "3 to add, 1 to change, 0 to destroy" on completion
  • Per-operation statuses (add/change/destroy) created only when resource counts > 0
  • Output variables exported to $GITHUB_OUTPUT (has_changes, has_additions, has_destructions, plan_summary, output_*)

Generic Provider (pkg/ci/providers/generic/)

  • Prints summaries, checks, and outputs to stdout — useful for local development and any CI without native integration

Planfile Storage (pkg/ci/artifact/, pkg/ci/plugins/terraform/planfile/)

  • Multi-backend artifact storage: GitHub Artifacts, S3, local filesystem
  • Bundled tar format with plan + lock file + metadata
  • CLI commands: atmos terraform planfile {upload,download,list,show,delete}
  • Component/stack addressing: atmos terraform planfile list vpc -s dev
  • Automatic upload after plan, automatic download before deploy

Terraform CI Plugin (pkg/ci/plugins/terraform/)

  • Output parsing: resource counts, warnings, errors, changed resource lists
  • Markdown summary templates for plan and apply results (customizable via Go templates)
  • Terraform output export as CI variables after successful apply

Plan Verification (internal/exec/terraform_verify_plan.go)

  • deploy command downloads stored planfile, generates fresh plan, compares semantically
  • Fails with drift error if plans don't match; applies verified plan if they match
  • Prevents applying stale plans in CI pipelines

Documentation (website/docs/ci/)

  • Native CI overview, job summaries, planfile storage feature docs
  • CLI command reference for all planfile subcommands
  • CI configuration reference (website/docs/cli/configuration/ci/)

Configuration

ci:
  enabled: true
  summary:
    enabled: true
  output:
    enabled: true
  checks:
    enabled: true
    context_prefix: "atmos"

Test plan

  • Unit tests for CI providers, plugins, artifact storage, output parsing
  • Golden snapshot tests for summary templates
  • Integration test: atmos terraform plan vpc -s dev --ci produces summary and outputs
  • Planfile upload/download/list/show/delete CLI commands
  • Plan verification: stored vs fresh plan comparison
  • Status checks created and updated with correct URLs
  • Website builds with no broken links

References

  • PRDs: docs/prd/native-ci/

🤖 Generated with Claude Code

Implement comprehensive CI integration with rich tfcmt-style templates for terraform plan/apply outputs. Auto-generates job summaries, outputs, and artifact management.

- Add CIProvider interface for extensible CI component support
- Implement terraform CI provider with JSON-based output parsing
- Create embedded default templates (plan.md, apply.md) with resource counts, badges, and collapsible sections
- Add template loader with atmos.yaml override support (base_path, per-component templates)
- Add generic CI provider for local testing (--ci flag without platform detection)
- Implement unified CI executor with hook bindings and declarative actions
- Add golden file tests for template regression testing
- Add --ci flag to plan/apply commands (respects CI env var precedence)
- Wire CI hooks through terraform PostRunE for automatic execution

Template features match existing GitHub Actions with tfcmt formatting:
- Plan summaries with resource change badges (CREATE, CHANGE, REPLACE, DESTROY)
- Caution warning when resources will be deleted
- Terraform output variables table after apply
- Error/warning extraction from command output
- Markdown rendering with collapsible sections

CI integration is controlled by:
1. ci.enabled in atmos.yaml (enables/disables integration)
2. CI environment detection (GitHub Actions auto-detected)
3. --ci flag on plan/apply (forces CI mode for testing)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
- Add defer perf.Track() to all public functions in CI package
- Fix import ordering (go-fumpt)
- Fix octal literal formatting (0644 → 0o644)
- Update golangci.yml to exclude pkg/ci/github/ from depguard
- Update lintroller to exclude pkg/ci/ from some checks
- Fix test file permission literals

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Announces the new native CI integration feature with:
- Simple GitHub Actions workflow examples
- Explanation of auto-detection and --ci flag
- Matrix strategy for multiple components
- Local testing instructions
- Configuration options

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The planfile command and pkg/ci/planfile packages were not committed
because .gitignore had a rule `**/planfile` which ignored any directory
named "planfile". Changed the rule to only ignore files matching
`*.planfile` pattern (already covered by existing rules).

Also:
- Fixed broken link in CI integration blog post that referenced /ci
- Added pkg/ci/planfile/s3/ to golangci exclusions for AWS SDK imports
- Fixed lint issues in internal/exec/describe_affected.go

Note: The newly tracked files have pre-existing lint issues that will
need to be addressed in a follow-up commit.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The constant was already defined in docs_generate.go in the same package.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Refactored CI integration code to resolve all lint issues without
using nolint directives:

- Extract helper functions to reduce cyclomatic/cognitive complexity
- Use pointer parameters for large structs (hugeParam fixes)
- Extract constants for magic numbers
- Refactor nested if blocks into early returns
- Split long functions into focused helpers

Files refactored:
- cmd/ci/status.go: Split getRepoContext into helper functions
- cmd/terraform/planfile/*.go: Extract format/download helpers
- pkg/ci/executor.go: Extract platform detection and binding logic
- pkg/ci/terraform/parser.go: Extract resource processing functions
- pkg/ci/planfile/github/store.go: Extract repo info and zip handling
- pkg/ci/templates/loader.go: Extract template loading by source

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Regenerated golden snapshots to reflect new CI integration features:
- New `ci` command in atmos --help output
- New `planfile` subcommand under `terraform`
- New `--ci` flag for terraform plan/apply commands
- New CI configuration fields in describe config output

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Use filepath.FromSlash() for path literals in test expectations to
ensure the test passes on both Unix and Windows, where path separators
differ.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- native-ci-integration.md: Added Implementation Status section showing
  Phase 1 complete, Phase 2 ~70%, and Phases 3-6 pending. Updated
  package structure and Files to Create table with status indicators.
  Documented additional components implemented beyond original PRD.

- ci-summary-templates.md: Marked as complete with all files implemented.
  Added missing test files to the implementation table.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Address review comment: clarify that ci.enabled: true in atmos.yaml
is respected as a way to enable CI mode. Added numbered list of
activation conditions and clarified precedence order.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
This commit addresses multiple CodeRabbit review comments:

- cmd/terraform/planfile/download.go: Fix double %w error wrapping using
  errors.Join, fix Windows path handling using filepath.Base()
- cmd/terraform/planfile/upload.go: Fix unreachable GitHub Actions detection
  by reordering store type logic
- pkg/ci/github/checks.go: Add documentation for completed status mapping,
  remove unused mapGitHubConclusionToCheckRunState function
- pkg/ci/planfile/github/store.go: Add HTTP timeout (30s) for artifact
  downloads, fix error wrapping with errors.Join
- pkg/ci/planfile/local/store.go: Fix file filter to only skip .metadata.json
  files
- pkg/ci/planfile/s3/store.go: Simplify error check functions by removing
  unused second parameter
- pkg/ci/terraform/provider.go: Add nil check for result parameter in
  GetOutputVariables
- tools/lintroller/rule_perf_track.go: Add pkg/template exclusion with proper
  documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
This commit addresses the second round of CodeRabbit review comments:

Comment #1 - Global flags in planfile commands:
- Add global flag parsing (--base-path, --config, --config-path, --profile)
  to delete.go, download.go, and upload.go using flags.ParseGlobalFlags()
- Refactored upload.go to extract helper functions and reduce function length

Comment #3 - GenerateKey placeholder validation:
- Add validation for required fields (Stack, Component, SHA) when used in pattern
- Return ErrPlanfileKeyInvalid error instead of leaving placeholders unreplaced
- Update interface_test.go with new test cases for validation behavior

Comments #4-5 - Golden file anchor mismatches:
- Update templates to use user-content- prefix on anchor IDs for proper
  markdown link fragment resolution
- Regenerate all golden files to match new template output

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add test files for CI integration packages to improve code coverage:

- pkg/ci/planfile/github/store_test.go: GitHub Artifacts store tests
- pkg/ci/planfile/s3/store_test.go: S3 store helper function tests
- pkg/ci/github/status_test.go: GitHub status fetching tests
- pkg/ci/github/checks_test.go: Check run creation/update tests
- cmd/ci/status_test.go: CI status command helper tests
- pkg/ci/output_test.go: Output writer tests
- cmd/terraform/planfile/upload_test.go: Upload command helper tests
- cmd/terraform/planfile/list_test.go: List formatting tests
- Expanded pkg/ci/executor_test.go with data structure tests
- Expanded pkg/ci/planfile/local/store_test.go with edge cases

Also removes accidentally committed lintroller binary and adds it to
.gitignore.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Reorganize CI configuration from confusing nested structure to a cleaner,
provider-agnostic structure with four top-level capabilities:

- output: key=value pairs for downstream jobs (GitHub: $GITHUB_OUTPUT)
- summary: markdown job summary (GitHub: $GITHUB_STEP_SUMMARY)
- checks: commit status checks (GitHub: Check Runs API)
- comments: PR/MR comments (GitHub: PR comments, GitLab: MR notes)

Key changes:
- Rename status_checks -> checks
- Rename pr_comment -> comments
- Move variables under output where it belongs
- Remove outputs wrapper (was conflating concepts)
- Add template field to summary and comments configs

This structure supports GitHub Actions, GitLab CI, and other CI providers
with consistent, intuitive naming.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add isActionEnabled() to check if CI actions are enabled based on config
- Summary and Output enabled by default, Checks disabled by default
- Upload/Download always enabled (controlled by planfile config)
- Add filterVariables() to filter output variables by CI.Output.Variables
- Update executeSummaryAction() to support custom template from config
- Add comprehensive tests for config-aware behavior

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Use ErrNotImplemented for GitHub Artifacts upload limitation
- Fix broken internal link fragment in plan_no_changes.md template
- Remove non-deterministic TestGetDefaultProvider test
- Remove tautological TestTableHeaderWidth and TestPlanfileInfoSorting tests
- Use errors.Is() for specific error sentinel verification in upload_test.go
- Handle JSON decode errors in checks_test.go mock handlers
- Check url.Parse errors in checks_test.go
- Fix config key names in PRD docs (ci.checks.enabled, ci.comments.enabled)
- Add Screengrab component to ci/status.mdx per documentation standards

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Changes:
- Use consistent fmt.Errorf("%w: ...") pattern in planfile store instead
  of errors.Join() for consistency with other methods
- Make error messages unique to avoid linter warning about duplicate
  string literals
- Fix type switch on error to use errors.As() in config loading
- Add nolint comment for ATMOS_CLI_CONFIG_PATH os.Getenv (bootstrap config)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Move environment variables from step level to job level in workflow
examples for better practice. This ensures all steps in the job have
access to the environment variables without repetition.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Lead with WHY before WHAT: complex bash scripts in CI workflows signal
hidden complexity from tools not designed for CI. The reproducibility
principle—same command, same behavior everywhere—is now the core
narrative for native CI integration.

PRD changes:
- Add Executive Summary with key insight
- Expand Problem Statement with Hidden Complexity Problem
- Add The Reproducibility Principle section with before/after examples
- Rename "What You Get" to "What This Enables" (after context)
- Remove duplicate Problem Statement section

Blog post changes:
- Lead with reproducibility narrative
- Add "The Problem with CI Glue Code" section
- Add "The Reproducibility Principle" with concrete examples
- Add "What This Enables" to connect solution to problem

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add Functional Requirements (FR-1 through FR-9):
- FR-1: CI Environment Detection
- FR-2: Job Summary Output
- FR-3: CI Output Variables
- FR-4: Status Checks
- FR-5: Planfile Storage
- FR-6: Plan Verification
- FR-7: Command Parity
- FR-8: Describe Affected Matrix Format
- FR-9: CI Status Command

Add Non-Functional Requirements (NFR-1 through NFR-4):
- NFR-1: Performance targets
- NFR-2: Reliability (graceful degradation)
- NFR-3: Security boundaries
- NFR-4: Extensibility

Fix matrix examples to use --output-file flag:
- Add --output-file="$GITHUB_OUTPUT" usage pattern
- Show complete workflow example with affected job
- Document key=value output format for $GITHUB_OUTPUT

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The pkg/template package performs template.Parse and recursive AST
tree traversal, which are non-trivial operations requiring perf
tracking per coding guidelines. Only trivial String() methods qualify
for exclusion.

Addresses CodeRabbit review comment.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Parse global flags before loading config in ci status command
- Add static error sentinels for planfile operations
- Add validation to planfile registry Register function
- Wrap errors with static sentinels in local and S3 stores
- Fix MD028 violations in markdown templates with HTML comments

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Update snapshots to reflect:
- CI config schema changes (outputs->output, status_checks->checks,
  pr_comment->comments, added summary section)
- New terraform apply flags (--auto-generate-backend-file,
  --init-run-reconfigure)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Update snapshot for terraform plan --help to include new flags:
- --auto-generate-backend-file
- --init-run-reconfigure

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
On Windows, filepath.IsAbs() requires a drive letter (e.g., C:\) for a
path to be considered absolute. The test was using Unix-style paths
(/absolute/path) which become \absolute\path on Windows - not absolute.

This fix uses runtime.GOOS to select appropriate absolute paths for
each platform, ensuring the test works correctly on both Windows and
Unix systems.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
1. delete.go: Require --force flag for deletion (returns error instead
   of silently exiting), using static error ErrPlanfileDeleteRequireForce
2. list.go: Add global flag parsing (--base-path, --config, etc.)
3. show.go: Add global flag parsing (--base-path, --config, etc.)
4. check.go: Add Name field to UpdateCheckRunOptions (distinct from Title)
5. checks.go: Use opts.Name instead of opts.Title for GitHub API

Note: Comment #5 about template field access was investigated and found
to be a false positive. The templates correctly access fields from
TerraformTemplateContext which provides .Resources, .HasChanges() etc.
at the top level (not under .Result).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Refactor all 5 planfile commands (list, show, delete, download, upload) to:
1. Use StandardParser pattern for flag handling (instead of package-level variables)
2. Use pkg/list infrastructure for list output formatting (instead of custom formatters)

Benefits:
- Automatic environment variable support (ATMOS_PLANFILE_*)
- Proper precedence handling (CLI > ENV > config > defaults)
- Type-safe options structs
- Consistent output formatting with TTY detection
- Less code to maintain

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The local variable `fmt` was shadowing the imported fmt package.
Renamed to `outputFmt` to avoid the shadowing issue.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Use *bool pointer types for CI config Enabled fields to distinguish
  "not set" from "explicitly false" (fixes isActionEnabled defaults)
- Document Detect() non-deterministic map iteration order in registry.go
- Replace manual mock with mockgen-generated MockComponentCIProvider
- Add validation for empty Stack/ComponentFromArg in GetArtifactKey
- Add perf.Track() to RunCIHooks function per coding guidelines

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

These changes were released in v1.210.0-test.18.

@github-actions

Copy link
Copy Markdown

These changes were released in v1.210.0-test.19.

@github-actions

Copy link
Copy Markdown

These changes were released in v1.210.0-test.20.

@mergify

mergify Bot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

💥 This pull request now has conflicts. Could you fix it Igor Rodionov (@goruha)? 🙏

…se/atmos into goruha/native-ci-terraform-plan

* 'goruha/native-ci-terraform-plan' of github.com:cloudposse/atmos:
  [autofix.ci] apply automated fixes
  chore: loosen issue templates and add AI prompt type (#2179)
  Add AI-assisted section to homepage (#2166)
@github-actions

Copy link
Copy Markdown

These changes were released in v1.210.0-test.21.

@github-actions

Copy link
Copy Markdown

These changes were released in v1.210.0-test.25.

@github-actions

Copy link
Copy Markdown

These changes were released in v1.210.0-test.27.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Mar 16, 2026
@github-actions

Copy link
Copy Markdown

These changes were released in v1.210.0-test.28.

@github-actions

Copy link
Copy Markdown

These changes were released in v1.210.0-rc.1.

This branch had an error being deployed

1 failed and 1 active deployments
feature-releases — 99bb769d Deployed Mar 16, 2026 by mergify[bot] via release / goreleaser #13724
preview — 99bb769d Deployed Mar 16, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch A minor, backward compatible change release/feature Create release from this PR size/xxl

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants