From 427bee76cc7bcbf2a040dd9abaef067d877db66e Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Tue, 4 Feb 2025 13:55:50 +0000 Subject: [PATCH 01/22] test: refactor terraform CLI tests with mock component --- tests/cli_terraform_test.go | 65 ++++++++++++++----- .../scenarios/mock-terraform/atmos.yaml | 22 +++++++ .../components/terraform/mock/backend.tf | 5 ++ .../components/terraform/mock/main.tf | 35 ++++++++++ .../components/terraform/mock/mock.json | 1 + .../components/terraform/mock/versions.tf | 9 +++ .../mock-terraform/stacks/catalog/mock.yaml | 17 +++++ .../mock-terraform/stacks/deploy/dev.yaml | 19 ++++++ .../mock-terraform/stacks/deploy/prod.yaml | 19 ++++++ 9 files changed, 174 insertions(+), 18 deletions(-) create mode 100644 tests/fixtures/scenarios/mock-terraform/atmos.yaml create mode 100644 tests/fixtures/scenarios/mock-terraform/components/terraform/mock/backend.tf create mode 100644 tests/fixtures/scenarios/mock-terraform/components/terraform/mock/main.tf create mode 100755 tests/fixtures/scenarios/mock-terraform/components/terraform/mock/mock.json create mode 100644 tests/fixtures/scenarios/mock-terraform/components/terraform/mock/versions.tf create mode 100644 tests/fixtures/scenarios/mock-terraform/stacks/catalog/mock.yaml create mode 100644 tests/fixtures/scenarios/mock-terraform/stacks/deploy/dev.yaml create mode 100644 tests/fixtures/scenarios/mock-terraform/stacks/deploy/prod.yaml diff --git a/tests/cli_terraform_test.go b/tests/cli_terraform_test.go index 53a63d0b0..22e92731d 100644 --- a/tests/cli_terraform_test.go +++ b/tests/cli_terraform_test.go @@ -33,7 +33,7 @@ func TestCLITerraformClean(t *testing.T) { }() // Define the work directory and change to it - workDir := "../examples/quick-start-simple" + workDir := "fixtures/scenarios/mock-terraform" if err := os.Chdir(workDir); err != nil { t.Fatalf("Failed to change directory to %q: %v", workDir, err) } @@ -44,29 +44,29 @@ func TestCLITerraformClean(t *testing.T) { t.Fatalf("Binary not found: %s. Current PATH: %s", "atmos", pathManager.GetPath()) } - // Force clean everything - runTerraformCleanCommand(t, binaryPath, "--force") - // Clean everything - runTerraformCleanCommand(t, binaryPath) - // Clean specific component - runTerraformCleanCommand(t, binaryPath, "station") - // Clean component with stack - runTerraformCleanCommand(t, binaryPath, "station", "-s", "dev") + // Initialize terraform for both environments + runTerraformInit(t, binaryPath, "prod") + runTerraformInit(t, binaryPath, "dev") // Run terraform apply for prod environment runTerraformApply(t, binaryPath, "prod") - verifyStateFilesExist(t, []string{"./components/terraform/weather/terraform.tfstate.d/prod-station"}) + verifyStateFilesExist(t, []string{ + "./components/terraform/mock/.terraform", + "./components/terraform/mock/.terraform.lock.hcl", + }) runCLITerraformCleanComponent(t, binaryPath, "prod") - verifyStateFilesDeleted(t, []string{"./components/terraform/weather/terraform.tfstate.d/prod-station"}) + verifyStateFilesDeleted(t, []string{ + "./components/terraform/mock/.terraform", + "./components/terraform/mock/.terraform.lock.hcl", + }) // Run terraform apply for dev environment runTerraformApply(t, binaryPath, "dev") // Verify if state files exist before cleaning stateFiles := []string{ - "./components/terraform/weather/.terraform", - "./components/terraform/weather/terraform.tfstate.d", - "./components/terraform/weather/.terraform.lock.hcl", + "./components/terraform/mock/.terraform", + "./components/terraform/mock/.terraform.lock.hcl", } verifyStateFilesExist(t, stateFiles) @@ -75,12 +75,11 @@ func TestCLITerraformClean(t *testing.T) { // Verify if state files have been deleted after clean verifyStateFilesDeleted(t, stateFiles) - } // runTerraformApply runs the terraform apply command for a given environment. func runTerraformApply(t *testing.T, binaryPath, environment string) { - cmd := exec.Command(binaryPath, "terraform", "apply", "station", "-s", environment) + cmd := exec.Command(binaryPath, "terraform", "apply", "mock", "-s", environment) envVars := os.Environ() envVars = append(envVars, "ATMOS_COMPONENTS_TERRAFORM_APPLY_AUTO_APPROVE=true") cmd.Env = envVars @@ -91,7 +90,7 @@ func runTerraformApply(t *testing.T, binaryPath, environment string) { err := cmd.Run() t.Log(stdout.String()) if err != nil { - t.Fatalf("Failed to run terraform apply station -s %s: %v", environment, stderr.String()) + t.Fatalf("Failed to run terraform apply mock -s %s: %v", environment, stderr.String()) } } @@ -138,7 +137,7 @@ func verifyStateFilesDeleted(t *testing.T, stateFiles []string) { } func runCLITerraformCleanComponent(t *testing.T, binaryPath, environment string) { - cmd := exec.Command(binaryPath, "terraform", "clean", "station", "-s", environment, "--force") + cmd := exec.Command(binaryPath, "terraform", "clean", "mock", "-s", environment, "--force") var stdout, stderr bytes.Buffer cmd.Stdout = &stdout cmd.Stderr = &stderr @@ -148,6 +147,7 @@ func runCLITerraformCleanComponent(t *testing.T, binaryPath, environment string) t.Fatalf("Failed to run terraform clean: %v", stderr.String()) } } + func runCLITerraformClean(t *testing.T, binaryPath string) { cmd := exec.Command(binaryPath, "terraform", "clean") var stdout, stderr bytes.Buffer @@ -158,7 +158,36 @@ func runCLITerraformClean(t *testing.T, binaryPath string) { if err != nil { t.Fatalf("Failed to run terraform clean: %v", stderr.String()) } +} + +// runTerraformInit initializes terraform for a given environment +func runTerraformInit(t *testing.T, binaryPath, environment string) { + cmd := exec.Command(binaryPath, "terraform", "init", "mock", "-s", environment) + // Set environment variables + envVars := os.Environ() + envVars = append(envVars, + "ATMOS_COMPONENTS_TERRAFORM_INIT_RUN_RECONFIGURE=true", + "ATMOS_COMPONENTS_TERRAFORM_DEPLOY_RUN_INIT=true", + "ATMOS_LOGS_LEVEL=Debug", + "ATMOS_LOGS_FILE=/dev/stderr") + cmd.Env = envVars + + var stdout, stderr bytes.Buffer + cmd.Stdout = &stdout + cmd.Stderr = &stderr + + // Log the command being executed + t.Logf("Running command: %s %v", binaryPath, cmd.Args) + + err := cmd.Run() + // Always log both stdout and stderr + t.Logf("Init command stdout:\n%s", stdout.String()) + t.Logf("Init command stderr:\n%s", stderr.String()) + if err != nil { + t.Fatalf("Failed to run terraform init mock -s %s: %v\nStdout: %s\nStderr: %s", + environment, err, stdout.String(), stderr.String()) + } } func runTerraformCleanCommand(t *testing.T, binaryPath string, args ...string) { diff --git a/tests/fixtures/scenarios/mock-terraform/atmos.yaml b/tests/fixtures/scenarios/mock-terraform/atmos.yaml new file mode 100644 index 000000000..259dc1056 --- /dev/null +++ b/tests/fixtures/scenarios/mock-terraform/atmos.yaml @@ -0,0 +1,22 @@ +components: + terraform: + base_path: components/terraform + apply: + auto_approve: true + clean: + auto_approve: true + deploy_run_init: true + init_run_reconfigure: true + command: terraform + +stacks: + base_path: stacks + included_paths: + - "**/*" + excluded_paths: + - "**/templates/**/*" + name_pattern: "{environment}-{component}" + +terraform: + version_constraint: ">= 1.0" + download_url: "https://releases.hashicorp.com/terraform" diff --git a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/backend.tf b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/backend.tf new file mode 100644 index 000000000..ba96c695b --- /dev/null +++ b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/backend.tf @@ -0,0 +1,5 @@ +terraform { + backend "local" { + workspace_dir = "terraform.tfstate.d" + } +} diff --git a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/main.tf b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/main.tf new file mode 100644 index 000000000..35d0bc935 --- /dev/null +++ b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/main.tf @@ -0,0 +1,35 @@ +variable "foo" { + type = string + default = "foo" +} + +variable "bar" { + type = string + default = "bar" +} + +variable "baz" { + type = string + default = "baz" +} + +resource "local_file" "mock" { + content = jsonencode({ + foo = var.foo + bar = var.bar + baz = var.baz + }) + filename = "${path.module}/mock.json" +} + +output "foo" { + value = var.foo +} + +output "bar" { + value = var.bar +} + +output "baz" { + value = var.baz +} diff --git a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/mock.json b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/mock.json new file mode 100755 index 000000000..2ae9db6ae --- /dev/null +++ b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/mock.json @@ -0,0 +1 @@ +{"bar":"dev-bar","baz":"dev-baz","foo":"dev-foo"} \ No newline at end of file diff --git a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/versions.tf b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/versions.tf new file mode 100644 index 000000000..da53755d4 --- /dev/null +++ b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.0.0" + required_providers { + local = { + source = "hashicorp/local" + version = ">= 2.0" + } + } +} diff --git a/tests/fixtures/scenarios/mock-terraform/stacks/catalog/mock.yaml b/tests/fixtures/scenarios/mock-terraform/stacks/catalog/mock.yaml new file mode 100644 index 000000000..739272ba3 --- /dev/null +++ b/tests/fixtures/scenarios/mock-terraform/stacks/catalog/mock.yaml @@ -0,0 +1,17 @@ +# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json + +components: + terraform: + mock: + metadata: + type: terraform + component: mock + backend: + type: local + workspace_dir: terraform.tfstate.d + settings: + component: mock + vars: + foo: "test-foo" + bar: "test-bar" + baz: "test-baz" diff --git a/tests/fixtures/scenarios/mock-terraform/stacks/deploy/dev.yaml b/tests/fixtures/scenarios/mock-terraform/stacks/deploy/dev.yaml new file mode 100644 index 000000000..b82f7ba46 --- /dev/null +++ b/tests/fixtures/scenarios/mock-terraform/stacks/deploy/dev.yaml @@ -0,0 +1,19 @@ +import: + - catalog/mock + +vars: + environment: dev + component: mock + +components: + terraform: + mock: + metadata: + component: mock + environment: dev + settings: + component: mock + vars: + foo: "dev-foo" + bar: "dev-bar" + baz: "dev-baz" diff --git a/tests/fixtures/scenarios/mock-terraform/stacks/deploy/prod.yaml b/tests/fixtures/scenarios/mock-terraform/stacks/deploy/prod.yaml new file mode 100644 index 000000000..d4549de8b --- /dev/null +++ b/tests/fixtures/scenarios/mock-terraform/stacks/deploy/prod.yaml @@ -0,0 +1,19 @@ +import: + - catalog/mock + +vars: + environment: prod + component: mock + +components: + terraform: + mock: + metadata: + component: mock + environment: prod + settings: + component: mock + vars: + foo: "prod-foo" + bar: "prod-bar" + baz: "prod-baz" From c05cfea1b8125041c088e3279bf5910e73cd28ec Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Wed, 5 Feb 2025 12:26:43 +0000 Subject: [PATCH 02/22] Add test fixtures for atmos configuration files --- tests/fixtures/atmos.yaml | 34 +++++++++++++++++++ .../scenarios/mock-terraform/atmos.yaml | 14 ++++---- 2 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 tests/fixtures/atmos.yaml diff --git a/tests/fixtures/atmos.yaml b/tests/fixtures/atmos.yaml new file mode 100644 index 000000000..4fa0ed4cd --- /dev/null +++ b/tests/fixtures/atmos.yaml @@ -0,0 +1,34 @@ +base_path: "./" + +components: + terraform: + # Set base path to the shared components directory + base_path: "components/terraform" + # Enable vendoring for component reuse + vendor: + enabled: true + source_path: "components/terraform" + target_path: "vendor/components/terraform" + apply_auto_approve: false + deploy_run_init: true + init_run_reconfigure: true + auto_generate_backend_file: false + command: terraform + +stacks: + base_path: "scenarios" + included_paths: + - "**/*" + excluded_paths: + - "**/templates/**/*" + - "**/_defaults.yaml" + name_pattern: "{environment}-{component}" + +terraform: + version_constraint: ">= 1.0" + download_url: "https://releases.hashicorp.com/terraform" + +logs: + file: "/dev/stderr" + level: "Info" + color: true \ No newline at end of file diff --git a/tests/fixtures/scenarios/mock-terraform/atmos.yaml b/tests/fixtures/scenarios/mock-terraform/atmos.yaml index 259dc1056..96fab075f 100644 --- a/tests/fixtures/scenarios/mock-terraform/atmos.yaml +++ b/tests/fixtures/scenarios/mock-terraform/atmos.yaml @@ -1,6 +1,9 @@ +inherits: + - ../../atmos.yaml + components: terraform: - base_path: components/terraform + base_path: "components/terraform" apply: auto_approve: true clean: @@ -10,13 +13,12 @@ components: command: terraform stacks: - base_path: stacks + base_path: "stacks" included_paths: - "**/*" excluded_paths: - "**/templates/**/*" - name_pattern: "{environment}-{component}" -terraform: - version_constraint: ">= 1.0" - download_url: "https://releases.hashicorp.com/terraform" +logs: + file: "/dev/stderr" + level: "Info" From aee2abda9100240d1a847b204e78c0093c90ad3f Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Wed, 5 Feb 2025 12:36:59 +0000 Subject: [PATCH 03/22] Add test fixtures documentation and directory structure --- tests/fixtures/README.md | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/fixtures/README.md diff --git a/tests/fixtures/README.md b/tests/fixtures/README.md new file mode 100644 index 000000000..e463f0321 --- /dev/null +++ b/tests/fixtures/README.md @@ -0,0 +1,44 @@ +# Atmos Test Fixtures + +This directory contains test fixtures for Atmos CLI testing. The structure is organized to maximize component reuse and reduce duplication through Atmos's inheritance and vendoring capabilities. + +## Directory Structure + +``` +fixtures/ +├── atmos.yaml # Base configuration file +├── components/ # Shared reusable components +│ └── terraform/ # Terraform modules used across tests +├── scenarios/ # Test scenarios +│ ├── mock-terraform/ # Mock Terraform testing +│ ├── vendor/ # Vendored components +│ └── ... # Other test scenarios +└── schemas/ # JSON schemas for validation +``` + +## Component Reuse + +Components are managed in two ways: +1. **Direct Reference**: Using `base_path` to point to the shared components directory +2. **Vendoring**: Using Atmos's vendor capability to vendor components into specific test scenarios + +## Configuration Inheritance + +Test scenarios inherit from the base `atmos.yaml` and override only necessary settings. This reduces duplication and makes test maintenance easier. + +## Usage + +1. For new test scenarios, create a new directory under `scenarios/` +2. Inherit from the base configuration using: + ```yaml + inherits: + - ../../atmos.yaml + ``` +3. Override only the necessary settings for your test case + +## Best Practices + +- Use vendoring for scenarios that need isolated components +- Leverage inheritance to reduce configuration duplication +- Keep shared components in the central `components/` directory +- Document scenario-specific requirements in a README within each scenario directory \ No newline at end of file From 3ca5ace365ecaceb81e3cc2d78718d697ca9ee11 Mon Sep 17 00:00:00 2001 From: "Erik Osterman (CEO @ Cloud Posse)" Date: Tue, 4 Feb 2025 06:15:02 -0600 Subject: [PATCH 04/22] Sanitize snapshots (#1002) * sanitize snapshots * [autofix.ci] apply automated fixes * check for empty repo root * normalize slashes * normalize slashes * try to fix windows snapshots with windows paths * handle multiple slashes * handle multiple slashes * changed strategy for removing double slashes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../scenarios/mock-terraform/atmos.yaml | 1 + .../components/terraform/mock/backend.tf | 2 +- .../components/terraform/mock/main.tf | 28 +++++++++++++++++++ .../components/terraform/mock/mock.json | 2 +- .../components/terraform/mock/versions.tf | 3 +- .../mock-terraform/stacks/catalog/mock.yaml | 17 ----------- .../stacks/catalog/terraform/mock.yaml | 13 +++++++++ .../stacks/{deploy/dev.yaml => dev/mock.yaml} | 15 +++++----- .../{deploy/prod.yaml => prod/mock.yaml} | 15 +++++----- 9 files changed, 60 insertions(+), 36 deletions(-) delete mode 100644 tests/fixtures/scenarios/mock-terraform/stacks/catalog/mock.yaml create mode 100644 tests/fixtures/scenarios/mock-terraform/stacks/catalog/terraform/mock.yaml rename tests/fixtures/scenarios/mock-terraform/stacks/{deploy/dev.yaml => dev/mock.yaml} (52%) rename tests/fixtures/scenarios/mock-terraform/stacks/{deploy/prod.yaml => prod/mock.yaml} (52%) diff --git a/tests/fixtures/scenarios/mock-terraform/atmos.yaml b/tests/fixtures/scenarios/mock-terraform/atmos.yaml index 96fab075f..b91af8fe4 100644 --- a/tests/fixtures/scenarios/mock-terraform/atmos.yaml +++ b/tests/fixtures/scenarios/mock-terraform/atmos.yaml @@ -18,6 +18,7 @@ stacks: - "**/*" excluded_paths: - "**/templates/**/*" + name_pattern: "{environment}-{component}" logs: file: "/dev/stderr" diff --git a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/backend.tf b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/backend.tf index ba96c695b..3c533e6bf 100644 --- a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/backend.tf +++ b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/backend.tf @@ -1,5 +1,5 @@ terraform { backend "local" { - workspace_dir = "terraform.tfstate.d" + path = "terraform.tfstate" } } diff --git a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/main.tf b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/main.tf index 35d0bc935..59159f5e2 100644 --- a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/main.tf +++ b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/main.tf @@ -1,3 +1,15 @@ +variable "stage" { + type = string +} + +variable "environment" { + type = string +} + +variable "tenant" { + type = string +} + variable "foo" { type = string default = "foo" @@ -13,11 +25,15 @@ variable "baz" { default = "baz" } +# Mock resource for testing resource "local_file" "mock" { content = jsonencode({ foo = var.foo bar = var.bar baz = var.baz + stage = var.stage + environment = var.environment + tenant = var.tenant }) filename = "${path.module}/mock.json" } @@ -33,3 +49,15 @@ output "bar" { output "baz" { value = var.baz } + +output "stage" { + value = var.stage +} + +output "environment" { + value = var.environment +} + +output "tenant" { + value = var.tenant +} diff --git a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/mock.json b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/mock.json index 2ae9db6ae..c2b421146 100755 --- a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/mock.json +++ b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/mock.json @@ -1 +1 @@ -{"bar":"dev-bar","baz":"dev-baz","foo":"dev-foo"} \ No newline at end of file +{"bar":"dev-bar","baz":"dev-baz","environment":"dev","foo":"dev-foo","stage":"dev","tenant":"test"} \ No newline at end of file diff --git a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/versions.tf b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/versions.tf index da53755d4..ee57aa1d3 100644 --- a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/versions.tf +++ b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/versions.tf @@ -1,5 +1,6 @@ terraform { - required_version = ">= 1.0.0" + + required_providers { local = { source = "hashicorp/local" diff --git a/tests/fixtures/scenarios/mock-terraform/stacks/catalog/mock.yaml b/tests/fixtures/scenarios/mock-terraform/stacks/catalog/mock.yaml deleted file mode 100644 index 739272ba3..000000000 --- a/tests/fixtures/scenarios/mock-terraform/stacks/catalog/mock.yaml +++ /dev/null @@ -1,17 +0,0 @@ -# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json - -components: - terraform: - mock: - metadata: - type: terraform - component: mock - backend: - type: local - workspace_dir: terraform.tfstate.d - settings: - component: mock - vars: - foo: "test-foo" - bar: "test-bar" - baz: "test-baz" diff --git a/tests/fixtures/scenarios/mock-terraform/stacks/catalog/terraform/mock.yaml b/tests/fixtures/scenarios/mock-terraform/stacks/catalog/terraform/mock.yaml new file mode 100644 index 000000000..330768518 --- /dev/null +++ b/tests/fixtures/scenarios/mock-terraform/stacks/catalog/terraform/mock.yaml @@ -0,0 +1,13 @@ +components: + terraform: + mock: + metadata: + component: mock + backend: + type: local + settings: + component: mock + vars: + foo: "catalog-foo" + bar: "catalog-bar" + baz: "catalog-baz" \ No newline at end of file diff --git a/tests/fixtures/scenarios/mock-terraform/stacks/deploy/dev.yaml b/tests/fixtures/scenarios/mock-terraform/stacks/dev/mock.yaml similarity index 52% rename from tests/fixtures/scenarios/mock-terraform/stacks/deploy/dev.yaml rename to tests/fixtures/scenarios/mock-terraform/stacks/dev/mock.yaml index b82f7ba46..5d3d50405 100644 --- a/tests/fixtures/scenarios/mock-terraform/stacks/deploy/dev.yaml +++ b/tests/fixtures/scenarios/mock-terraform/stacks/dev/mock.yaml @@ -1,9 +1,5 @@ import: - - catalog/mock - -vars: - environment: dev - component: mock + - ../catalog/terraform/mock components: terraform: @@ -11,9 +7,12 @@ components: metadata: component: mock environment: dev - settings: - component: mock + backend: + type: local vars: + stage: dev + environment: dev + tenant: test foo: "dev-foo" bar: "dev-bar" - baz: "dev-baz" + baz: "dev-baz" \ No newline at end of file diff --git a/tests/fixtures/scenarios/mock-terraform/stacks/deploy/prod.yaml b/tests/fixtures/scenarios/mock-terraform/stacks/prod/mock.yaml similarity index 52% rename from tests/fixtures/scenarios/mock-terraform/stacks/deploy/prod.yaml rename to tests/fixtures/scenarios/mock-terraform/stacks/prod/mock.yaml index d4549de8b..239572a49 100644 --- a/tests/fixtures/scenarios/mock-terraform/stacks/deploy/prod.yaml +++ b/tests/fixtures/scenarios/mock-terraform/stacks/prod/mock.yaml @@ -1,9 +1,5 @@ import: - - catalog/mock - -vars: - environment: prod - component: mock + - ../catalog/terraform/mock components: terraform: @@ -11,9 +7,12 @@ components: metadata: component: mock environment: prod - settings: - component: mock + backend: + type: local vars: + stage: prod + environment: prod + tenant: test foo: "prod-foo" bar: "prod-bar" - baz: "prod-baz" + baz: "prod-baz" \ No newline at end of file From f1f4cdc5cce5d2e7798cd1ec4afd11d376722568 Mon Sep 17 00:00:00 2001 From: "Vinicius C." Date: Wed, 5 Feb 2025 18:58:36 +0000 Subject: [PATCH 05/22] Update tests/fixtures/scenarios/mock-terraform/atmos.yaml Co-authored-by: Erik Osterman (CEO @ Cloud Posse) --- tests/fixtures/scenarios/mock-terraform/atmos.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/scenarios/mock-terraform/atmos.yaml b/tests/fixtures/scenarios/mock-terraform/atmos.yaml index b91af8fe4..29cdf7abf 100644 --- a/tests/fixtures/scenarios/mock-terraform/atmos.yaml +++ b/tests/fixtures/scenarios/mock-terraform/atmos.yaml @@ -3,7 +3,7 @@ inherits: components: terraform: - base_path: "components/terraform" + base_path: "../../" apply: auto_approve: true clean: From 78ab753aba80ca828992f964b61a840ef10a574e Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Wed, 5 Feb 2025 19:34:38 +0000 Subject: [PATCH 06/22] Remove inheritance from mock-terraform test scenario --- tests/fixtures/README.md | 44 ------------------- tests/fixtures/atmos.yaml | 34 -------------- .../scenarios/mock-terraform/atmos.yaml | 3 -- 3 files changed, 81 deletions(-) delete mode 100644 tests/fixtures/README.md delete mode 100644 tests/fixtures/atmos.yaml diff --git a/tests/fixtures/README.md b/tests/fixtures/README.md deleted file mode 100644 index e463f0321..000000000 --- a/tests/fixtures/README.md +++ /dev/null @@ -1,44 +0,0 @@ -# Atmos Test Fixtures - -This directory contains test fixtures for Atmos CLI testing. The structure is organized to maximize component reuse and reduce duplication through Atmos's inheritance and vendoring capabilities. - -## Directory Structure - -``` -fixtures/ -├── atmos.yaml # Base configuration file -├── components/ # Shared reusable components -│ └── terraform/ # Terraform modules used across tests -├── scenarios/ # Test scenarios -│ ├── mock-terraform/ # Mock Terraform testing -│ ├── vendor/ # Vendored components -│ └── ... # Other test scenarios -└── schemas/ # JSON schemas for validation -``` - -## Component Reuse - -Components are managed in two ways: -1. **Direct Reference**: Using `base_path` to point to the shared components directory -2. **Vendoring**: Using Atmos's vendor capability to vendor components into specific test scenarios - -## Configuration Inheritance - -Test scenarios inherit from the base `atmos.yaml` and override only necessary settings. This reduces duplication and makes test maintenance easier. - -## Usage - -1. For new test scenarios, create a new directory under `scenarios/` -2. Inherit from the base configuration using: - ```yaml - inherits: - - ../../atmos.yaml - ``` -3. Override only the necessary settings for your test case - -## Best Practices - -- Use vendoring for scenarios that need isolated components -- Leverage inheritance to reduce configuration duplication -- Keep shared components in the central `components/` directory -- Document scenario-specific requirements in a README within each scenario directory \ No newline at end of file diff --git a/tests/fixtures/atmos.yaml b/tests/fixtures/atmos.yaml deleted file mode 100644 index 4fa0ed4cd..000000000 --- a/tests/fixtures/atmos.yaml +++ /dev/null @@ -1,34 +0,0 @@ -base_path: "./" - -components: - terraform: - # Set base path to the shared components directory - base_path: "components/terraform" - # Enable vendoring for component reuse - vendor: - enabled: true - source_path: "components/terraform" - target_path: "vendor/components/terraform" - apply_auto_approve: false - deploy_run_init: true - init_run_reconfigure: true - auto_generate_backend_file: false - command: terraform - -stacks: - base_path: "scenarios" - included_paths: - - "**/*" - excluded_paths: - - "**/templates/**/*" - - "**/_defaults.yaml" - name_pattern: "{environment}-{component}" - -terraform: - version_constraint: ">= 1.0" - download_url: "https://releases.hashicorp.com/terraform" - -logs: - file: "/dev/stderr" - level: "Info" - color: true \ No newline at end of file diff --git a/tests/fixtures/scenarios/mock-terraform/atmos.yaml b/tests/fixtures/scenarios/mock-terraform/atmos.yaml index 29cdf7abf..56752a9af 100644 --- a/tests/fixtures/scenarios/mock-terraform/atmos.yaml +++ b/tests/fixtures/scenarios/mock-terraform/atmos.yaml @@ -1,6 +1,3 @@ -inherits: - - ../../atmos.yaml - components: terraform: base_path: "../../" From a7f6e8eafb3da237ed202c9e702b85cea73845fc Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Thu, 6 Feb 2025 12:37:53 +0000 Subject: [PATCH 07/22] test: improve terraform integration test reliability --- tests/cli_terraform_test.go | 61 ++++++++++++++++--- .../scenarios/mock-terraform/atmos.yaml | 4 +- .../terraform/components/mock/main.tf | 18 ++++++ 3 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 tests/fixtures/scenarios/mock-terraform/terraform/components/mock/main.tf diff --git a/tests/cli_terraform_test.go b/tests/cli_terraform_test.go index 22e92731d..8592a0a84 100644 --- a/tests/cli_terraform_test.go +++ b/tests/cli_terraform_test.go @@ -25,6 +25,8 @@ func TestCLITerraformClean(t *testing.T) { t.Fatalf("Failed to apply updated PATH: %v", err) } fmt.Printf("Updated PATH: %s\n", pathManager.GetPath()) + + // Setup cleanup function to run after test completion defer func() { // Change back to the original working directory after the test if err := os.Chdir(startingDir); err != nil { @@ -44,6 +46,9 @@ func TestCLITerraformClean(t *testing.T) { t.Fatalf("Binary not found: %s. Current PATH: %s", "atmos", pathManager.GetPath()) } + // Clean up any existing Terraform state before starting tests + cleanupTerraformState(t) + // Initialize terraform for both environments runTerraformInit(t, binaryPath, "prod") runTerraformInit(t, binaryPath, "dev") @@ -51,13 +56,13 @@ func TestCLITerraformClean(t *testing.T) { // Run terraform apply for prod environment runTerraformApply(t, binaryPath, "prod") verifyStateFilesExist(t, []string{ - "./components/terraform/mock/.terraform", - "./components/terraform/mock/.terraform.lock.hcl", + "terraform/components/mock/.terraform", + "terraform/components/mock/.terraform.lock.hcl", }) runCLITerraformCleanComponent(t, binaryPath, "prod") verifyStateFilesDeleted(t, []string{ - "./components/terraform/mock/.terraform", - "./components/terraform/mock/.terraform.lock.hcl", + "terraform/components/mock/.terraform", + "terraform/components/mock/.terraform.lock.hcl", }) // Run terraform apply for dev environment @@ -65,8 +70,8 @@ func TestCLITerraformClean(t *testing.T) { // Verify if state files exist before cleaning stateFiles := []string{ - "./components/terraform/mock/.terraform", - "./components/terraform/mock/.terraform.lock.hcl", + "terraform/components/mock/.terraform", + "terraform/components/mock/.terraform.lock.hcl", } verifyStateFilesExist(t, stateFiles) @@ -167,8 +172,8 @@ func runTerraformInit(t *testing.T, binaryPath, environment string) { // Set environment variables envVars := os.Environ() envVars = append(envVars, - "ATMOS_COMPONENTS_TERRAFORM_INIT_RUN_RECONFIGURE=true", "ATMOS_COMPONENTS_TERRAFORM_DEPLOY_RUN_INIT=true", + "ATMOS_COMPONENTS_TERRAFORM_INIT_RUN_RECONFIGURE=true", "ATMOS_LOGS_LEVEL=Debug", "ATMOS_LOGS_FILE=/dev/stderr") cmd.Env = envVars @@ -178,16 +183,26 @@ func runTerraformInit(t *testing.T, binaryPath, environment string) { cmd.Stderr = &stderr // Log the command being executed - t.Logf("Running command: %s %v", binaryPath, cmd.Args) + t.Logf("Running terraform init for environment %s: %s %v", environment, binaryPath, cmd.Args) err := cmd.Run() // Always log both stdout and stderr t.Logf("Init command stdout:\n%s", stdout.String()) t.Logf("Init command stderr:\n%s", stderr.String()) + if err != nil { t.Fatalf("Failed to run terraform init mock -s %s: %v\nStdout: %s\nStderr: %s", environment, err, stdout.String(), stderr.String()) } + + // Verify that terraform was properly initialized + terraformDir := filepath.Join("terraform", "components", "mock") + if _, err := os.Stat(filepath.Join(terraformDir, ".terraform")); os.IsNotExist(err) { + t.Fatalf("Terraform was not properly initialized: .terraform directory not found in %s", terraformDir) + } + if _, err := os.Stat(filepath.Join(terraformDir, ".terraform.lock.hcl")); os.IsNotExist(err) { + t.Fatalf("Terraform was not properly initialized: .terraform.lock.hcl not found in %s", terraformDir) + } } func runTerraformCleanCommand(t *testing.T, binaryPath string, args ...string) { @@ -202,3 +217,33 @@ func runTerraformCleanCommand(t *testing.T, binaryPath string, args ...string) { t.Fatalf("Failed to run terraform clean: %v", stderr.String()) } } + +func cleanupTerraformState(t *testing.T) { + t.Helper() + + // Define paths to clean + terraformDir := filepath.Join("terraform", "components", "mock") + pathsToClean := []string{ + filepath.Join(terraformDir, ".terraform"), + filepath.Join(terraformDir, ".terraform.lock.hcl"), + filepath.Join(terraformDir, "terraform.tfstate"), + filepath.Join(terraformDir, "terraform.tfstate.backup"), + filepath.Join(terraformDir, ".terraform.tfstate.lock.info"), + filepath.Join(terraformDir, "terraform.tfstate.d"), + } + + // Remove each path + for _, path := range pathsToClean { + err := os.RemoveAll(path) + if err != nil && !os.IsNotExist(err) { + t.Fatalf("Failed to clean up Terraform state at %s: %v", path, err) + } + } + + // Ensure the terraform directory exists + if err := os.MkdirAll(terraformDir, 0755); err != nil { + t.Fatalf("Failed to create terraform directory at %s: %v", terraformDir, err) + } + + t.Logf("Successfully cleaned up Terraform state in %s", terraformDir) +} diff --git a/tests/fixtures/scenarios/mock-terraform/atmos.yaml b/tests/fixtures/scenarios/mock-terraform/atmos.yaml index 56752a9af..484efdb90 100644 --- a/tests/fixtures/scenarios/mock-terraform/atmos.yaml +++ b/tests/fixtures/scenarios/mock-terraform/atmos.yaml @@ -1,6 +1,6 @@ components: terraform: - base_path: "../../" + base_path: "terraform/components" apply: auto_approve: true clean: @@ -19,4 +19,4 @@ stacks: logs: file: "/dev/stderr" - level: "Info" + level: "Info" \ No newline at end of file diff --git a/tests/fixtures/scenarios/mock-terraform/terraform/components/mock/main.tf b/tests/fixtures/scenarios/mock-terraform/terraform/components/mock/main.tf new file mode 100644 index 000000000..dd1a89d08 --- /dev/null +++ b/tests/fixtures/scenarios/mock-terraform/terraform/components/mock/main.tf @@ -0,0 +1,18 @@ +terraform { + required_providers { + local = { + source = "hashicorp/local" + version = ">= 2.0" + } + } +} + +variable "environment" { + type = string +} + +# Mock resource for testing +resource "local_file" "test" { + content = "test-${var.environment}" + filename = "${path.module}/test.txt" +} \ No newline at end of file From 5eb60878f2e82a75b622268a8e08ebf82aa8c81c Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 6 Feb 2025 12:38:47 +0000 Subject: [PATCH 08/22] [autofix.ci] apply automated fixes --- tests/cli_terraform_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cli_terraform_test.go b/tests/cli_terraform_test.go index 8592a0a84..c88015135 100644 --- a/tests/cli_terraform_test.go +++ b/tests/cli_terraform_test.go @@ -241,7 +241,7 @@ func cleanupTerraformState(t *testing.T) { } // Ensure the terraform directory exists - if err := os.MkdirAll(terraformDir, 0755); err != nil { + if err := os.MkdirAll(terraformDir, 0o755); err != nil { t.Fatalf("Failed to create terraform directory at %s: %v", terraformDir, err) } From 8411f198e0ab199f7061531cb9243b012a7b9aae Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Fri, 7 Feb 2025 11:13:13 +0000 Subject: [PATCH 09/22] Add random test component and remove myapp component --- .../components/terraform/random/backend.tf | 6 ++ .../components/terraform/random/main.tf | 97 +++++++++++++++++++ .../components/terraform/random/versions.tf | 10 ++ .../components/terraform/myapp/README.md | 50 ---------- .../components/terraform/myapp/main.tf | 22 ----- .../components/terraform/myapp/outputs.tf | 27 ------ .../components/terraform/myapp/variables.tf | 34 ------- .../components/terraform/myapp/versions.tf | 5 - .../relative-paths/stacks/catalog/myapp.yaml | 11 --- .../relative-paths/stacks/catalog/random.yaml | 12 +++ 10 files changed, 125 insertions(+), 149 deletions(-) create mode 100644 tests/fixtures/components/terraform/random/backend.tf create mode 100644 tests/fixtures/components/terraform/random/main.tf create mode 100644 tests/fixtures/components/terraform/random/versions.tf delete mode 100644 tests/fixtures/scenarios/relative-paths/components/terraform/myapp/README.md delete mode 100644 tests/fixtures/scenarios/relative-paths/components/terraform/myapp/main.tf delete mode 100644 tests/fixtures/scenarios/relative-paths/components/terraform/myapp/outputs.tf delete mode 100644 tests/fixtures/scenarios/relative-paths/components/terraform/myapp/variables.tf delete mode 100644 tests/fixtures/scenarios/relative-paths/components/terraform/myapp/versions.tf delete mode 100644 tests/fixtures/scenarios/relative-paths/stacks/catalog/myapp.yaml create mode 100644 tests/fixtures/scenarios/relative-paths/stacks/catalog/random.yaml diff --git a/tests/fixtures/components/terraform/random/backend.tf b/tests/fixtures/components/terraform/random/backend.tf new file mode 100644 index 000000000..35effd8e3 --- /dev/null +++ b/tests/fixtures/components/terraform/random/backend.tf @@ -0,0 +1,6 @@ +terraform { + # Using local backend for testing + backend "local" { + path = "terraform.tfstate" + } +} diff --git a/tests/fixtures/components/terraform/random/main.tf b/tests/fixtures/components/terraform/random/main.tf new file mode 100644 index 000000000..fe0edc26c --- /dev/null +++ b/tests/fixtures/components/terraform/random/main.tf @@ -0,0 +1,97 @@ +# 🎲 Random Component for Testing +# This component is designed to be simple, reusable, and perfect for testing Atmos functionality + +terraform { + required_providers { + local = { + source = "hashicorp/local" + version = ">= 2.0" + } + } +} + +# Common variables used across test scenarios +variable "stage" { + type = string + description = "Stage (e.g., dev, staging, prod)" +} + +variable "environment" { + type = string + description = "Environment (e.g., ue2, uw2)" +} + +variable "tenant" { + type = string + description = "Tenant name" +} + +# Test-specific variables with defaults +variable "foo" { + type = string + default = "foo" + description = "Test variable foo" +} + +variable "bar" { + type = string + default = "bar" + description = "Test variable bar" +} + +variable "baz" { + type = string + default = "baz" + description = "Test variable baz" +} + +# Simple local file resource for testing +resource "local_file" "test" { + content = jsonencode({ + metadata = { + stage = var.stage + environment = var.environment + tenant = var.tenant + timestamp = timestamp() + } + config = { + foo = var.foo + bar = var.bar + baz = var.baz + } + }) + filename = "${path.module}/test-${var.environment}-${var.stage}.json" +} + +# Outputs for testing +output "stage" { + value = var.stage +} + +output "environment" { + value = var.environment +} + +output "tenant" { + value = var.tenant +} + +output "foo" { + value = var.foo +} + +output "bar" { + value = var.bar +} + +output "baz" { + value = var.baz +} + +output "file_path" { + value = local_file.test.filename +} + +output "file_content" { + value = local_file.test.content +} diff --git a/tests/fixtures/components/terraform/random/versions.tf b/tests/fixtures/components/terraform/random/versions.tf new file mode 100644 index 000000000..7cb363d31 --- /dev/null +++ b/tests/fixtures/components/terraform/random/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 1.0.0" + + required_providers { + local = { + source = "hashicorp/local" + version = ">= 2.0" + } + } +} diff --git a/tests/fixtures/scenarios/relative-paths/components/terraform/myapp/README.md b/tests/fixtures/scenarios/relative-paths/components/terraform/myapp/README.md deleted file mode 100644 index 1d7a7ee03..000000000 --- a/tests/fixtures/scenarios/relative-paths/components/terraform/myapp/README.md +++ /dev/null @@ -1,50 +0,0 @@ -# Example Terraform Weather Component - -This Terraform "root" module fetches weather information for a specified location with custom display options. -It queries data from the [`wttr.in`](https://wttr.in) weather service and stores the result in a local file (`cache.txt`). -It also provides several outputs like weather information, request URL, stage, location, language, and units of measurement. - -## Features - -- Fetch weather updates for a location using HTTP request. -- Write the obtained weather data in a local file. -- Customizable display options. -- View the request URL. -- Get informed about the stage, location, language, and units in the metadata. - -## Usage - -To include this module in your [Atmos Stacks](https://atmos.tools/core-concepts/stacks) configuration: - -```yaml -components: - terraform: - weather: - vars: - stage: dev - location: New York - options: 0T - format: v2 - lang: en - units: m -``` - -### Inputs -- `stage`: Stage where it will be deployed. -- `location`: Location for which the weather is reported. Default is "Los Angeles". -- `options`: Options to customize the output. Default is "0T". -- `format`: Specifies the output format. Default is "v2". -- `lang`: Language in which the weather will be displayed. Default is "en". -- `units`: Units in which the weather will be displayed. Default is "m". - -### Outputs -- `weather`: The fetched weather data. -- `url`: Requested URL. -- `stage`: Stage of deployment. -- `location`: Location of the reported weather. -- `lang`: Language used for weather data. -- `units`: Units of measurement for the weather data. - -Please note, this module requires Terraform version >=1.0.0, and you need to specify no other required providers. - -Happy Weather Tracking! diff --git a/tests/fixtures/scenarios/relative-paths/components/terraform/myapp/main.tf b/tests/fixtures/scenarios/relative-paths/components/terraform/myapp/main.tf deleted file mode 100644 index 9971bf5b0..000000000 --- a/tests/fixtures/scenarios/relative-paths/components/terraform/myapp/main.tf +++ /dev/null @@ -1,22 +0,0 @@ -locals { - url = format("https://wttr.in/%v?%v&format=%v&lang=%v&u=%v", - urlencode(var.location), - urlencode(var.options), - urlencode(var.format), - urlencode(var.lang), - urlencode(var.units), - ) -} - -data "http" "weather" { - url = local.url - request_headers = { - User-Agent = "curl" - } -} - -# Now write this to a file (as an example of a resource) -resource "local_file" "cache" { - filename = "cache.${var.stage}.txt" - content = data.http.weather.response_body -} diff --git a/tests/fixtures/scenarios/relative-paths/components/terraform/myapp/outputs.tf b/tests/fixtures/scenarios/relative-paths/components/terraform/myapp/outputs.tf deleted file mode 100644 index f0e7fd442..000000000 --- a/tests/fixtures/scenarios/relative-paths/components/terraform/myapp/outputs.tf +++ /dev/null @@ -1,27 +0,0 @@ -output "weather" { - value = data.http.weather.response_body -} - -output "url" { - value = local.url -} - -output "stage" { - value = var.stage - description = "Stage where it was deployed" -} - -output "location" { - value = var.location - description = "Location of the weather report." -} - -output "lang" { - value = var.lang - description = "Language which the weather is displayed." -} - -output "units" { - value = var.units - description = "Units the weather is displayed." -} diff --git a/tests/fixtures/scenarios/relative-paths/components/terraform/myapp/variables.tf b/tests/fixtures/scenarios/relative-paths/components/terraform/myapp/variables.tf deleted file mode 100644 index c8a32310a..000000000 --- a/tests/fixtures/scenarios/relative-paths/components/terraform/myapp/variables.tf +++ /dev/null @@ -1,34 +0,0 @@ -variable "stage" { - description = "Stage where it will be deployed" - type = string -} - -variable "location" { - description = "Location for which the weather." - type = string - default = "Los Angeles" -} - -variable "options" { - description = "Options to customize the output." - type = string - default = "0T" -} - -variable "format" { - description = "Format of the output." - type = string - default = "v2" -} - -variable "lang" { - description = "Language in which the weather is displayed." - type = string - default = "en" -} - -variable "units" { - description = "Units in which the weather is displayed." - type = string - default = "m" -} diff --git a/tests/fixtures/scenarios/relative-paths/components/terraform/myapp/versions.tf b/tests/fixtures/scenarios/relative-paths/components/terraform/myapp/versions.tf deleted file mode 100644 index e2a3d732d..000000000 --- a/tests/fixtures/scenarios/relative-paths/components/terraform/myapp/versions.tf +++ /dev/null @@ -1,5 +0,0 @@ -terraform { - required_version = ">= 1.0.0" - - required_providers {} -} diff --git a/tests/fixtures/scenarios/relative-paths/stacks/catalog/myapp.yaml b/tests/fixtures/scenarios/relative-paths/stacks/catalog/myapp.yaml deleted file mode 100644 index 4fef54e38..000000000 --- a/tests/fixtures/scenarios/relative-paths/stacks/catalog/myapp.yaml +++ /dev/null @@ -1,11 +0,0 @@ -# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json - -components: - terraform: - myapp: - vars: - location: Los Angeles - lang: en - format: '' - options: '0' - units: m diff --git a/tests/fixtures/scenarios/relative-paths/stacks/catalog/random.yaml b/tests/fixtures/scenarios/relative-paths/stacks/catalog/random.yaml new file mode 100644 index 000000000..5a59a7ded --- /dev/null +++ b/tests/fixtures/scenarios/relative-paths/stacks/catalog/random.yaml @@ -0,0 +1,12 @@ +# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json + +components: + terraform: + random: + vars: + stage: dev + environment: ue2 + tenant: acme + foo: "test-foo" + bar: "test-bar" + baz: "test-baz" From 8007383f4fc5a1933f9a658d70e5ade4475c8a19 Mon Sep 17 00:00:00 2001 From: "Vinicius C." Date: Fri, 7 Feb 2025 14:38:03 +0000 Subject: [PATCH 10/22] Update tests/fixtures/scenarios/mock-terraform/stacks/prod/mock.yaml Co-authored-by: Erik Osterman (CEO @ Cloud Posse) --- tests/fixtures/scenarios/mock-terraform/stacks/prod/mock.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/scenarios/mock-terraform/stacks/prod/mock.yaml b/tests/fixtures/scenarios/mock-terraform/stacks/prod/mock.yaml index 239572a49..a6515b4a6 100644 --- a/tests/fixtures/scenarios/mock-terraform/stacks/prod/mock.yaml +++ b/tests/fixtures/scenarios/mock-terraform/stacks/prod/mock.yaml @@ -1,5 +1,5 @@ import: - - ../catalog/terraform/mock + - catalog/mock components: terraform: From 95dd117049607e34949246517796641d65c670ca Mon Sep 17 00:00:00 2001 From: "Vinicius C." Date: Fri, 7 Feb 2025 14:38:24 +0000 Subject: [PATCH 11/22] Update tests/fixtures/scenarios/mock-terraform/atmos.yaml Co-authored-by: Erik Osterman (CEO @ Cloud Posse) --- tests/fixtures/scenarios/mock-terraform/atmos.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/scenarios/mock-terraform/atmos.yaml b/tests/fixtures/scenarios/mock-terraform/atmos.yaml index 484efdb90..a2afe1e55 100644 --- a/tests/fixtures/scenarios/mock-terraform/atmos.yaml +++ b/tests/fixtures/scenarios/mock-terraform/atmos.yaml @@ -1,6 +1,6 @@ components: terraform: - base_path: "terraform/components" + base_path: "../../terraform/components" apply: auto_approve: true clean: From 30f49a0f5719bd6e3acf1d144f395f36be14696c Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Fri, 7 Feb 2025 14:49:36 +0000 Subject: [PATCH 12/22] Delete mock terraform test fixtures --- .../components/terraform/mock/backend.tf | 5 -- .../components/terraform/mock/main.tf | 63 ------------------- .../components/terraform/mock/mock.json | 1 - .../components/terraform/mock/versions.tf | 10 --- .../stacks/catalog/{terraform => }/mock.yaml | 0 5 files changed, 79 deletions(-) delete mode 100644 tests/fixtures/scenarios/mock-terraform/components/terraform/mock/backend.tf delete mode 100644 tests/fixtures/scenarios/mock-terraform/components/terraform/mock/main.tf delete mode 100755 tests/fixtures/scenarios/mock-terraform/components/terraform/mock/mock.json delete mode 100644 tests/fixtures/scenarios/mock-terraform/components/terraform/mock/versions.tf rename tests/fixtures/scenarios/mock-terraform/stacks/catalog/{terraform => }/mock.yaml (100%) diff --git a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/backend.tf b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/backend.tf deleted file mode 100644 index 3c533e6bf..000000000 --- a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/backend.tf +++ /dev/null @@ -1,5 +0,0 @@ -terraform { - backend "local" { - path = "terraform.tfstate" - } -} diff --git a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/main.tf b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/main.tf deleted file mode 100644 index 59159f5e2..000000000 --- a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/main.tf +++ /dev/null @@ -1,63 +0,0 @@ -variable "stage" { - type = string -} - -variable "environment" { - type = string -} - -variable "tenant" { - type = string -} - -variable "foo" { - type = string - default = "foo" -} - -variable "bar" { - type = string - default = "bar" -} - -variable "baz" { - type = string - default = "baz" -} - -# Mock resource for testing -resource "local_file" "mock" { - content = jsonencode({ - foo = var.foo - bar = var.bar - baz = var.baz - stage = var.stage - environment = var.environment - tenant = var.tenant - }) - filename = "${path.module}/mock.json" -} - -output "foo" { - value = var.foo -} - -output "bar" { - value = var.bar -} - -output "baz" { - value = var.baz -} - -output "stage" { - value = var.stage -} - -output "environment" { - value = var.environment -} - -output "tenant" { - value = var.tenant -} diff --git a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/mock.json b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/mock.json deleted file mode 100755 index c2b421146..000000000 --- a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/mock.json +++ /dev/null @@ -1 +0,0 @@ -{"bar":"dev-bar","baz":"dev-baz","environment":"dev","foo":"dev-foo","stage":"dev","tenant":"test"} \ No newline at end of file diff --git a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/versions.tf b/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/versions.tf deleted file mode 100644 index ee57aa1d3..000000000 --- a/tests/fixtures/scenarios/mock-terraform/components/terraform/mock/versions.tf +++ /dev/null @@ -1,10 +0,0 @@ -terraform { - - - required_providers { - local = { - source = "hashicorp/local" - version = ">= 2.0" - } - } -} diff --git a/tests/fixtures/scenarios/mock-terraform/stacks/catalog/terraform/mock.yaml b/tests/fixtures/scenarios/mock-terraform/stacks/catalog/mock.yaml similarity index 100% rename from tests/fixtures/scenarios/mock-terraform/stacks/catalog/terraform/mock.yaml rename to tests/fixtures/scenarios/mock-terraform/stacks/catalog/mock.yaml From c6a154a85333b53ecafa661dd5e97d2eca914751 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Fri, 7 Feb 2025 18:32:25 +0000 Subject: [PATCH 13/22] refactor: update stack configurations and import paths --- .../scenarios/mock-terraform/stacks/dev/mock.yaml | 4 ++-- .../stacks/orgs/acme/platform/dev.yaml | 12 ++++++++---- .../stacks/orgs/acme/platform/prod.yaml | 12 ++++++++---- .../stacks/orgs/acme/platform/staging.yaml | 12 ++++++++---- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/tests/fixtures/scenarios/mock-terraform/stacks/dev/mock.yaml b/tests/fixtures/scenarios/mock-terraform/stacks/dev/mock.yaml index 5d3d50405..de8b553e3 100644 --- a/tests/fixtures/scenarios/mock-terraform/stacks/dev/mock.yaml +++ b/tests/fixtures/scenarios/mock-terraform/stacks/dev/mock.yaml @@ -1,5 +1,5 @@ import: - - ../catalog/terraform/mock + - ../catalog/mock components: terraform: @@ -15,4 +15,4 @@ components: tenant: test foo: "dev-foo" bar: "dev-bar" - baz: "dev-baz" \ No newline at end of file + baz: "dev-baz" diff --git a/tests/fixtures/scenarios/relative-paths/stacks/orgs/acme/platform/dev.yaml b/tests/fixtures/scenarios/relative-paths/stacks/orgs/acme/platform/dev.yaml index 060e05fdc..b0e281da5 100644 --- a/tests/fixtures/scenarios/relative-paths/stacks/orgs/acme/platform/dev.yaml +++ b/tests/fixtures/scenarios/relative-paths/stacks/orgs/acme/platform/dev.yaml @@ -5,11 +5,15 @@ vars: import: - ./_defaults - - catalog/myapp + - catalog/random components: terraform: - myapp: + random: vars: - location: Stockholm - lang: se + stage: dev + environment: ue2 + tenant: platform + foo: "test-foo" + bar: "test-bar" + baz: "test-baz" diff --git a/tests/fixtures/scenarios/relative-paths/stacks/orgs/acme/platform/prod.yaml b/tests/fixtures/scenarios/relative-paths/stacks/orgs/acme/platform/prod.yaml index 3bb4193e4..3ba32e2b6 100644 --- a/tests/fixtures/scenarios/relative-paths/stacks/orgs/acme/platform/prod.yaml +++ b/tests/fixtures/scenarios/relative-paths/stacks/orgs/acme/platform/prod.yaml @@ -5,11 +5,15 @@ vars: import: - ./_defaults - - catalog/myapp + - catalog/random components: terraform: - myapp: + random: vars: - location: Los Angeles - lang: en + stage: prod + environment: ue2 + tenant: platform + foo: "test-foo" + bar: "test-bar" + baz: "test-baz" diff --git a/tests/fixtures/scenarios/relative-paths/stacks/orgs/acme/platform/staging.yaml b/tests/fixtures/scenarios/relative-paths/stacks/orgs/acme/platform/staging.yaml index 095822a27..d7cc0a482 100644 --- a/tests/fixtures/scenarios/relative-paths/stacks/orgs/acme/platform/staging.yaml +++ b/tests/fixtures/scenarios/relative-paths/stacks/orgs/acme/platform/staging.yaml @@ -5,11 +5,15 @@ vars: import: - ./_defaults - - catalog/myapp + - catalog/random components: terraform: - myapp: + random: vars: - location: Los Angeles - lang: en + stage: staging + environment: ue2 + tenant: platform + foo: "test-foo" + bar: "test-bar" + baz: "test-baz" From 5e2b478ec55536f05b30b6ed285728de99505719 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Sat, 8 Feb 2025 17:26:49 +0000 Subject: [PATCH 14/22] Update test fixtures and paths for terraform components --- tests/cli_terraform_test.go | 16 +++---- .../components/terraform/mock/main.tf | 26 +++++++++++ .../scenarios/mock-terraform/atmos.yaml | 2 +- .../terraform/components/mock/main.tf | 18 -------- ...s_stacks_with_relative_paths.stdout.golden | 45 +++++++++---------- 5 files changed, 56 insertions(+), 51 deletions(-) delete mode 100644 tests/fixtures/scenarios/mock-terraform/terraform/components/mock/main.tf diff --git a/tests/cli_terraform_test.go b/tests/cli_terraform_test.go index c88015135..a95f86464 100644 --- a/tests/cli_terraform_test.go +++ b/tests/cli_terraform_test.go @@ -56,13 +56,13 @@ func TestCLITerraformClean(t *testing.T) { // Run terraform apply for prod environment runTerraformApply(t, binaryPath, "prod") verifyStateFilesExist(t, []string{ - "terraform/components/mock/.terraform", - "terraform/components/mock/.terraform.lock.hcl", + "../../components/terraform/mock/.terraform", + "../../components/terraform/mock/.terraform.lock.hcl", }) runCLITerraformCleanComponent(t, binaryPath, "prod") verifyStateFilesDeleted(t, []string{ - "terraform/components/mock/.terraform", - "terraform/components/mock/.terraform.lock.hcl", + "../../components/terraform/mock/.terraform", + "../../components/terraform/mock/.terraform.lock.hcl", }) // Run terraform apply for dev environment @@ -70,8 +70,8 @@ func TestCLITerraformClean(t *testing.T) { // Verify if state files exist before cleaning stateFiles := []string{ - "terraform/components/mock/.terraform", - "terraform/components/mock/.terraform.lock.hcl", + "../../components/terraform/mock/.terraform", + "../../components/terraform/mock/.terraform.lock.hcl", } verifyStateFilesExist(t, stateFiles) @@ -196,7 +196,7 @@ func runTerraformInit(t *testing.T, binaryPath, environment string) { } // Verify that terraform was properly initialized - terraformDir := filepath.Join("terraform", "components", "mock") + terraformDir := filepath.Join("../../components/terraform", "mock") if _, err := os.Stat(filepath.Join(terraformDir, ".terraform")); os.IsNotExist(err) { t.Fatalf("Terraform was not properly initialized: .terraform directory not found in %s", terraformDir) } @@ -222,7 +222,7 @@ func cleanupTerraformState(t *testing.T) { t.Helper() // Define paths to clean - terraformDir := filepath.Join("terraform", "components", "mock") + terraformDir := filepath.Join("../../components/terraform", "mock") pathsToClean := []string{ filepath.Join(terraformDir, ".terraform"), filepath.Join(terraformDir, ".terraform.lock.hcl"), diff --git a/tests/fixtures/components/terraform/mock/main.tf b/tests/fixtures/components/terraform/mock/main.tf index 236ce8896..bc787c0a6 100644 --- a/tests/fixtures/components/terraform/mock/main.tf +++ b/tests/fixtures/components/terraform/mock/main.tf @@ -1,3 +1,29 @@ +terraform { + required_providers { + local = { + source = "hashicorp/local" + version = ">= 2.0.0" + } + } +} + +variable "environment" { + type = string +} + +variable "stage" { + type = string +} + +variable "tenant" { + type = string +} + +resource "local_file" "test" { + content = "test-${var.environment}" + filename = "./test.txt" +} + variable "foo" { type = string default = "foo" diff --git a/tests/fixtures/scenarios/mock-terraform/atmos.yaml b/tests/fixtures/scenarios/mock-terraform/atmos.yaml index a2afe1e55..4ac2b4682 100644 --- a/tests/fixtures/scenarios/mock-terraform/atmos.yaml +++ b/tests/fixtures/scenarios/mock-terraform/atmos.yaml @@ -1,6 +1,6 @@ components: terraform: - base_path: "../../terraform/components" + base_path: "../../components/terraform" apply: auto_approve: true clean: diff --git a/tests/fixtures/scenarios/mock-terraform/terraform/components/mock/main.tf b/tests/fixtures/scenarios/mock-terraform/terraform/components/mock/main.tf deleted file mode 100644 index dd1a89d08..000000000 --- a/tests/fixtures/scenarios/mock-terraform/terraform/components/mock/main.tf +++ /dev/null @@ -1,18 +0,0 @@ -terraform { - required_providers { - local = { - source = "hashicorp/local" - version = ">= 2.0" - } - } -} - -variable "environment" { - type = string -} - -# Mock resource for testing -resource "local_file" "test" { - content = "test-${var.environment}" - filename = "${path.module}/test.txt" -} \ No newline at end of file diff --git a/tests/snapshots/TestCLICommands_atmos_stacks_with_relative_paths.stdout.golden b/tests/snapshots/TestCLICommands_atmos_stacks_with_relative_paths.stdout.golden index a0cd1f4ce..f53b5a7fc 100644 --- a/tests/snapshots/TestCLICommands_atmos_stacks_with_relative_paths.stdout.golden +++ b/tests/snapshots/TestCLICommands_atmos_stacks_with_relative_paths.stdout.golden @@ -1,15 +1,15 @@ acme-platform-dev: components: terraform: - myapp: - atmos_component: myapp + random: + atmos_component: random atmos_manifest: orgs/acme/platform/dev atmos_stack: acme-platform-dev atmos_stack_file: orgs/acme/platform/dev backend: {} backend_type: "" command: terraform - component: myapp + component: random env: {} hooks: {} inheritance: [] @@ -21,27 +21,26 @@ acme-platform-dev: settings: {} stack: acme-platform-dev vars: - format: "" - lang: se - location: Stockholm + bar: test-bar + baz: test-baz + environment: ue2 + foo: test-foo namespace: acme - options: "0" stage: dev tenant: platform - units: m workspace: acme-platform-dev acme-platform-prod: components: terraform: - myapp: - atmos_component: myapp + random: + atmos_component: random atmos_manifest: orgs/acme/platform/prod atmos_stack: acme-platform-prod atmos_stack_file: orgs/acme/platform/prod backend: {} backend_type: "" command: terraform - component: myapp + component: random env: {} hooks: {} inheritance: [] @@ -53,27 +52,26 @@ acme-platform-prod: settings: {} stack: acme-platform-prod vars: - format: "" - lang: en - location: Los Angeles + bar: test-bar + baz: test-baz + environment: ue2 + foo: test-foo namespace: acme - options: "0" stage: prod tenant: platform - units: m workspace: acme-platform-prod acme-platform-staging: components: terraform: - myapp: - atmos_component: myapp + random: + atmos_component: random atmos_manifest: orgs/acme/platform/staging atmos_stack: acme-platform-staging atmos_stack_file: orgs/acme/platform/staging backend: {} backend_type: "" command: terraform - component: myapp + component: random env: {} hooks: {} inheritance: [] @@ -85,13 +83,12 @@ acme-platform-staging: settings: {} stack: acme-platform-staging vars: - format: "" - lang: en - location: Los Angeles + bar: test-bar + baz: test-baz + environment: ue2 + foo: test-foo namespace: acme - options: "0" stage: staging tenant: platform - units: m workspace: acme-platform-staging From 2fab0602852ae21ae9b91a7f54692767b9814aa9 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Sat, 8 Feb 2025 18:12:28 +0000 Subject: [PATCH 15/22] test: update test cases and add random component fixtures --- pkg/stack/stack_processor_test.go | 13 +++++++++++-- tests/fixtures/scenarios/atmos-functions/atmos.yaml | 1 + .../relative-paths/stacks/catalog/random.yaml | 2 -- .../stacks/catalog/random/defaults.yaml | 10 ++++++++++ tests/test-cases/atmos-functions.yaml | 6 ++---- 5 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 tests/fixtures/scenarios/relative-paths/stacks/catalog/random/defaults.yaml diff --git a/pkg/stack/stack_processor_test.go b/pkg/stack/stack_processor_test.go index 78257f69b..ff30f6716 100644 --- a/pkg/stack/stack_processor_test.go +++ b/pkg/stack/stack_processor_test.go @@ -239,9 +239,18 @@ func TestStackProcessorRelativePaths(t *testing.T) { mapConfig1, err := u.UnmarshalYAML[schema.AtmosSectionMapType](listResult[0]) assert.Nil(t, err) + // Check components components := mapConfig1["components"].(map[string]any) terraformComponents := components["terraform"].(map[string]any) - myappComponent := terraformComponents["myapp"].(map[string]any) - assert.NotNil(t, myappComponent) + randomComponent := terraformComponents["random"].(map[string]any) + assert.NotNil(t, randomComponent) + + vars := randomComponent["vars"].(map[string]any) + assert.Equal(t, "dev", vars["stage"]) + assert.Equal(t, "ue2", vars["environment"]) + assert.Equal(t, "platform", vars["tenant"]) + assert.Equal(t, "test-foo", vars["foo"]) + assert.Equal(t, "test-bar", vars["bar"]) + assert.Equal(t, "test-baz", vars["baz"]) } diff --git a/tests/fixtures/scenarios/atmos-functions/atmos.yaml b/tests/fixtures/scenarios/atmos-functions/atmos.yaml index 48faef460..27a7d87d7 100644 --- a/tests/fixtures/scenarios/atmos-functions/atmos.yaml +++ b/tests/fixtures/scenarios/atmos-functions/atmos.yaml @@ -12,6 +12,7 @@ stacks: base_path: "stacks" included_paths: - "deploy/**/*" + - "workflows/**/*" excluded_paths: - "**/_defaults.yaml" name_pattern: "{stage}" diff --git a/tests/fixtures/scenarios/relative-paths/stacks/catalog/random.yaml b/tests/fixtures/scenarios/relative-paths/stacks/catalog/random.yaml index 5a59a7ded..2db9a9d90 100644 --- a/tests/fixtures/scenarios/relative-paths/stacks/catalog/random.yaml +++ b/tests/fixtures/scenarios/relative-paths/stacks/catalog/random.yaml @@ -1,5 +1,3 @@ -# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json - components: terraform: random: diff --git a/tests/fixtures/scenarios/relative-paths/stacks/catalog/random/defaults.yaml b/tests/fixtures/scenarios/relative-paths/stacks/catalog/random/defaults.yaml new file mode 100644 index 000000000..13c500917 --- /dev/null +++ b/tests/fixtures/scenarios/relative-paths/stacks/catalog/random/defaults.yaml @@ -0,0 +1,10 @@ +components: + terraform: + random: + vars: + stage: dev + environment: ue2 + tenant: platform + foo: "test-foo" + bar: "test-bar" + baz: "test-baz" \ No newline at end of file diff --git a/tests/test-cases/atmos-functions.yaml b/tests/test-cases/atmos-functions.yaml index 9dbd1ea6b..a3e960c6f 100644 --- a/tests/test-cases/atmos-functions.yaml +++ b/tests/test-cases/atmos-functions.yaml @@ -6,9 +6,8 @@ tests: workdir: "fixtures/scenarios/atmos-functions/" command: "atmos" args: - - "terraform" + - "workflow" - "deploy" - - "component-4" - "-s" - "nonprod" skip: @@ -30,9 +29,8 @@ tests: workdir: "fixtures/scenarios/atmos-functions/" command: "atmos" args: - - "terraform" + - "workflow" - "deploy" - - "component-4" - "-s" - "nonprod" expect: From 9587b486373731292f9bb72797aee69c15f4025e Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sat, 8 Feb 2025 18:13:14 +0000 Subject: [PATCH 16/22] [autofix.ci] apply automated fixes --- pkg/stack/stack_processor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/stack/stack_processor_test.go b/pkg/stack/stack_processor_test.go index ff30f6716..fba7446ba 100644 --- a/pkg/stack/stack_processor_test.go +++ b/pkg/stack/stack_processor_test.go @@ -38,7 +38,7 @@ func TestStackProcessor(t *testing.T) { }, } - var listResult, mapResult, _, err = ProcessYAMLConfigFiles( + listResult, mapResult, _, err := ProcessYAMLConfigFiles( atmosConfig, stacksBasePath, terraformComponentsBasePath, From e95ffea10be32c990f50f1304c5d38b52deedb65 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Sat, 8 Feb 2025 19:08:20 +0000 Subject: [PATCH 17/22] Revert "test: update test cases and add random component fixtures" This reverts commit 2fab0602852ae21ae9b91a7f54692767b9814aa9. --- pkg/stack/stack_processor_test.go | 13 ++----------- tests/fixtures/scenarios/atmos-functions/atmos.yaml | 1 - .../relative-paths/stacks/catalog/random.yaml | 2 ++ .../stacks/catalog/random/defaults.yaml | 10 ---------- tests/test-cases/atmos-functions.yaml | 6 ++++-- 5 files changed, 8 insertions(+), 24 deletions(-) delete mode 100644 tests/fixtures/scenarios/relative-paths/stacks/catalog/random/defaults.yaml diff --git a/pkg/stack/stack_processor_test.go b/pkg/stack/stack_processor_test.go index fba7446ba..672c1c1b0 100644 --- a/pkg/stack/stack_processor_test.go +++ b/pkg/stack/stack_processor_test.go @@ -239,18 +239,9 @@ func TestStackProcessorRelativePaths(t *testing.T) { mapConfig1, err := u.UnmarshalYAML[schema.AtmosSectionMapType](listResult[0]) assert.Nil(t, err) - // Check components components := mapConfig1["components"].(map[string]any) terraformComponents := components["terraform"].(map[string]any) - randomComponent := terraformComponents["random"].(map[string]any) - assert.NotNil(t, randomComponent) - - vars := randomComponent["vars"].(map[string]any) - assert.Equal(t, "dev", vars["stage"]) - assert.Equal(t, "ue2", vars["environment"]) - assert.Equal(t, "platform", vars["tenant"]) - assert.Equal(t, "test-foo", vars["foo"]) - assert.Equal(t, "test-bar", vars["bar"]) - assert.Equal(t, "test-baz", vars["baz"]) + myappComponent := terraformComponents["myapp"].(map[string]any) + assert.NotNil(t, myappComponent) } diff --git a/tests/fixtures/scenarios/atmos-functions/atmos.yaml b/tests/fixtures/scenarios/atmos-functions/atmos.yaml index 27a7d87d7..48faef460 100644 --- a/tests/fixtures/scenarios/atmos-functions/atmos.yaml +++ b/tests/fixtures/scenarios/atmos-functions/atmos.yaml @@ -12,7 +12,6 @@ stacks: base_path: "stacks" included_paths: - "deploy/**/*" - - "workflows/**/*" excluded_paths: - "**/_defaults.yaml" name_pattern: "{stage}" diff --git a/tests/fixtures/scenarios/relative-paths/stacks/catalog/random.yaml b/tests/fixtures/scenarios/relative-paths/stacks/catalog/random.yaml index 2db9a9d90..5a59a7ded 100644 --- a/tests/fixtures/scenarios/relative-paths/stacks/catalog/random.yaml +++ b/tests/fixtures/scenarios/relative-paths/stacks/catalog/random.yaml @@ -1,3 +1,5 @@ +# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json + components: terraform: random: diff --git a/tests/fixtures/scenarios/relative-paths/stacks/catalog/random/defaults.yaml b/tests/fixtures/scenarios/relative-paths/stacks/catalog/random/defaults.yaml deleted file mode 100644 index 13c500917..000000000 --- a/tests/fixtures/scenarios/relative-paths/stacks/catalog/random/defaults.yaml +++ /dev/null @@ -1,10 +0,0 @@ -components: - terraform: - random: - vars: - stage: dev - environment: ue2 - tenant: platform - foo: "test-foo" - bar: "test-bar" - baz: "test-baz" \ No newline at end of file diff --git a/tests/test-cases/atmos-functions.yaml b/tests/test-cases/atmos-functions.yaml index a3e960c6f..9dbd1ea6b 100644 --- a/tests/test-cases/atmos-functions.yaml +++ b/tests/test-cases/atmos-functions.yaml @@ -6,8 +6,9 @@ tests: workdir: "fixtures/scenarios/atmos-functions/" command: "atmos" args: - - "workflow" + - "terraform" - "deploy" + - "component-4" - "-s" - "nonprod" skip: @@ -29,8 +30,9 @@ tests: workdir: "fixtures/scenarios/atmos-functions/" command: "atmos" args: - - "workflow" + - "terraform" - "deploy" + - "component-4" - "-s" - "nonprod" expect: From bfc24515d19025ada8961fa6861aa1c243a5b483 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Sun, 9 Feb 2025 14:57:20 +0000 Subject: [PATCH 18/22] update main tf --- .../components/terraform/mock/main.tf | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/tests/fixtures/components/terraform/mock/main.tf b/tests/fixtures/components/terraform/mock/main.tf index bc787c0a6..236ce8896 100644 --- a/tests/fixtures/components/terraform/mock/main.tf +++ b/tests/fixtures/components/terraform/mock/main.tf @@ -1,29 +1,3 @@ -terraform { - required_providers { - local = { - source = "hashicorp/local" - version = ">= 2.0.0" - } - } -} - -variable "environment" { - type = string -} - -variable "stage" { - type = string -} - -variable "tenant" { - type = string -} - -resource "local_file" "test" { - content = "test-${var.environment}" - filename = "./test.txt" -} - variable "foo" { type = string default = "foo" From adcf46ef3df5b2469a92082d1ec5e475dc1a2f71 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Sun, 9 Feb 2025 15:39:50 +0000 Subject: [PATCH 19/22] update tf main --- .../fixtures/components/terraform/mock/main.tf | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/fixtures/components/terraform/mock/main.tf b/tests/fixtures/components/terraform/mock/main.tf index 236ce8896..50709c2ba 100644 --- a/tests/fixtures/components/terraform/mock/main.tf +++ b/tests/fixtures/components/terraform/mock/main.tf @@ -1,3 +1,12 @@ +terraform { + required_providers { + random = { + source = "hashicorp/random" + version = ">= 3.0.0" + } + } +} + variable "foo" { type = string default = "foo" @@ -13,6 +22,11 @@ variable "baz" { default = "baz" } +# Add a random string just to ensure the provider is used +resource "random_string" "test" { + length = 8 +} + output "foo" { value = var.foo } @@ -24,3 +38,7 @@ output "bar" { output "baz" { value = var.baz } + +output "random_string" { + value = random_string.test.result +} From 9b53fa6ef81d00b277b075e8bce0607db07f7028 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Sun, 9 Feb 2025 18:12:54 +0000 Subject: [PATCH 20/22] add variables --- tests/fixtures/components/terraform/mock/main.tf | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/fixtures/components/terraform/mock/main.tf b/tests/fixtures/components/terraform/mock/main.tf index 50709c2ba..86116d84f 100644 --- a/tests/fixtures/components/terraform/mock/main.tf +++ b/tests/fixtures/components/terraform/mock/main.tf @@ -7,6 +7,21 @@ terraform { } } +variable "environment" { + type = string + description = "Environment name" +} + +variable "stage" { + type = string + description = "Stage name" +} + +variable "tenant" { + type = string + description = "Tenant name" +} + variable "foo" { type = string default = "foo" From 517276063026cc06ae20ab9c6303e6ddfdf479ac Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Tue, 11 Feb 2025 08:50:13 +0000 Subject: [PATCH 21/22] fix fixture file --- pkg/stack/stack_processor_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/stack/stack_processor_test.go b/pkg/stack/stack_processor_test.go index 672c1c1b0..5cc1be67c 100644 --- a/pkg/stack/stack_processor_test.go +++ b/pkg/stack/stack_processor_test.go @@ -242,6 +242,11 @@ func TestStackProcessorRelativePaths(t *testing.T) { components := mapConfig1["components"].(map[string]any) terraformComponents := components["terraform"].(map[string]any) - myappComponent := terraformComponents["myapp"].(map[string]any) - assert.NotNil(t, myappComponent) + randomComponent := terraformComponents["random"].(map[string]any) + assert.NotNil(t, randomComponent) + + // Verify the expected variables are present + vars := randomComponent["vars"].(map[string]any) + assert.Equal(t, "dev", vars["stage"]) + assert.Equal(t, "ue2", vars["environment"]) } From 0701ec7b6eb5199f276fbe7f7c8952bc049252a4 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Tue, 11 Feb 2025 09:23:02 +0000 Subject: [PATCH 22/22] increase timeout --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b6f91d7d7..7b889c384 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,6 @@ deps: # Run acceptance tests testacc: get - go test $(TEST) -v $(TESTARGS) -timeout 10m + go test $(TEST) -v $(TESTARGS) -timeout 15m .PHONY: lint get build version build-linux build-windows build-macos deps version-linux version-windows version-macos testacc