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

Fixes and Improvements for terraform clean #870

Merged
merged 30 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6832ddd
fix clean cmd
haitham911 Dec 19, 2024
0c90df5
feat --everything is the default behavior
haitham911 Dec 19, 2024
a2b820e
remove debug print
haitham911 Dec 19, 2024
1649cd9
Merge branch 'main' into DEV-2859
osterman Dec 19, 2024
4a9bde6
Update website/docs/cli/commands/terraform/usage.mdx
osterman Dec 26, 2024
755e5c6
Update website/docs/cli/commands/terraform/usage.mdx
osterman Dec 26, 2024
13126b2
Apply suggestions from code review
osterman Dec 26, 2024
7e2f054
Update internal/exec/help.go
osterman Dec 26, 2024
f4a81b3
Merge branch 'main' into DEV-2859
osterman Dec 26, 2024
8d1292b
Merge branch 'main' into DEV-2859
haitham911 Jan 4, 2025
1acd1d0
remove --everything
haitham911 Jan 4, 2025
338d859
add integration test for terraform apply and terraform clean
haitham911 Jan 4, 2025
6735525
chang dev with prod
haitham911 Jan 5, 2025
d9f4ff6
move TestCLITerraformClean to new file
haitham911 Jan 21, 2025
e983196
Merge branch 'main' into DEV-2859
haitham911 Jan 21, 2025
2ad7321
add clean help
haitham911 Jan 21, 2025
b87a851
improve TestCLITerraformClean
haitham911 Jan 21, 2025
e3b16d9
improve TestCLITerraformClean
haitham911 Jan 21, 2025
24f7385
improve clean test
haitham911 Jan 21, 2025
87f9bc4
add clean runCLITerraformCleanComponent
haitham911 Jan 21, 2025
d5cca32
modify docs
haitham911 Jan 21, 2025
73c6a80
improve test
haitham911 Jan 22, 2025
dfd8ada
remove clean help from help.go
haitham911 Jan 22, 2025
76d5cda
add line
haitham911 Jan 22, 2025
ed57122
Merge branch 'main' into DEV-2859
aknysh Jan 27, 2025
2cf9f38
updates
aknysh Jan 28, 2025
ff8df5f
fix clean cmd
haitham911 Jan 30, 2025
319cd71
add test for clean cmd
haitham911 Jan 30, 2025
0034639
improve test
haitham911 Jan 30, 2025
be66e0a
Merge branch 'main' into DEV-2859
aknysh Jan 30, 2025
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
2 changes: 1 addition & 1 deletion internal/exec/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <component> -s <stack> <flags>\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" +
osterman marked this conversation as resolved.
Show resolved Hide resolved
"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" +
Expand Down
7 changes: 2 additions & 5 deletions internal/exec/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != ""

}
Expand All @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion internal/exec/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,13 @@ 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)
}
}

// 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
Expand Down
2 changes: 1 addition & 1 deletion website/docs/cli/commands/terraform/terraform-clean.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Execute the `terraform clean` command like this:
atmos terraform clean <component> -s <stack> [--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.
osterman marked this conversation as resolved.
Show resolved Hide resolved
Use these flags with extreme caution as they can lead to irreversible data loss.
:::
haitham911 marked this conversation as resolved.
Show resolved Hide resolved
```
Expand Down
2 changes: 1 addition & 1 deletion website/docs/cli/commands/terraform/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
osterman marked this conversation as resolved.
Show resolved Hide resolved
Use the `--force` flag to bypass the safety confirmation prompt and force the deletion (use with caution).
osterman marked this conversation as resolved.
Show resolved Hide resolved

:::warning
Expand Down
Loading