Skip to content

Commit 652751b

Browse files
committed
Merge branch 'main' of https://github.com/cloudposse/atmos into feature/dev-2953-update-help-and-usageyaml-with-snapshots
2 parents c66dbfa + c76d05a commit 652751b

File tree

10 files changed

+135
-124
lines changed

10 files changed

+135
-124
lines changed

cmd/cmd_utils.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,5 +670,15 @@ func showUsageExample(cmd *cobra.Command, details string) {
670670
suggestion = exampleContent.Suggestion
671671
details += "\n## Usage Examples:\n" + exampleContent.Content
672672
}
673-
u.PrintErrorMarkdownAndExit("Incorrect Usage", errors.New(details), suggestion)
673+
u.PrintErrorMarkdownAndExit("Incorrect Usage", fmt.Errorf(details), suggestion)
674+
}
675+
676+
// Contains checks if a slice of strings contains an exact match for the target string.
677+
func Contains(slice []string, target string) bool {
678+
for _, item := range slice {
679+
if item == target {
680+
return true
681+
}
682+
}
683+
return false
674684
}

cmd/terraform.go

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ package cmd
33
import (
44
"fmt"
55

6+
l "github.com/charmbracelet/log"
67
"github.com/spf13/cobra"
78

89
e "github.com/cloudposse/atmos/internal/exec"
910
cfg "github.com/cloudposse/atmos/pkg/config"
1011
h "github.com/cloudposse/atmos/pkg/hooks"
1112
u "github.com/cloudposse/atmos/pkg/utils"
12-
13-
l "github.com/charmbracelet/log"
1413
)
1514

1615
// terraformCmd represents the base command for all terraform sub-commands
@@ -23,26 +22,12 @@ var terraformCmd = &cobra.Command{
2322
Example: terraformUsage,
2423
}
2524

26-
// Contains checks if a slice of strings contains an exact match for the target string.
27-
func Contains(slice []string, target string) bool {
28-
for _, item := range slice {
29-
if item == target {
30-
return true
31-
}
32-
}
33-
return false
34-
}
35-
36-
func terraformRun(cmd *cobra.Command, actualCmd *cobra.Command, args []string) {
37-
info := getConfigAndStacksInfo("terraform", cmd, args)
38-
if info.NeedHelp {
39-
actualCmd.Usage()
40-
return
41-
}
42-
err := e.ExecuteTerraform(info)
43-
if err != nil {
44-
u.PrintErrorMarkdownAndExit("", err, "")
45-
}
25+
func init() {
26+
// https://github.com/spf13/cobra/issues/739
27+
terraformCmd.DisableFlagParsing = true
28+
terraformCmd.PersistentFlags().StringP("stack", "s", "", "atmos terraform <terraform_command> <component> -s <stack>")
29+
attachTerraformCommands(terraformCmd)
30+
RootCmd.AddCommand(terraformCmd)
4631
}
4732

4833
func runHooks(event h.HookEvent, cmd *cobra.Command, args []string) error {
@@ -67,11 +52,17 @@ func runHooks(event h.HookEvent, cmd *cobra.Command, args []string) error {
6752
return nil
6853
}
6954

70-
func init() {
71-
// https://github.com/spf13/cobra/issues/739
72-
terraformCmd.DisableFlagParsing = true
73-
terraformCmd.PersistentFlags().StringP("stack", "s", "", "atmos terraform <terraform_command> <component> -s <stack>")
74-
terraformCmd.PersistentFlags().Bool("", false, doubleDashHint)
75-
attachTerraformCommands(terraformCmd)
76-
RootCmd.AddCommand(terraformCmd)
55+
func terraformRun(cmd *cobra.Command, actualCmd *cobra.Command, args []string) {
56+
info := getConfigAndStacksInfo("terraform", cmd, args)
57+
if info.NeedHelp {
58+
err := actualCmd.Usage()
59+
if err != nil {
60+
u.LogErrorAndExit(err)
61+
}
62+
return
63+
}
64+
err := e.ExecuteTerraform(info)
65+
if err != nil {
66+
u.PrintErrorMarkdownAndExit("", err, "")
67+
}
7768
}

examples/quick-start-advanced/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ARG GEODESIC_OS=debian
66
# https://atmos.tools/
77
# https://github.com/cloudposse/atmos
88
# https://github.com/cloudposse/atmos/releases
9-
ARG ATMOS_VERSION=1.158.0
9+
ARG ATMOS_VERSION=1.160.0
1010

1111
# Terraform: https://github.com/hashicorp/terraform/releases
1212
ARG TF_VERSION=1.5.7

go.mod

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.sum

Lines changed: 18 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/exec/go_getter_utils.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,13 @@ func ValidateURI(uri string) error {
2727
if len(uri) > 2048 {
2828
return fmt.Errorf("URI exceeds maximum length of 2048 characters")
2929
}
30-
// Add more validation as needed
3130
// Validate URI format
3231
if strings.Contains(uri, "..") {
3332
return fmt.Errorf("URI cannot contain path traversal sequences")
3433
}
3534
if strings.Contains(uri, " ") {
3635
return fmt.Errorf("URI cannot contain spaces")
3736
}
38-
// Validate characters
39-
if strings.ContainsAny(uri, "<>|&;$") {
40-
return fmt.Errorf("URI contains invalid characters")
41-
}
4237
// Validate scheme-specific format
4338
if strings.HasPrefix(uri, "oci://") {
4439
if !strings.Contains(uri[6:], "/") {

internal/exec/terraform.go

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -32,62 +32,6 @@ func ExecuteTerraformCmd(cmd *cobra.Command, args []string, additionalArgsAndFla
3232
return ExecuteTerraform(info)
3333
}
3434

35-
func shouldProcessStacks(info *schema.ConfigAndStacksInfo) (bool, bool) {
36-
shouldProcessStacks := true
37-
shouldCheckStack := true
38-
39-
if info.SubCommand == "clean" {
40-
if info.ComponentFromArg == "" {
41-
shouldProcessStacks = false
42-
}
43-
shouldCheckStack = info.Stack != ""
44-
45-
}
46-
47-
return shouldProcessStacks, shouldCheckStack
48-
}
49-
50-
func generateBackendConfig(atmosConfig *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo, workingDir string) error {
51-
// Auto-generate backend file
52-
if atmosConfig.Components.Terraform.AutoGenerateBackendFile {
53-
backendFileName := filepath.Join(workingDir, "backend.tf.json")
54-
55-
u.LogDebug("\nWriting the backend config to file:")
56-
u.LogDebug(backendFileName)
57-
58-
if !info.DryRun {
59-
componentBackendConfig, err := generateComponentBackendConfig(info.ComponentBackendType, info.ComponentBackendSection, info.TerraformWorkspace)
60-
if err != nil {
61-
return err
62-
}
63-
64-
err = u.WriteToFileAsJSON(backendFileName, componentBackendConfig, 0o644)
65-
if err != nil {
66-
return err
67-
}
68-
}
69-
}
70-
71-
return nil
72-
}
73-
74-
func generateProviderOverrides(atmosConfig *schema.AtmosConfiguration, info *schema.ConfigAndStacksInfo, workingDir string) error {
75-
// Generate `providers_override.tf.json` file if the `providers` section is configured
76-
if len(info.ComponentProvidersSection) > 0 {
77-
providerOverrideFileName := filepath.Join(workingDir, "providers_override.tf.json")
78-
79-
u.LogDebug("\nWriting the provider overrides to file:")
80-
u.LogDebug(providerOverrideFileName)
81-
82-
if !info.DryRun {
83-
providerOverrides := generateComponentProviderOverrides(info.ComponentProvidersSection)
84-
err := u.WriteToFileAsJSON(providerOverrideFileName, providerOverrides, 0o644)
85-
return err
86-
}
87-
}
88-
return nil
89-
}
90-
9135
// ExecuteTerraform executes terraform commands
9236
func ExecuteTerraform(info schema.ConfigAndStacksInfo) error {
9337
atmosConfig, err := cfg.InitCliConfig(info, true)
@@ -109,18 +53,18 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error {
10953
info.RedirectStdErr)
11054
}
11155

112-
// Skip stack processing when cleaning with --everything or --force flags to allow cleaning without requiring stack
113-
// configuration
56+
// Skip stack processing when cleaning with --force flag to allow cleaning without requiring stack configuration
11457
shouldProcessStacks, shouldCheckStack := shouldProcessStacks(&info)
11558

11659
if shouldProcessStacks {
117-
info, err = ProcessStacks(atmosConfig, info, shouldCheckStack, true, true, nil)
60+
processTemplatesAndYamlFunctions := needProcessTemplatesAndYamlFunctions(info.SubCommand)
61+
info, err = ProcessStacks(atmosConfig, info, shouldCheckStack, processTemplatesAndYamlFunctions, processTemplatesAndYamlFunctions, nil)
11862
if err != nil {
11963
return err
12064
}
12165

12266
if len(info.Stack) < 1 && shouldCheckStack {
123-
return errors.New("stack must be specified when not using --everything or --force flags")
67+
return errors.New("stack must be specified for the terraform command")
12468
}
12569
}
12670

0 commit comments

Comments
 (0)