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

add terraform clean --everything and terraform clean --force to delete terraform.tfstate.d folder #727

Merged
merged 86 commits into from
Dec 5, 2024
Merged
Changes from 1 commit
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
10f8570
add terraform clean delete terraform.tfstate.d folder if the `--ever…
haitham911 Oct 15, 2024
594be52
add comment
haitham911 Oct 15, 2024
aaf17de
Merge branch 'main' into DEV-346
aknysh Oct 16, 2024
61136f4
Refactor processArgsAndFlags function to handle additional options wi…
haitham911 Oct 17, 2024
447105b
Refactor path_utils.go and add new functions for finding folders with…
haitham911 Oct 17, 2024
014dd09
add --everything provide additional options for the 'atmos terraform …
haitham911 Oct 17, 2024
ff42d22
Refactor path_utils.go to improve folder search and deletion function…
haitham911 Oct 17, 2024
23b320a
add comment to function
haitham911 Oct 17, 2024
36e946d
Merge branch 'main' into DEV-346
haitham911 Oct 17, 2024
e290655
Refactor processArgsAndFlags function to handle options and component…
haitham911 Oct 17, 2024
5713f90
Refactor help.go to improve 'atmos terraform clean' command documenta…
haitham911 Oct 17, 2024
5749a47
use filepath ensure cross-platform compatibility
haitham911 Oct 17, 2024
5985dcb
findFoldersNamesWithPrefix function to clarify search levels
haitham911 Oct 17, 2024
10a097c
Refactor ExecuteTerraform function to use descriptive variable names …
haitham911 Oct 17, 2024
9dda130
Refactor ExecuteTerraform function to use descriptive variable names …
haitham911 Oct 17, 2024
fd16997
Refactor processArgsAndFlags function to handle additional arguments …
haitham911 Oct 17, 2024
34e7b6f
Merge branch 'main' into DEV-346
osterman Oct 20, 2024
bcdbbc5
Refactor help.go to clarify Terraform state file deletion and add for…
haitham911 Oct 23, 2024
2fd446b
Refactor deleteFilesAndFoldersRecursive function to improve error han…
haitham911 Oct 23, 2024
c08a46a
rename file bubble_msg.go
haitham911 Oct 23, 2024
0610b30
use log package for deletion logging
haitham911 Oct 23, 2024
57953db
Refactor deleteFilesAndFoldersRecursive function to improve error han…
haitham911 Oct 24, 2024
33a6a07
Refactor bubble_msg.go to improve confirmation dialog state handling
haitham911 Oct 24, 2024
2843529
Refactor Confirm function to handle confirmation dialog state and mod…
haitham911 Oct 24, 2024
47ca61c
Refactor bubble_msg.go to improve confirmation dialog state handling …
haitham911 Oct 24, 2024
b14b1e9
command with --everything or --force flags
haitham911 Oct 24, 2024
4944db7
remove comment
haitham911 Oct 24, 2024
760c725
Refactor error handling in ExecuteTerraform function
haitham911 Oct 24, 2024
5a67dee
Refactor error handling in findFoldersNamesWithPrefix function
haitham911 Oct 24, 2024
f56b15d
Refactor help.go to improve 'atmos terraform clean' command documenta…
haitham911 Oct 24, 2024
beee637
Refactor error handling in findFoldersNamesWithPrefix and ExecuteTerr…
haitham911 Oct 24, 2024
76943f1
Refactor confirm delete msg
haitham911 Oct 24, 2024
9a3eca0
log waring with no confirm msg
haitham911 Oct 24, 2024
a7b57c2
Refactor error handling in findFoldersNamesWithPrefix function
haitham911 Oct 24, 2024
893b725
Refactor clean command to improve Terraform state file deletion
haitham911 Oct 24, 2024
0fc70e1
Refactor clean command to improve Terraform state file deletion
haitham911 Oct 24, 2024
3d57f25
confirm msg color
haitham911 Oct 25, 2024
2045cce
add log clean all components
haitham911 Oct 25, 2024
4ff0fa9
check file exist before delete
haitham911 Oct 25, 2024
3d0fd44
use filepath pkg
haitham911 Oct 25, 2024
b5042eb
modify log
haitham911 Oct 25, 2024
2c30fd3
use DeletePathTerraform utility
haitham911 Oct 25, 2024
5378abd
Refactor clean subcommand to handle terraform component cleanup
haitham911 Oct 27, 2024
c24eac9
Refactor clean subcommand to use filepath package for path manipulation
haitham911 Oct 27, 2024
1c8a4b9
Refactor clean empty dir
haitham911 Oct 27, 2024
483c19e
remove print line for debug
haitham911 Oct 27, 2024
fa94d4f
Refactor clean subcommand to handle relative path correctly
haitham911 Oct 27, 2024
32d01f6
Refactor clean subcommand to handle relative path correctly
haitham911 Oct 27, 2024
21e92d8
Refactor help message for 'atmos terraform clean' command
haitham911 Oct 28, 2024
130560b
Refactor clean subcommand
haitham911 Oct 28, 2024
0350c8a
Refactor clean subcommand to use u.PrintMessage instead of u.LogInfo …
haitham911 Oct 28, 2024
5b54e15
Refactor clean TF_DATA_DIR with everything
haitham911 Oct 28, 2024
a87b585
Refactor handleTFDataDir to handle relative path correctly
haitham911 Oct 28, 2024
bb688a3
Merge branch 'main' into DEV-346
aknysh Oct 29, 2024
be055a8
Refactor error messages for invalid TF_DATA_DIR and missing stack
haitham911 Oct 30, 2024
3e65888
Update internal/exec/terraform_clean.go
osterman Oct 30, 2024
3274fbc
Refactor handleCleanSubCommand to improve deletion messaging and stre…
haitham911 Oct 31, 2024
ee133a6
Calculate total objects to delete by counting files in folders
haitham911 Oct 31, 2024
5153cea
Merge branch 'main' into DEV-346
haitham911 Oct 31, 2024
bb63396
Update dependencies in go.mod and go.sum to include new packages
haitham911 Oct 31, 2024
dc5934b
Merge branch 'main' into DEV-346
haitham911 Nov 2, 2024
fbaa62a
update dependencies: upgrade lipgloss to v1.0.0 and x/ansi to v0.4.2;
haitham911 Nov 2, 2024
9155801
Merge branch 'main' into DEV-346
aknysh Nov 6, 2024
9390f77
Merge branch 'main' into DEV-346
haitham911 Nov 13, 2024
55b89c5
chore: update charmbracelet/x dependencies in go.mod
haitham911 Nov 13, 2024
30e8b05
fix: remove duplicate help message for clean operation in help.go
haitham911 Nov 14, 2024
1fcf12d
Merge branch 'main' into DEV-346
osterman Nov 14, 2024
d5cdb29
feat: enhance terraform clean command with --everything and --force o…
haitham911 Nov 14, 2024
f774bfe
Update website/docs/cli/commands/terraform/terraform-clean.mdx
osterman Nov 14, 2024
e2b4e96
Update website/docs/cli/commands/terraform/terraform-clean.mdx
osterman Nov 14, 2024
4759e13
Update website/docs/cli/commands/terraform/usage.mdx
osterman Nov 14, 2024
345fb38
Update website/docs/cli/commands/terraform/usage.mdx
osterman Nov 14, 2024
9d9ee69
Update website/docs/cli/commands/terraform/usage.mdx
osterman Nov 14, 2024
1ad31a6
Update website/docs/cli/commands/terraform/usage.mdx
osterman Nov 14, 2024
fad5e6d
Refactor error handling in handleCleanSubCommand for TF_DATA_DIR vali…
haitham911 Nov 15, 2024
191c444
Merge branch 'main' into DEV-346
osterman Nov 17, 2024
cee4ffc
fix: correct typo in documentation
haitham911 Nov 17, 2024
59940ce
fix html doc
haitham911 Nov 17, 2024
870ce20
fix: validate that the base path exists in CollectDirectoryObjects
haitham911 Nov 18, 2024
cbecdcf
fix: pass cliConfig to findFoldersNamesWithPrefix and getStackTerrafo…
haitham911 Nov 19, 2024
813e9eb
fix: enhance DeletePathTerraform to handle symbolic links and improve…
haitham911 Nov 21, 2024
f452447
fix: improve error handling in deleteFolders function for better dele…
haitham911 Nov 24, 2024
149f4c9
Merge branch 'main' into DEV-346
haitham911 Nov 24, 2024
5e0c92f
fix: streamline error handling in deleteFolders function for improved…
haitham911 Nov 24, 2024
5564dc0
Merge branch 'main' into DEV-346
osterman Dec 4, 2024
d7cfbbf
Merge branch 'main' into DEV-346
aknysh Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions internal/exec/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
outFlag = "-out"
varFileFlag = "-var-file"
skipTerraformLockFileFlag = "--skip-lock-file"
everything = "--everything"
haitham911 marked this conversation as resolved.
Show resolved Hide resolved
)

// ExecuteTerraformCmd parses the provided arguments and flags and executes terraform commands
Expand Down Expand Up @@ -94,6 +95,7 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error {

varFile := constructTerraformComponentVarfileName(info)
planFile := constructTerraformComponentPlanfileName(info)
tfStateFolder := fmt.Sprintf("%s-%s", info.ContextPrefix, info.Component)

if info.SubCommand == "clean" {
u.LogInfo(cliConfig, "Deleting '.terraform' folder")
Expand All @@ -102,6 +104,15 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error {
u.LogWarning(cliConfig, err.Error())
}

if u.SliceContainsString(info.AdditionalArgsAndFlags, everything) {
haitham911 marked this conversation as resolved.
Show resolved Hide resolved
tfStateFolderPath := path.Join(componentPath, "terraform.tfstate.d", tfStateFolder)
u.LogInfo(cliConfig, fmt.Sprintf("Deleting 'terraform.tfstate.d/%s' folder", tfStateFolder))
err = os.RemoveAll(tfStateFolderPath)
if err != nil {
u.LogWarning(cliConfig, err.Error())
}
}
haitham911 marked this conversation as resolved.
Show resolved Hide resolved

if !u.SliceContainsString(info.AdditionalArgsAndFlags, skipTerraformLockFileFlag) {
u.LogInfo(cliConfig, "Deleting '.terraform.lock.hcl' file")
_ = os.Remove(path.Join(componentPath, ".terraform.lock.hcl"))
Expand Down