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

Fix terraform plan file should not be deleted #855

Merged
merged 1 commit into from
Dec 14, 2024

Conversation

samtholiya
Copy link
Collaborator

@samtholiya samtholiya commented Dec 13, 2024

issue: https://linear.app/cloudposse/issue/DEV-2825/atmos-terraform-show-deletes-planfile

what

  • Stop deleting planfile after terraform show

why

We should not delete the terraform plan file if the user uses show to check his results.

Test

Steps:

  1. cd examples/quick-start-simple
  2. ../../build/atmos terraform plan -s dev station
  3. ../../build/atmos terraform show -s dev station --json dev-station.planfile --skip-init

Verified if the file ./examples/quick-start-simple/components/terraform/weather/dev-station.planfile still exists.

Before this change: deleted

After this change: present

references

issue: https://linear.app/cloudposse/issue/DEV-2825/atmos-terraform-show-deletes-planfile

conversation: https://sweetops.slack.com/archives/C031919U8A0/p1733924783112799

Summary by CodeRabbit

  • Bug Fixes
    • Updated cleanup logic to prevent unintended removal of plan files when the subcommand is "show".

@samtholiya samtholiya requested review from a team as code owners December 13, 2024 21:53
Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request modify the ExecuteTerraform function within internal/exec/terraform.go. The update enhances the cleanup logic by adding a condition to prevent the deletion of the plan file when the info.SubCommand is "show". This complements the existing condition that prevents deletion when the subcommand is "plan". The cleanup logic for the variable file remains unchanged.

Changes

File Change Summary
internal/exec/terraform.go Modified cleanup logic in ExecuteTerraform to prevent plan file deletion for "show" subcommand.

Assessment against linked issues

Objective Addressed Explanation
Prevent deletion of plan file when using show (DEV-2825)

Suggested labels

patch

Suggested reviewers

  • kevcube

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22c9b28 and 78f5fb0.

📒 Files selected for processing (1)
  • internal/exec/terraform.go (1 hunks)
🔇 Additional comments (2)
internal/exec/terraform.go (2)

Line range hint 485-488: LGTM! Variable file cleanup remains unchanged.

The cleanup logic for the variable file is correctly maintained, only removing it after the apply command.


481-484: LGTM! The change effectively prevents plan file deletion.

The modification correctly preserves the plan file when running terraform show, which aligns with the PR objective. The logic is consistent with the existing behavior for the plan subcommand.

Let's verify the behavior with different terraform commands:

✅ Verification successful

The plan file cleanup logic is correctly implemented and consistent with the codebase's behavior

The verification confirms that:

  • Plan files are preserved for both plan and show commands
  • Plan file cleanup occurs for other commands except when a specific plan file is provided via PlanFile
  • The behavior aligns with the command flow, where show command needs the plan file for displaying the plan details
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify plan file handling across different terraform commands
# Expected: Plan file should be preserved for 'plan' and 'show' commands, but removed for others

# Test 1: Search for plan file cleanup logic
rg -A 5 "PlanFile == \"\"" internal/exec/terraform.go

# Test 2: Search for all terraform show command handling
rg -A 5 "SubCommand.*show" internal/exec/terraform.go

Length of output: 849


Script:

#!/bin/bash
# Let's verify the complete context of terraform command handling
# to ensure the plan file cleanup logic is consistent

# Search for all terraform command handling patterns
rg -B 5 -A 10 "info\.SubCommand\s*==" internal/exec/terraform.go

# Check if there are any other places where plan files are handled
rg -A 5 "planFilePath" internal/exec/terraform.go

Length of output: 8159


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@aknysh aknysh added the patch A minor, backward compatible change label Dec 14, 2024
@osterman
Copy link
Member

I think you've identified the culprit here causing the problem however I think that our approach is wrong. Rather than by default deleting files for a virtually any command, which is an unexpected behavior, especially for command like running help, I think we should instead identify when if ever we should delete files automatically. We have a separate command called atmos terraform clean that handles this.

In other words, I think what I'm proposing is we just remove this deletion altogether.

@osterman
Copy link
Member

osterman commented Dec 14, 2024

@aknysh what are your thoughts about this?

@aknysh
Copy link
Member

aknysh commented Dec 14, 2024

@aknysh what are your thoughts about this?

we had disabled the deletion altogether once, but then people started complaining that Atmos leaves a lot of files behind :)
we re-enabled it again

I agree that the best approach would be to only clean after the commands that actually generate the files

All help commands get executed before this part of the code, they don't delete any files

@aknysh aknysh merged commit c0e7054 into main Dec 14, 2024
30 checks passed
@aknysh aknysh deleted the feature/dev-2825-atmos-terraform-show-deletes-planfile branch December 14, 2024 03:35
Copy link

These changes were released in v1.123.1.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants