From 6832ddd061c664ae51b6d8e43e5a7caf7b1513e7 Mon Sep 17 00:00:00 2001 From: haitham911 Date: Thu, 19 Dec 2024 04:50:48 +0200 Subject: [PATCH 1/7] fix clean cmd --- internal/exec/terraform.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/internal/exec/terraform.go b/internal/exec/terraform.go index fcf65bdb3..0690964f7 100644 --- a/internal/exec/terraform.go +++ b/internal/exec/terraform.go @@ -75,13 +75,10 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error { shouldCheckStack := true // Skip stack processing when cleaning with --everything or --force flags to allow // cleaning without requiring stack configuration - if info.SubCommand == "clean" && - (u.SliceContainsString(info.AdditionalArgsAndFlags, everythingFlag) || - u.SliceContainsString(info.AdditionalArgsAndFlags, forceFlag)) { + if info.SubCommand == "clean" { if info.ComponentFromArg == "" { shouldProcessStacks = false } - shouldCheckStack = info.Stack != "" } @@ -96,7 +93,7 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error { } } - if !info.ComponentIsEnabled { + if !info.ComponentIsEnabled && info.SubCommand != "clean" { u.LogInfo(atmosConfig, fmt.Sprintf("component '%s' is not enabled and skipped", info.ComponentFromArg)) return nil } From 0c90df55ef0c8180fbbf59aad107825b9e18ff61 Mon Sep 17 00:00:00 2001 From: haitham911 Date: Thu, 19 Dec 2024 14:37:39 +0200 Subject: [PATCH 2/7] feat --everything is the default behavior --- internal/exec/help.go | 2 +- internal/exec/utils.go | 8 +++++++- website/docs/cli/commands/terraform/terraform-clean.mdx | 2 +- website/docs/cli/commands/terraform/usage.mdx | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/exec/help.go b/internal/exec/help.go index b90c8ce64..e5c8257ef 100644 --- a/internal/exec/help.go +++ b/internal/exec/help.go @@ -79,7 +79,7 @@ func processHelp( " - 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 '--everything' flag to also delete the Terraform state files and and directories with confirm message.\n\n" + + "Use '--everything' flag —everything is the default behavior to delete the Terraform state files and and directories with confirm message.\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/utils.go b/internal/exec/utils.go index a3a7c9cc5..d052ae4e8 100644 --- a/internal/exec/utils.go +++ b/internal/exec/utils.go @@ -657,8 +657,14 @@ func processArgsAndFlags(componentType string, inputArgsAndFlags []string) (sche 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) + } + } + fmt.Println(inputArgsAndFlags) - // For commands like `atmos terraform clean` and `atmos terraform plan`, show the command help + // For commands like `atmos terraform plan`, show the command help if len(inputArgsAndFlags) == 1 && inputArgsAndFlags[0] != "version" { info.SubCommand = inputArgsAndFlags[0] info.NeedHelp = true diff --git a/website/docs/cli/commands/terraform/terraform-clean.mdx b/website/docs/cli/commands/terraform/terraform-clean.mdx index 3ddc4b341..766fea226 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 will delete all Terraform-related files including state files. The `--force` flag will bypass confirmation prompts. +The `--everything` flag is the default behavior and will delete all Terraform-related files including state files. The `--force` flag will bypass confirmation prompts. Use these flags with extreme caution as they can lead to irreversible data loss. ::: ``` diff --git a/website/docs/cli/commands/terraform/usage.mdx b/website/docs/cli/commands/terraform/usage.mdx index ce60dbee6..9054a5b16 100644 --- a/website/docs/cli/commands/terraform/usage.mdx +++ b/website/docs/cli/commands/terraform/usage.mdx @@ -59,7 +59,7 @@ 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. - Use the `--everything` flag to delete all the local Terraform state files and directories (including `terraform.tfstate.d`) for all components and stacks. + Use the `--everything` flag is the default behavior to delete all the local Terraform state files and directories (including `terraform.tfstate.d`) for all components and stacks. Use the `--force` flag to bypass the safety confirmation prompt and force the deletion (use with caution). :::warning From a2b820e59d56bdb26018bdd6b0e30d7377f2a25f Mon Sep 17 00:00:00 2001 From: haitham911 Date: Thu, 19 Dec 2024 15:54:44 +0200 Subject: [PATCH 3/7] remove debug print --- internal/exec/utils.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/exec/utils.go b/internal/exec/utils.go index d052ae4e8..3e11d9ab2 100644 --- a/internal/exec/utils.go +++ b/internal/exec/utils.go @@ -662,7 +662,6 @@ func processArgsAndFlags(componentType string, inputArgsAndFlags []string) (sche inputArgsAndFlags = append(inputArgsAndFlags, everythingFlag) } } - fmt.Println(inputArgsAndFlags) // For commands like `atmos terraform plan`, show the command help if len(inputArgsAndFlags) == 1 && inputArgsAndFlags[0] != "version" { From 4a9bde6ee3e741757d29390ab3f55506fa269449 Mon Sep 17 00:00:00 2001 From: "Erik Osterman (CEO @ Cloud Posse)" Date: Thu, 26 Dec 2024 10:46:12 -0600 Subject: [PATCH 4/7] Update website/docs/cli/commands/terraform/usage.mdx --- website/docs/cli/commands/terraform/usage.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/cli/commands/terraform/usage.mdx b/website/docs/cli/commands/terraform/usage.mdx index 9054a5b16..173165522 100644 --- a/website/docs/cli/commands/terraform/usage.mdx +++ b/website/docs/cli/commands/terraform/usage.mdx @@ -59,7 +59,7 @@ 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. - Use the `--everything` flag is the default behavior to delete all the local Terraform state files and directories (including `terraform.tfstate.d`) for all components and stacks. + 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. Use the `--force` flag to bypass the safety confirmation prompt and force the deletion (use with caution). :::warning From 755e5c670cd6368fe548b15ca9ae8eb0ad8ae6ad Mon Sep 17 00:00:00 2001 From: "Erik Osterman (CEO @ Cloud Posse)" Date: Thu, 26 Dec 2024 10:46:39 -0600 Subject: [PATCH 5/7] Update website/docs/cli/commands/terraform/usage.mdx --- website/docs/cli/commands/terraform/usage.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/cli/commands/terraform/usage.mdx b/website/docs/cli/commands/terraform/usage.mdx index 173165522..a9c32f7f2 100644 --- a/website/docs/cli/commands/terraform/usage.mdx +++ b/website/docs/cli/commands/terraform/usage.mdx @@ -60,7 +60,7 @@ 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. - Use the `--force` flag to bypass the safety confirmation prompt and force the deletion (use with caution). + 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. From 13126b280f0263e999315c47c617310d50e75341 Mon Sep 17 00:00:00 2001 From: "Erik Osterman (CEO @ Cloud Posse)" Date: Thu, 26 Dec 2024 10:47:09 -0600 Subject: [PATCH 6/7] Apply suggestions from code review --- website/docs/cli/commands/terraform/terraform-clean.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/cli/commands/terraform/terraform-clean.mdx b/website/docs/cli/commands/terraform/terraform-clean.mdx index 766fea226..9bd0bdb66 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. The `--force` flag will bypass confirmation prompts. +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. Use these flags with extreme caution as they can lead to irreversible data loss. ::: ``` From 7e2f054aa5552cf3787e0ca2a97bebeb7970fb69 Mon Sep 17 00:00:00 2001 From: "Erik Osterman (CEO @ Cloud Posse)" Date: Thu, 26 Dec 2024 10:48:38 -0600 Subject: [PATCH 7/7] Update internal/exec/help.go --- internal/exec/help.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/exec/help.go b/internal/exec/help.go index e5c8257ef..30355197e 100644 --- a/internal/exec/help.go +++ b/internal/exec/help.go @@ -79,7 +79,7 @@ func processHelp( " - 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 '--everything' flag —everything is the default behavior to delete the Terraform state files and and directories with confirm message.\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" +