From 1acd1d0dfae264e83fd9d64e1065df1244d38673 Mon Sep 17 00:00:00 2001 From: haitham911 Date: Sun, 5 Jan 2025 00:37:17 +0200 Subject: [PATCH] remove --everything --- internal/exec/help.go | 7 ++----- internal/exec/terraform.go | 1 - internal/exec/terraform_clean.go | 9 ++++----- internal/exec/utils.go | 8 +++----- .../docs/cli/commands/terraform/terraform-clean.mdx | 7 +++---- website/docs/cli/commands/terraform/usage.mdx | 12 ++++++------ .../Screengrabs/atmos-terraform--help.html | 4 ++-- .../Screengrabs/atmos-terraform-clean--help.html | 4 ++-- 8 files changed, 22 insertions(+), 30 deletions(-) diff --git a/internal/exec/help.go b/internal/exec/help.go index 47e724037..1fe7abdc7 100644 --- a/internal/exec/help.go +++ b/internal/exec/help.go @@ -32,9 +32,8 @@ func processHelp( "the commands will use the planfile previously generated by 'atmos terraform plan' command instead of generating a new planfile") u.PrintMessage(" - 'atmos terraform apply' and 'atmos terraform deploy' commands commands support '--planfile' flag to specify the path " + "to a planfile. The '--planfile' flag should be used instead of the planfile argument in the native 'terraform apply ' command") - u.PrintMessage(" - 'atmos terraform clean' command deletes the '.terraform' folder, '.terraform.lock.hcl' lock file, " + + u.PrintMessage(" - 'atmos terraform clean' command delete the Terraform state files and directories for the component and stack., '.terraform.lock.hcl' lock file, " + "and the previously generated 'planfile', 'varfile', and 'backend.tf.json' file for the specified component and stack. " + - "Use the --everything flag to also delete the Terraform state files and directories for the component. " + "Note: State files store the local state of your infrastructure and should be handled with care, if not using a remote backend.\n\n" + "Additional flags:\n" + " --force Forcefully delete Terraform state files and directories without interaction\n" + @@ -70,16 +69,14 @@ func processHelp( "native arguments and flags for the 'helmfile' commands") } } else if componentType == "terraform" && command == "clean" { - u.PrintMessage("\n'atmos terraform clean' command deletes the following folders and files from the component's directory:\n\n" + + u.PrintMessage("\n'atmos terraform clean' command delete all the Terraform state files and directories for all components and stacks . deletes the following folders and files from the component's directory:\n\n" + " - '.terraform' folder\n" + " - folder that the 'TF_DATA_DIR' ENV var points to\n" + " - '.terraform.lock.hcl' file\n" + " - generated varfile for the component in the stack\n" + " - generated planfile for the component in the stack\n" + " - generated 'backend.tf.json' file\n" + - " - 'terraform.tfstate.d' folder (if '--everything' flag is used)\n\n" + "Usage: atmos terraform clean -s \n\n" + - "Use the `--everything` flag to remove all Terraform state files and directories, prompting you for confirmation before proceeding. This is the default behavior.\n\n" + "Use --force to forcefully delete Terraform state files and directories for the component.\n\n" + "- If no component is specified, the command will apply to all components and stacks.\n" + "- If no stack is specified, the command will apply to all stacks for the specified component.\n" + diff --git a/internal/exec/terraform.go b/internal/exec/terraform.go index 0690964f7..130baee7b 100644 --- a/internal/exec/terraform.go +++ b/internal/exec/terraform.go @@ -21,7 +21,6 @@ const ( outFlag = "-out" varFileFlag = "-var-file" skipTerraformLockFileFlag = "--skip-lock-file" - everythingFlag = "--everything" forceFlag = "--force" ) diff --git a/internal/exec/terraform_clean.go b/internal/exec/terraform_clean.go index e3b190e01..275d6b905 100644 --- a/internal/exec/terraform_clean.go +++ b/internal/exec/terraform_clean.go @@ -346,8 +346,8 @@ func handleTFDataDir(componentPath string, relativePath string, atmosConfig sche } } -func initializeFilesToClear(info schema.ConfigAndStacksInfo, atmosConfig schema.AtmosConfiguration, everything bool) []string { - if everything && info.Stack == "" { +func initializeFilesToClear(info schema.ConfigAndStacksInfo, atmosConfig schema.AtmosConfiguration) []string { + if info.ComponentFromArg == "" { return []string{".terraform", ".terraform.lock.hcl", "*.tfvar.json", "terraform.tfstate.d"} } varFile := constructTerraformComponentVarfileName(info) @@ -406,8 +406,7 @@ func handleCleanSubCommand(info schema.ConfigAndStacksInfo, componentPath string } force := u.SliceContainsString(info.AdditionalArgsAndFlags, forceFlag) - everything := u.SliceContainsString(info.AdditionalArgsAndFlags, everythingFlag) - filesToClear := initializeFilesToClear(info, atmosConfig, everything) + filesToClear := initializeFilesToClear(info, atmosConfig) folders, err := CollectDirectoryObjects(cleanPath, filesToClear) if err != nil { u.LogTrace(atmosConfig, fmt.Errorf("error collecting folders and files: %v", err).Error()) @@ -455,7 +454,7 @@ func handleCleanSubCommand(info schema.ConfigAndStacksInfo, componentPath string u.PrintMessage(fmt.Sprintf("Do you want to delete the folder '%s'? ", tfDataDir)) } var message string - if everything && info.ComponentFromArg == "" { + if info.ComponentFromArg == "" { message = fmt.Sprintf("This will delete %v local terraform state files affecting all components", total) } else if info.Component != "" && info.Stack != "" { message = fmt.Sprintf("This will delete %v local terraform state files for component '%s' in stack '%s'", total, info.Component, info.Stack) diff --git a/internal/exec/utils.go b/internal/exec/utils.go index 81a9cf518..9ea63313c 100644 --- a/internal/exec/utils.go +++ b/internal/exec/utils.go @@ -665,14 +665,12 @@ func processArgsAndFlags( var additionalArgsAndFlags []string var globalOptions []string var indexesToRemove []int - if len(inputArgsAndFlags) > 1 && inputArgsAndFlags[0] == "clean" { - if !u.SliceContainsString(inputArgsAndFlags, everythingFlag) { - inputArgsAndFlags = append(inputArgsAndFlags, everythingFlag) - } + if len(inputArgsAndFlags) == 1 && inputArgsAndFlags[0] == "clean" { + info.SubCommand = inputArgsAndFlags[0] } // For commands like `atmos terraform plan`, show the command help - if len(inputArgsAndFlags) == 1 && inputArgsAndFlags[0] != "version" { + if len(inputArgsAndFlags) == 1 && inputArgsAndFlags[0] != "version" && info.SubCommand == "" { info.SubCommand = inputArgsAndFlags[0] info.NeedHelp = true return info, nil diff --git a/website/docs/cli/commands/terraform/terraform-clean.mdx b/website/docs/cli/commands/terraform/terraform-clean.mdx index 9bd0bdb66..4834df177 100644 --- a/website/docs/cli/commands/terraform/terraform-clean.mdx +++ b/website/docs/cli/commands/terraform/terraform-clean.mdx @@ -23,7 +23,7 @@ Execute the `terraform clean` command like this: atmos terraform clean -s [--skip-lock-file] [--everything] [--force] :::warning -The `--everything` flag is the default behavior and will delete all Terraform-related files including state files, with a confirmation prompt before proceeding. The `--force` flag will bypass confirmation prompts. +The `clean` default behavior and will delete all Terraform-related files including state files, with a confirmation prompt before proceeding. The `--force` flag will bypass confirmation prompts. Use these flags with extreme caution as they can lead to irreversible data loss. ::: ``` @@ -36,10 +36,9 @@ Run `atmos terraform clean --help` to see all the available options ```shell # Delete all Terraform-related files for all components (with confirmation) -atmos terraform clean --everything - +atmos terraform clean # Force delete all Terraform-related files for all components (no confirmation) -atmos terraform clean --everything --force +atmos terraform clean --force atmos terraform clean top-level-component1 -s tenant1-ue2-dev atmos terraform clean infra/vpc -s tenant1-ue2-staging atmos terraform clean infra/vpc -s tenant1-ue2-staging --skip-lock-file diff --git a/website/docs/cli/commands/terraform/usage.mdx b/website/docs/cli/commands/terraform/usage.mdx index a9c32f7f2..3a28d2ce2 100644 --- a/website/docs/cli/commands/terraform/usage.mdx +++ b/website/docs/cli/commands/terraform/usage.mdx @@ -59,11 +59,11 @@ HCL-based domain-specific language and its interpreter. Atmos works with [OpenTo - `atmos terraform clean` command deletes the `.terraform` folder, `.terraform.lock.hcl` lock file, and the previously generated `planfile` and `varfile` for the specified component and stack. Use the `--skip-lock-file` flag to skip deleting the `.terraform.lock.hcl` file. - The `--everything` flag is the default behavior. It deletes all local Terraform state files and directories (including `terraform.tfstate.d/`) for all components and stacks. + It deletes all local Terraform state files and directories (including `terraform.tfstate.d/`) for all components and stacks. The `--force` flag bypasses the safety confirmation prompt and forces the deletion. Use with caution. :::warning - The `--everything` flag performs destructive operations that can lead to permanent state loss. Always ensure you have remote state configured in your components before proceeding. + The `clean` performs destructive operations that can lead to permanent state loss. Always ensure you have remote state configured in your components before proceeding. ::: - `atmos terraform workspace` command first runs `terraform init -reconfigure`, then `terraform workspace select`, and if the workspace was not @@ -113,16 +113,16 @@ atmos terraform destroy test/test-component-override -s tenant1-ue2-dev --redire atmos terraform init test/test-component-override-3 -s tenant1-ue2-dev # Clean all components (with confirmation) -atmos terraform clean --everything +atmos terraform clean # Clean a specific component -atmos terraform clean vpc --everything +atmos terraform clean vpc # Clean a specific component in a stack -atmos terraform clean vpc --stack dev --everything +atmos terraform clean vpc --stack dev # Clean without confirmation prompt -atmos terraform clean --everything --force +atmos terraform clean --force atmos terraform clean test/test-component-override-3 -s tenant1-ue2-dev atmos terraform workspace test/test-component-override-3 -s tenant1-ue2-dev diff --git a/website/src/components/Screengrabs/atmos-terraform--help.html b/website/src/components/Screengrabs/atmos-terraform--help.html index 5142abd4e..af2cfee27 100644 --- a/website/src/components/Screengrabs/atmos-terraform--help.html +++ b/website/src/components/Screengrabs/atmos-terraform--help.html @@ -20,8 +20,8 @@ - 'atmos terraform deploy' command supports '--deploy-run-init=true/false' flag to enable/disable running 'terraform init' before executing the command - 'atmos terraform apply' and 'atmos terraform deploy' commands support '--from-plan' flag. If the flag is specified, the commands will use the planfile previously generated by 'atmos terraform plan' command instead of generating a new planfile - 'atmos terraform apply' and 'atmos terraform deploy' commands commands support '--planfile' flag to specify the path to a planfile. The '--planfile' flag should be used instead of the planfile argument in the native 'terraform apply <planfile>' command - - 'atmos terraform clean' command deletes the '.terraform' folder, '.terraform.lock.hcl' lock file, and the previously generated 'planfile', 'varfile' and 'backend.tf.json' file for the specified component and stack. Use --skip-lock-file flag to skip deleting the lock file. - - 'atmos terraform clean' command supports '--everything' flag to delete all the Terraform state files and directories for all components and stacks . Use --force flag to skip the confirmation prompt. + - 'atmos terraform clean' command delete all the Terraform state files and directories for all components and stacks . deletes the '.terraform' folder, '.terraform.lock.hcl' lock file, and the previously generated 'planfile', 'varfile' and 'backend.tf.json' file for the specified component and stack. Use --skip-lock-file flag to skip deleting the lock file. + - 'atmos terraform clean' . Use --force flag to skip the confirmation prompt. - 'atmos terraform workspace' command first runs 'terraform init -reconfigure', then 'terraform workspace select', and if the workspace was not created before, it then runs 'terraform workspace new' - 'atmos terraform import' command searches for 'region' in the variables for the specified component and stack, and if it finds it, sets 'AWS_REGION=<region>' ENV var before executing the command - 'atmos terraform generate backend' command generates a backend config file for an 'atmos' component in a stack diff --git a/website/src/components/Screengrabs/atmos-terraform-clean--help.html b/website/src/components/Screengrabs/atmos-terraform-clean--help.html index 7d5710b43..0d664de16 100644 --- a/website/src/components/Screengrabs/atmos-terraform-clean--help.html +++ b/website/src/components/Screengrabs/atmos-terraform-clean--help.html @@ -8,7 +8,7 @@ 'atmos terraform clean' command deletes the following folders and files from the component's directory: - + - delete all the Terraform state files and directories for all components and stacks - '.terraform' folder - folder that the 'TF_DATA_DIR' ENV var points to - '.terraform.lock.hcl' file @@ -17,7 +17,7 @@ - generated 'backend.tf.json' file Usage: atmos terraform clean <component> -s <stack> <flags> -Use '--everything' flag to delete all the files and folders mentioned above. '--force' to delete the files without confirmation. +Use '--force' to delete the files without confirmation. Use '--skip-lock-file' flag to skip deleting the lock file. For more details refer to https://atmos.tools/cli/commands/terraform/clean