Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement plan-diff command #1134

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft

implement plan-diff command #1134

wants to merge 14 commits into from

Conversation

mcalhoun
Copy link
Member

@mcalhoun mcalhoun commented Mar 11, 2025

what

Create a new command that shows what has changed between two plan files

why

Helps validate that an "approved plan" hasn't changed prior to deployment

example output

$ atmos terraform plan-diff myapp -s dev --orig orig.planfile

Diff output:
        Plan differences:
        ----------------
        ~ variables.location.value: Stockholm => New Jersey
        ~ variables.instance_type.value: t3.micro => t3.large
        ~ variables.environment.value: development => production
        ~ planned_values.root_module.resources: (resource changes)
          Resources:
          Resource: aws_instance.example
          ~ ami: ami-12345 => ami-67890
          ~ instance_type: t3.micro => t3.large
          ~ tags: map[Environment:development Name:example-stockholm] => map[Environment:production Name:example-newjersey]

todo

  • Exit code 2 if there are any changes
  • Make the diffs easier to read

Copy link

codecov bot commented Mar 11, 2025

Codecov Report

Attention: Patch coverage is 65.53191% with 162 lines in your changes missing coverage. Please review.

Project coverage is 18.63%. Comparing base (f64a505) to head (8155d3a).

Files with missing lines Patch % Lines
internal/exec/terraform_utils.go 65.85% 127 Missing and 28 partials ⚠️
internal/exec/terraform.go 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1134      +/-   ##
==========================================
+ Coverage   17.44%   18.63%   +1.18%     
==========================================
  Files         170      170              
  Lines       18764    19224     +460     
==========================================
+ Hits         3274     3583     +309     
- Misses      14892    15016     +124     
- Partials      598      625      +27     
Flag Coverage Δ
unittests 18.63% <65.53%> (+1.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions bot added size/xl and removed size/l labels Mar 11, 2025
Copy link

mergify bot commented Mar 11, 2025

Warning

This PR exceeds the recommended limit of 1,000 lines.

Large PRs are difficult to review and may be rejected due to their size.

Please verify that this PR does not address multiple issues.
Consider refactoring it into smaller, more focused PRs to facilitate a smoother review process.

@osterman
Copy link
Member

osterman commented Mar 11, 2025

Could we add some whitespace and reduce leading whitespace?

For example:

$ atmos terraform plan-diff myapp -s dev --orig orig.planfile

Diff Output
===========

Plan Differences:
-----------------
~ variables.location.value: Stockholm => New Jersey
~ variables.instance_type.value: t3.micro => t3.large
~ variables.environment.value: development => production
~ planned_values.root_module.resources: (resource changes)

Resources:
----------

Resource: aws_instance.example
~ ami: ami-12345 => ami-67890
~ instance_type: t3.micro => t3.large
~ tags:
  - Environment: development => production
  - Name: example-stockholm => example-newjersey

// TestPlanDiffCommandRouting tests that the plan-diff command is correctly routed
// in the ExecuteTerraform function's switch statement.
//
// NOTE: This test will show a linter error when run separately with golangci-lint,
Copy link
Member

Choose a reason for hiding this comment

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

We have many lint rules disabled in *_test.go files. Is there another linter we should exclude?

Copy link
Member

@osterman osterman left a comment

Choose a reason for hiding this comment

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

Meant to comment, not approve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants