From 6f7a5dd68730e894a3d9cb5ecdf1490008039492 Mon Sep 17 00:00:00 2001 From: Andriy Knysh Date: Wed, 29 May 2024 12:11:11 -0400 Subject: [PATCH] Update `atmos validate stacks` command (#611) * updates * updates * updates * updates * updates * updates * updates * updates --- examples/quick-start/Dockerfile | 2 +- internal/exec/validate_stacks.go | 65 ++++++++++++++++-- .../cli/commands/validate/validate-stacks.mdx | 41 +++++++++-- .../docs/core-concepts/stacks/validation.md | 39 ----------- .../docs/core-concepts/stacks/validation.mdx | 68 +++++++++++++++++++ website/docs/integrations/atlantis.mdx | 2 +- .../github-actions/setup-atmos.md | 2 +- 7 files changed, 163 insertions(+), 56 deletions(-) delete mode 100644 website/docs/core-concepts/stacks/validation.md create mode 100644 website/docs/core-concepts/stacks/validation.mdx diff --git a/examples/quick-start/Dockerfile b/examples/quick-start/Dockerfile index 9ebd41ef4..4fd013126 100644 --- a/examples/quick-start/Dockerfile +++ b/examples/quick-start/Dockerfile @@ -6,7 +6,7 @@ ARG GEODESIC_OS=debian # https://atmos.tools/ # https://github.com/cloudposse/atmos # https://github.com/cloudposse/atmos/releases -ARG ATMOS_VERSION=1.76.0 +ARG ATMOS_VERSION=1.77.0 # Terraform: https://github.com/hashicorp/terraform/releases ARG TF_VERSION=1.8.4 diff --git a/internal/exec/validate_stacks.go b/internal/exec/validate_stacks.go index 2fb69e468..9b9a038cc 100644 --- a/internal/exec/validate_stacks.go +++ b/internal/exec/validate_stacks.go @@ -3,6 +3,7 @@ package exec import ( "fmt" "path" + "reflect" "strings" "github.com/pkg/errors" @@ -272,13 +273,63 @@ func checkComponentStackMap(componentStackMap map[string]map[string][]string) ([ for componentName, componentSection := range componentStackMap { for stackName, stackManifests := range componentSection { if len(stackManifests) > 1 { - m := fmt.Sprintf("the Atmos component '%s' in the stack '%s' is defined in more than one top-level stack manifest file: %s.\n"+ - "Atmos can't decide which stack manifest to use to get configuration for the component in the stack.\n"+ - "This is a stack misconfiguration.", - componentName, - stackName, - strings.Join(stackManifests, ", ")) - res = append(res, m) + // We have the same Atmos component in the same stack configured (or imported) in more than one stack manifest files + // Check if the component configs are the same (deep-equal) in those stack manifests. + // If the configs are different, add it to the errors + var componentConfigs []map[string]any + for _, stackManifestName := range stackManifests { + componentConfig, err := ExecuteDescribeComponent(componentName, stackManifestName) + if err != nil { + return nil, err + } + + // Hide the sections that should not be compared + componentConfig["atmos_cli_config"] = nil + componentConfig["atmos_stack"] = nil + componentConfig["atmos_stack_file"] = nil + componentConfig["sources"] = nil + componentConfig["imports"] = nil + componentConfig["deps_all"] = nil + componentConfig["deps"] = nil + + componentConfigs = append(componentConfigs, componentConfig) + } + + componentConfigsEqual := true + + for i := 0; i < len(componentConfigs)-1; i++ { + if !reflect.DeepEqual(componentConfigs[i], componentConfigs[i+1]) { + componentConfigsEqual = false + break + } + } + + if !componentConfigsEqual { + var m1 string + for _, stackManifestName := range stackManifests { + m1 = m1 + "\n" + fmt.Sprintf("- atmos describe component %s -s %s", componentName, stackManifestName) + } + + m := fmt.Sprintf("The Atmos component '%[1]s' in the stack '%[2]s' is defined in more than one top-level stack manifest file: %[3]s.\n\n"+ + "The component configurations in the stack manifests are different.\n\n"+ + "To check and compare the component configurations in the stack manifests, run the following commands: %[4]s\n\n"+ + "You can use the '--file' flag to write the results of the above commands to files (refer to https://atmos.tools/cli/commands/describe/component).\n"+ + "You can then use the Linux 'diff' command to compare the files line by line and show the differences (refer to https://man7.org/linux/man-pages/man1/diff.1.html)\n\n"+ + "When searching for the component '%[1]s' in the stack '%[2]s', Atmos can't decide which stack "+ + "manifest file to use to get configuration for the component.\n"+ + "This is a stack misconfiguration.\n\n"+ + "Consider the following solutions to fix the issue:\n"+ + "- Ensure that the same instance of the Atmos '%[1]s' component in the stack '%[2]s' is only defined once (in one YAML stack manifest file)\n"+ + "- When defining multiple instances of the same component in the stack, ensure each has a unique name\n"+ + "- Use multiple-inheritance to combine multiple configurations together (refer to https://atmos.tools/core-concepts/components/inheritance)\n\n", + componentName, + stackName, + strings.Join(stackManifests, ", "), + m1, + ) + + res = append(res, m) + } } } } diff --git a/website/docs/cli/commands/validate/validate-stacks.mdx b/website/docs/cli/commands/validate/validate-stacks.mdx index 58cfe5059..fed318211 100644 --- a/website/docs/cli/commands/validate/validate-stacks.mdx +++ b/website/docs/cli/commands/validate/validate-stacks.mdx @@ -35,14 +35,41 @@ This command validates Atmos stack manifests and checks the following: - Schema: if all sections in all YAML manifest files are correctly configured and have valid data types - Misconfiguration and duplication of components in stacks. If the same Atmos component in the same Atmos stack is - defined in more than one stack manifest file, an error message will be displayed similar to the following: + defined in more than one stack manifest file, and the component configurations are different, an error message will + be displayed similar to the following: - ```console - the Atmos component 'vpc' in the stack 'plat-ue2-dev' is defined in more than one top-level stack - manifest file: orgs/acme/plat/dev/us-east-2, orgs/acme/plat/dev/us-east-2-extras. - Atmos can't decide which stack manifest to use to get configuration for the component - in the stack. This is a stack misconfiguration. - ``` + + ```console + The Atmos component 'vpc' in the stack 'plat-ue2-dev' is defined in more than one + top-level stack manifest file: orgs/acme/plat/dev/us-east-2-extras, orgs/acme/plat/dev/us-east-2. + + The component configurations in the stack manifests are different. + + To check and compare the component configurations in the stack manifests, run the following commands: + - atmos describe component vpc -s orgs/acme/plat/dev/us-east-2-extras + - atmos describe component vpc -s orgs/acme/plat/dev/us-east-2 + + You can use the '--file' flag to write the results of the above commands to files + (refer to https://atmos.tools/cli/commands/describe/component). + + You can then use the Linux 'diff' command to compare the files line by line and show the differences + (refer to https://man7.org/linux/man-pages/man1/diff.1.html) + + When searching for the component 'vpc' in the stack 'plat-ue2-dev', Atmos can't decide which + stack manifest file to use to get configuration for the component. This is a stack misconfiguration. + + Consider the following solutions to fix the issue: + + - Ensure that the same instance of the Atmos 'vpc' component in the stack 'plat-ue2-dev' + is only defined once (in one YAML stack manifest file) + + - When defining multiple instances of the same component in the stack, + ensure each has a unique name + + - Use multiple-inheritance to combine multiple configurations together + (refer to https://atmos.tools/core-concepts/components/inheritance) + ``` +
diff --git a/website/docs/core-concepts/stacks/validation.md b/website/docs/core-concepts/stacks/validation.md deleted file mode 100644 index c89f5950f..000000000 --- a/website/docs/core-concepts/stacks/validation.md +++ /dev/null @@ -1,39 +0,0 @@ ---- -title: Stack Validation -sidebar_position: 2 -sidebar_label: Validation -description: Validate all Stack configurations and YAML syntax. -id: validation ---- - -To validate all Stack configurations and YAML syntax, execute the `validate stacks` command: - -```shell -atmos validate stacks -``` - -
- -The command checks and validates the following: - -- All YAML manifest files for YAML errors and inconsistencies - -- All imports: if they are configured correctly, have valid data types, and point to existing manifest files - -- Schema: if all sections in all YAML manifest files are correctly configured and have valid data types - -- Misconfiguration and duplication of components in stacks. If the same Atmos component in the same Atmos stack is - defined in more than one stack manifest file, an error message will be displayed similar to the following: - - ```console - the Atmos component 'vpc' in the stack 'plat-ue2-dev' is defined in more than one top-level stack - manifest file: orgs/acme/plat/dev/us-east-2, orgs/acme/plat/dev/us-east-2-extras. - Atmos can't decide which stack manifest to use to get configuration for the component - in the stack. This is a stack misconfiguration. - ``` - -
- -:::tip -For more details, refer to [`atmos validate stacks`](/cli/commands/validate/stacks) CLI command -::: diff --git a/website/docs/core-concepts/stacks/validation.mdx b/website/docs/core-concepts/stacks/validation.mdx new file mode 100644 index 000000000..72e663b10 --- /dev/null +++ b/website/docs/core-concepts/stacks/validation.mdx @@ -0,0 +1,68 @@ +--- +title: Stack Validation +sidebar_position: 2 +sidebar_label: Validation +description: Validate all Stack configurations and YAML syntax. +id: validation +--- + +import Terminal from '@site/src/components/Terminal' + +To validate all Stack configurations and YAML syntax, execute the `validate stacks` command: + +```shell +atmos validate stacks +``` + +
+ +The command checks and validates the following: + +- All YAML manifest files for YAML errors and inconsistencies + +- All imports: if they are configured correctly, have valid data types, and point to existing manifest files + +- Schema: if all sections in all YAML manifest files are correctly configured and have valid data types + +- Misconfiguration and duplication of components in stacks. If the same Atmos component in the same Atmos stack is + defined in more than one stack manifest file, and the component configurations are different, an error message will + be displayed similar to the following: + + + ```console + The Atmos component 'vpc' in the stack 'plat-ue2-dev' is defined in more than one + top-level stack manifest file: orgs/acme/plat/dev/us-east-2-extras, orgs/acme/plat/dev/us-east-2. + + The component configurations in the stack manifests are different. + + To check and compare the component configurations in the stack manifests, run the following commands: + - atmos describe component vpc -s orgs/acme/plat/dev/us-east-2-extras + - atmos describe component vpc -s orgs/acme/plat/dev/us-east-2 + + You can use the '--file' flag to write the results of the above commands to files + (refer to https://atmos.tools/cli/commands/describe/component). + + You can then use the Linux 'diff' command to compare the files line by line and show the differences + (refer to https://man7.org/linux/man-pages/man1/diff.1.html) + + When searching for the component 'vpc' in the stack 'plat-ue2-dev', Atmos can't decide which + stack manifest file to use to get configuration for the component. This is a stack misconfiguration. + + Consider the following solutions to fix the issue: + + - Ensure that the same instance of the Atmos 'vpc' component in the stack 'plat-ue2-dev' + is only defined once (in one YAML stack manifest file) + + - When defining multiple instances of the same component in the stack, + ensure each has a unique name + + - Use multiple-inheritance to combine multiple configurations together + (refer to https://atmos.tools/core-concepts/components/inheritance) + ``` + + +
+ +:::tip +For more details, refer to [`atmos validate stacks`](/cli/commands/validate/stacks) CLI command +::: diff --git a/website/docs/integrations/atlantis.mdx b/website/docs/integrations/atlantis.mdx index 161526711..26c734818 100644 --- a/website/docs/integrations/atlantis.mdx +++ b/website/docs/integrations/atlantis.mdx @@ -687,7 +687,7 @@ on: branches: [ main ] env: - ATMOS_VERSION: 1.76.0 + ATMOS_VERSION: 1.77.0 ATMOS_CLI_CONFIG_PATH: ./ jobs: diff --git a/website/docs/integrations/github-actions/setup-atmos.md b/website/docs/integrations/github-actions/setup-atmos.md index da4e2fd82..170f95fce 100644 --- a/website/docs/integrations/github-actions/setup-atmos.md +++ b/website/docs/integrations/github-actions/setup-atmos.md @@ -27,5 +27,5 @@ jobs: uses: cloudposse/github-action-setup-atmos with: # Make sure to pin to the latest version of atmos - atmos_version: 1.76.0 + atmos_version: 1.77.0 ```