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

[Feature] Get contents of deleted file #938

Closed
2 tasks done
SamuelMolling opened this issue Jan 6, 2023 · 9 comments
Closed
2 tasks done

[Feature] Get contents of deleted file #938

SamuelMolling opened this issue Jan 6, 2023 · 9 comments
Labels
enhancement New feature or request

Comments

@SamuelMolling
Copy link

Is this feature missing in the latest version?

  • I'm using the latest release

Is your feature request related to a problem? Please describe.

Basically I'm using this action to get all the files that were changed/created and run terragrun on top of each one. My problem today is that for me to destroy a resource in terragrunt, I need the file. What I would like is to take the file that was deleted, keep it until the end of the workflow execution and delete it, so that the resources can be deleted.

Describe the solution you'd like?

It would be something like:

  - name: Run changed-files with dir_names
    id: changed-files-dir-names
    uses: tj-actions/changed-files@v35
    with:
      dir_names: "true"
      content_file_tmp: "true"
      files: |
        terraform/mongodb-atlas/clusters/**

  - name: Terragrunt Destroy
    id: destroy
    run: |
      for folder in ${{ steps.changed-files-dir-names.outputs. file_tmp }}; do
        terragrunt destroy -auto-approve --terragrunt-working-dir $folder
      done 

Describe alternatives you've considered?

I couldn't think of many things at the moment.

In summary, I would like to run my destroy on the file before it is deleted or get the state prior to deletion, mount it and run. then discard it.

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@SamuelMolling SamuelMolling added the enhancement New feature or request label Jan 6, 2023
@jackton1
Copy link
Member

jackton1 commented Jan 6, 2023

@SamuelMolling does the file need to still be located in the workspace directory or can it reside in a temp directory?

@SamuelMolling
Copy link
Author

The file needs to reside in the directory, on account of the state file, located in a bucket in the google cloud

@SamuelMolling
Copy link
Author

Also, I would like to know if it is possible to run on all modified files excluding one.

@SamuelMolling
Copy link
Author

To solve the problem, I made an if, like this.

      for folder in ${{ steps.changed-files-dir-names.outputs.all_changed_files }}; do
        if [ -f $folder/cluster.hcl ]
        then
          echo "cluster.hcl found"
        else
          terragrunt init --terragrunt-working-dir $folder
        fi
      done 

@jackton1
Copy link
Member

jackton1 commented Jan 8, 2023

Given the complexity of reverting the state of the repository in order support this feature, I’ll recommend your workflow destroys the resource via inputs if necessary and deletes the related folder prior to committing the changes.

@jackton1 jackton1 closed this as completed Jan 8, 2023
@SamuelMolling
Copy link
Author

@jackton1 Do you have an idea how to do it? I'm not sure how I would do it. Would you have to open 2 prs there? One to destroy and another to delete the files, right?

@SamuelMolling
Copy link
Author

@jackton1 It is not possible to recover the value of the deleted file in PR and create it temporarily in the container and then remove it, I believe it is not so complicated to get this value, there is a load diff, basically it would be to get the value before it for deleted files .

@SamuelMolling
Copy link
Author

SamuelMolling commented Feb 6, 2023

If there is a way to recover the value of the deleted file, I can do the logic locally to create it and then delete it.

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

No branches or pull requests

2 participants