Skip to content

implement plan-diff command#1134

Closed
mcalhoun wants to merge 21 commits intomainfrom
atmos/terraform-plan-diff
Closed

implement plan-diff command#1134
mcalhoun wants to merge 21 commits intomainfrom
atmos/terraform-plan-diff

Conversation

@mcalhoun
Copy link
Contributor

@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

@codecov
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
@mergify
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

osterman
osterman previously approved these changes Mar 11, 2025
// 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.

@mergify
Copy link

mergify bot commented Mar 11, 2025

💥 This pull request now has conflicts. Could you fix it @mcalhoun? 🙏

@mergify mergify bot added the conflict This PR has conflicts label Mar 11, 2025
@mergify mergify bot removed the conflict This PR has conflicts label Mar 11, 2025
@mergify
Copy link

mergify bot commented Mar 12, 2025

💥 This pull request now has conflicts. Could you fix it @mcalhoun? 🙏

@mergify mergify bot added the conflict This PR has conflicts label Mar 12, 2025
@osterman osterman added the minor New features that do not break anything label Mar 12, 2025
@mergify mergify bot removed the conflict This PR has conflicts label Mar 12, 2025
@mcalhoun
Copy link
Contributor Author

Closing in favor of implementation in #1144

@mcalhoun mcalhoun closed this Mar 13, 2025
@mcalhoun mcalhoun deleted the atmos/terraform-plan-diff branch March 24, 2025 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor New features that do not break anything

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants