Skip to content

Commit

Permalink
Merge branch 'DEV-2778-version' of github.com:cloudposse/atmos into D…
Browse files Browse the repository at this point in the history
…EV-2778-version
  • Loading branch information
Listener430 committed Jan 7, 2025
2 parents 5953c6b + 3a5147f commit 48baf08
Show file tree
Hide file tree
Showing 213 changed files with 920 additions and 123 deletions.
42 changes: 21 additions & 21 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -298,25 +298,25 @@ jobs:
- { os: windows-latest, target: windows }
- { os: macos-latest, target: macos }
demo-folder:
- demo-atlantis
# - demo-component-manifest
- demo-component-versions
- demo-context
# - demo-custom-command
# - demo-json-validation
# - demo-opa-validation
# - demo-opentofu
# - demo-project
# - demo-stacks
# - demo-terraform
# - demo-terraform-overrides
# - demo-workflows
# - demo-yaml-anchors
# - demo-mock-architecture
# - demo-stack-templating
# - demo-multi-cloud
- demo-vendoring
- tests
- examples/demo-atlantis
# - examples/demo-component-manifest
- examples/demo-component-versions
- examples/demo-context
# - examples/demo-custom-command
# - examples/demo-json-validation
# - examples/demo-opa-validation
# - examples/demo-opentofu
# - examples/demo-project
# - examples/demo-stacks
# - examples/demo-terraform
# - examples/demo-terraform-overrides
# - examples/demo-workflows
# - examples/demo-yaml-anchors
# - examples/demo-mock-architecture
# - examples/demo-stack-templating
# - examples/demo-multi-cloud
- examples/demo-vendoring
- tests/fixtures/scenarios/complete

timeout-minutes: 20
steps:
Expand Down Expand Up @@ -350,7 +350,7 @@ jobs:
terraform_wrapper: false

- name: Run tests in ${{ matrix.demo-folder }} for ${{ matrix.flavor.target }}
working-directory: examples/${{ matrix.demo-folder }}
working-directory: ${{ matrix.demo-folder }}
if: matrix.flavor.target == 'linux' || matrix.flavor.target == 'macos'
run: |
atmos test
Expand All @@ -366,7 +366,7 @@ jobs:
atmos version
- name: Run tests in ${{ matrix.demo-folder }} for ${{ matrix.flavor.target }}
working-directory: examples/${{ matrix.demo-folder }}
working-directory: ${{ matrix.demo-folder }}
if: matrix.flavor.target == 'windows'
shell: pwsh
run: |
Expand Down
48 changes: 45 additions & 3 deletions internal/exec/shell_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,30 @@ import (
u "github.com/cloudposse/atmos/pkg/utils"
)

// MaxShellDepth is the maximum number of nested shell commands that can be executed
const MaxShellDepth = 10

// getNextShellLevel increments the ATMOS_SHLVL and returns the new value or an error if maximum depth is exceeded
func getNextShellLevel() (int, error) {
atmosShellLvl := os.Getenv("ATMOS_SHLVL")
shellVal := 0
if atmosShellLvl != "" {
val, err := strconv.Atoi(atmosShellLvl)
if err != nil {
return 0, fmt.Errorf("invalid ATMOS_SHLVL value: %s", atmosShellLvl)
}
shellVal = val
}

shellVal++

if shellVal > MaxShellDepth {
return 0, fmt.Errorf("ATMOS_SHLVL (%d) exceeds maximum allowed depth (%d). Infinite recursion?",
shellVal, MaxShellDepth)
}
return shellVal, nil
}

// ExecuteShellCommand prints and executes the provided command with args and flags
func ExecuteShellCommand(
atmosConfig schema.AtmosConfiguration,
Expand All @@ -31,8 +55,14 @@ func ExecuteShellCommand(
dryRun bool,
redirectStdError string,
) error {
newShellLevel, err := getNextShellLevel()
if err != nil {
return err
}
updatedEnv := append(env, fmt.Sprintf("ATMOS_SHLVL=%d", newShellLevel))

cmd := exec.Command(command, args...)
cmd.Env = append(os.Environ(), env...)
cmd.Env = append(os.Environ(), updatedEnv...)
cmd.Dir = dir
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
Expand Down Expand Up @@ -83,14 +113,20 @@ func ExecuteShell(
env []string,
dryRun bool,
) error {
newShellLevel, err := getNextShellLevel()
if err != nil {
return err
}
updatedEnv := append(env, fmt.Sprintf("ATMOS_SHLVL=%d", newShellLevel))

u.LogDebug(atmosConfig, "\nExecuting command:")
u.LogDebug(atmosConfig, command)

if dryRun {
return nil
}

return shellRunner(command, name, dir, env, os.Stdout)
return shellRunner(command, name, dir, updatedEnv, os.Stdout)
}

// ExecuteShellAndReturnOutput runs a shell script and capture its standard output
Expand All @@ -104,14 +140,20 @@ func ExecuteShellAndReturnOutput(
) (string, error) {
var b bytes.Buffer

newShellLevel, err := getNextShellLevel()
if err != nil {
return "", err
}
updatedEnv := append(env, fmt.Sprintf("ATMOS_SHLVL=%d", newShellLevel))

u.LogDebug(atmosConfig, "\nExecuting command:")
u.LogDebug(atmosConfig, command)

if dryRun {
return "", nil
}

err := shellRunner(command, name, dir, env, &b)
err = shellRunner(command, name, dir, updatedEnv, &b)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/atlantis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ projects:
- name: tenant1-ue2-staging-test-test-component-override-3
workspace: test-component-override-3-workspace
workflow: workflow-1
dir: examples/tests/components/terraform/test/test-component
dir: tests/fixtures/scenarios/complete/components/terraform/test/test-component
terraform_version: v1.2
delete_source_branch_on_merge: true
autoplan:
Expand All @@ -135,7 +135,7 @@ projects:
- name: tenant1-ue2-staging-infra-vpc
workspace: tenant1-ue2-staging
workflow: workflow-1
dir: examples/tests/components/terraform/infra/vpc
dir: tests/fixtures/scenarios/complete/components/terraform/infra/vpc
terraform_version: v1.2
delete_source_branch_on_merge: true
autoplan:
Expand Down
2 changes: 1 addition & 1 deletion pkg/atlantis/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# are independent settings (supporting both absolute and relative paths).
# If 'base_path' is provided, 'components.terraform.base_path', 'components.helmfile.base_path', 'stacks.base_path' and 'workflows.base_path'
# are considered paths relative to 'base_path'.
base_path: "../../examples/tests"
base_path: "../../tests/fixtures/scenarios/complete"

components:
terraform:
Expand Down
2 changes: 1 addition & 1 deletion pkg/aws/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# are independent settings (supporting both absolute and relative paths).
# If 'base_path' is provided, 'components.terraform.base_path', 'components.helmfile.base_path', 'stacks.base_path' and 'workflows.base_path'
# are considered paths relative to 'base_path'.
base_path: "../../examples/tests"
base_path: "../../tests/fixtures/scenarios/complete"

components:
terraform:
Expand Down
2 changes: 1 addition & 1 deletion pkg/component/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# are independent settings (supporting both absolute and relative paths).
# If 'base_path' is provided, 'components.terraform.base_path', 'components.helmfile.base_path', 'stacks.base_path' and 'workflows.base_path'
# are considered paths relative to 'base_path'.
base_path: "../../examples/tests"
base_path: "../../tests/fixtures/scenarios/complete"

components:
terraform:
Expand Down
2 changes: 1 addition & 1 deletion pkg/describe/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# are independent settings (supporting both absolute and relative paths).
# If 'base_path' is provided, 'components.terraform.base_path', 'components.helmfile.base_path', 'stacks.base_path' and 'workflows.base_path'
# are considered paths relative to 'base_path'.
base_path: "../../examples/tests"
base_path: "../../tests/fixtures/scenarios/complete"

components:
terraform:
Expand Down
8 changes: 4 additions & 4 deletions pkg/describe/describe_affected_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func TestDescribeAffectedWithTargetRefClone(t *testing.T) {
atmosConfig, err := cfg.InitCliConfig(configAndStacksInfo, true)
assert.Nil(t, err)

// We are using `atmos.yaml` from this dir. This `atmos.yaml` has set base_path: "../../examples/tests",
// We are using `atmos.yaml` from this dir. This `atmos.yaml` has set base_path: "../../tests/fixtures/scenarios/complete",
// which will be wrong for the remote repo which is cloned into a temp dir.
// Set the correct base path for the cloned remote repo
atmosConfig.BasePath = "./examples/tests"
atmosConfig.BasePath = "./tests/fixtures/scenarios/complete"

// Git reference and commit SHA
// Refer to https://git-scm.com/book/en/v2/Git-Internals-Git-References for more details
Expand Down Expand Up @@ -53,10 +53,10 @@ func TestDescribeAffectedWithTargetRepoPath(t *testing.T) {
atmosConfig, err := cfg.InitCliConfig(configAndStacksInfo, true)
assert.Nil(t, err)

// We are using `atmos.yaml` from this dir. This `atmos.yaml` has set base_path: "../../examples/tests",
// We are using `atmos.yaml` from this dir. This `atmos.yaml` has set base_path: "../../tests/fixtures/scenarios/complete",
// which will be wrong for the remote repo which is cloned into a temp dir.
// Set the correct base path for the cloned remote repo
atmosConfig.BasePath = "./examples/tests"
atmosConfig.BasePath = "./tests/fixtures/scenarios/complete"

// Point to the same local repository
// This will compare this local repository with itself as the remote target, which should result in an empty `affected` list
Expand Down
2 changes: 1 addition & 1 deletion pkg/generate/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# are independent settings (supporting both absolute and relative paths).
# If 'base_path' is provided, 'components.terraform.base_path', 'components.helmfile.base_path', 'stacks.base_path' and 'workflows.base_path'
# are considered paths relative to 'base_path'.
base_path: "../../examples/tests"
base_path: "../../tests/fixtures/scenarios/complete"

components:
terraform:
Expand Down
2 changes: 1 addition & 1 deletion pkg/list/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# are independent settings (supporting both absolute and relative paths).
# If 'base_path' is provided, 'components.terraform.base_path', 'components.helmfile.base_path', 'stacks.base_path' and 'workflows.base_path'
# are considered paths relative to 'base_path'.
base_path: "../../examples/tests"
base_path: "../../tests/fixtures/scenarios/complete"

components:
terraform:
Expand Down
2 changes: 1 addition & 1 deletion pkg/spacelift/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# are independent settings (supporting both absolute and relative paths).
# If 'base_path' is provided, 'components.terraform.base_path', 'components.helmfile.base_path', 'stacks.base_path' and 'workflows.base_path'
# are considered paths relative to 'base_path'.
base_path: "../../examples/tests"
base_path: "../../tests/fixtures/scenarios/complete"

components:
terraform:
Expand Down
20 changes: 10 additions & 10 deletions pkg/spacelift/spacelift_stack_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ func TestSpaceliftStackProcessor(t *testing.T) {
}

func TestLegacySpaceliftStackProcessor(t *testing.T) {
stacksBasePath := "../../examples/tests/stacks"
terraformComponentsBasePath := "../../examples/tests/components/terraform"
helmfileComponentsBasePath := "../../examples/tests/components/helmfile"
stacksBasePath := "../../tests/fixtures/scenarios/complete/stacks"
terraformComponentsBasePath := "../../tests/fixtures/scenarios/complete/components/terraform"
helmfileComponentsBasePath := "../../tests/fixtures/scenarios/complete/components/helmfile"

filePaths := []string{
"../../examples/tests/stacks/orgs/cp/tenant1/dev/us-east-2.yaml",
"../../examples/tests/stacks/orgs/cp/tenant1/prod/us-east-2.yaml",
"../../examples/tests/stacks/orgs/cp/tenant1/staging/us-east-2.yaml",
"../../examples/tests/stacks/orgs/cp/tenant1/test1/us-east-2.yaml",
"../../examples/tests/stacks/orgs/cp/tenant2/dev/us-east-2.yaml",
"../../examples/tests/stacks/orgs/cp/tenant2/prod/us-east-2.yaml",
"../../examples/tests/stacks/orgs/cp/tenant2/staging/us-east-2.yaml",
"../../tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/dev/us-east-2.yaml",
"../../tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/prod/us-east-2.yaml",
"../../tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/staging/us-east-2.yaml",
"../../tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/test1/us-east-2.yaml",
"../../tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant2/dev/us-east-2.yaml",
"../../tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant2/prod/us-east-2.yaml",
"../../tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant2/staging/us-east-2.yaml",
}

processStackDeps := true
Expand Down
14 changes: 7 additions & 7 deletions pkg/stack/stack_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (
)

func TestStackProcessor(t *testing.T) {
stacksBasePath := "../../examples/tests/stacks"
terraformComponentsBasePath := "../../examples/tests/components/terraform"
helmfileComponentsBasePath := "../../examples/tests/components/helmfile"
stacksBasePath := "../../tests/fixtures/scenarios/complete/stacks"
terraformComponentsBasePath := "../../tests/fixtures/scenarios/complete/components/terraform"
helmfileComponentsBasePath := "../../tests/fixtures/scenarios/complete/components/helmfile"

filePaths := []string{
"../../examples/tests/stacks/orgs/cp/tenant1/dev/us-east-2.yaml",
"../../examples/tests/stacks/orgs/cp/tenant1/prod/us-east-2.yaml",
"../../examples/tests/stacks/orgs/cp/tenant1/staging/us-east-2.yaml",
"../../examples/tests/stacks/orgs/cp/tenant1/test1/us-east-2.yaml",
"../../tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/dev/us-east-2.yaml",
"../../tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/prod/us-east-2.yaml",
"../../tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/staging/us-east-2.yaml",
"../../tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/test1/us-east-2.yaml",
}

processStackDeps := true
Expand Down
2 changes: 1 addition & 1 deletion pkg/validate/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# are independent settings (supporting both absolute and relative paths).
# If 'base_path' is provided, 'components.terraform.base_path', 'components.helmfile.base_path', 'stacks.base_path' and 'workflows.base_path'
# are considered paths relative to 'base_path'.
base_path: "../../examples/tests"
base_path: "../../tests/fixtures/scenarios/complete"

components:
terraform:
Expand Down
2 changes: 1 addition & 1 deletion pkg/vender/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# are independent settings (supporting both absolute and relative paths).
# If 'base_path' is provided, 'components.terraform.base_path', 'components.helmfile.base_path', 'stacks.base_path' and 'workflows.base_path'
# are considered paths relative to 'base_path'.
base_path: "../../examples/tests"
base_path: "../../tests/fixtures/scenarios/complete"

components:
terraform:
Expand Down
2 changes: 1 addition & 1 deletion pkg/workflow/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# are independent settings (supporting both absolute and relative paths).
# If 'base_path' is provided, 'components.terraform.base_path', 'components.helmfile.base_path', 'stacks.base_path' and 'workflows.base_path'
# are considered paths relative to 'base_path'.
base_path: "../../examples/tests"
base_path: "../../tests/fixtures/scenarios/complete"

components:
terraform:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ commands:
steps:
- atmos vendor pull

# test for infinite loop
- name: loop
description: This command tests circuit breaker for infinite loop
steps:
- "echo Hello world!"
- atmos loop

- name: tf
description: Execute 'terraform' commands
# subcommands
Expand Down Expand Up @@ -343,7 +350,7 @@ schemas:
atmos:
# Can also be set using 'ATMOS_SCHEMAS_ATMOS_MANIFEST' ENV var, or '--schemas-atmos-manifest' command-line argument
# Supports both absolute and relative paths (relative to the `base_path` setting in `atmos.yaml`)
manifest: "../quick-start-advanced/stacks/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json"
manifest: "../../schemas/atmos/atmos-manifest/1.0/atmos-manifest.json"

# CLI command aliases
aliases:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# > atmos vendor pull -c infra/vpc-flow-logs-bucket
# Pulling sources for the component 'infra/vpc-flow-logs-bucket' from 'github.com/cloudposse/terraform-aws-components.git//modules/vpc-flow-logs-bucket?ref=0.194.0'
# into 'examples/tests/components/terraform/infra/vpc-flow-logs-bucket'
# into 'tests/fixtures/scenarios/complete/components/terraform/infra/vpc-flow-logs-bucket'
#
# Including the file 'README.md' since it matches the '**/*.md' pattern from 'included_paths'
# Excluding the file 'context.tf' since it matches the '**/context.tf' pattern from 'excluded_paths'
Expand All @@ -17,9 +17,9 @@
# Including the file 'versions.tf' since it matches the '**/*.tf' pattern from 'included_paths'
#
# Pulling the mixin 'https://raw.githubusercontent.com/cloudposse/terraform-null-label/0.25.0/exports/context.tf'
# for the component 'infra/vpc-flow-logs-bucket' into 'examples/tests/components/terraform/infra/vpc-flow-logs-bucket'
# for the component 'infra/vpc-flow-logs-bucket' into 'tests/fixtures/scenarios/complete/components/terraform/infra/vpc-flow-logs-bucket'
# Pulling the mixin 'https://raw.githubusercontent.com/cloudposse/terraform-aws-components/0.194.0/modules/datadog-agent/introspection.mixin.tf'
# for the component 'infra/vpc-flow-logs-bucket' into 'examples/tests/components/terraform/infra/vpc-flow-logs-bucket'
# for the component 'infra/vpc-flow-logs-bucket' into 'tests/fixtures/scenarios/complete/components/terraform/infra/vpc-flow-logs-bucket'

apiVersion: atmos/v1
kind: ComponentVendorConfig
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ components:
workspace_enabled: false
depends_on:
1:
file: "examples/tests/components/terraform/mixins/introspection.mixin.tf"
file: "tests/fixtures/scenarios/complete/components/terraform/mixins/introspection.mixin.tf"
2:
folder: "examples/tests/components/helmfile/infra/infra-server"
folder: "tests/fixtures/scenarios/complete/components/helmfile/infra/infra-server"
vars:
enabled: true
File renamed without changes.
Loading

0 comments on commit 48baf08

Please sign in to comment.