Skip to content

Commit

Permalink
Update atmos validate stacks command (#611)
Browse files Browse the repository at this point in the history
* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates
  • Loading branch information
aknysh authored May 29, 2024
1 parent 3e0983a commit 6f7a5dd
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 56 deletions.
2 changes: 1 addition & 1 deletion examples/quick-start/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 58 additions & 7 deletions internal/exec/validate_stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package exec
import (
"fmt"
"path"
"reflect"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down
41 changes: 34 additions & 7 deletions website/docs/cli/commands/validate/validate-stacks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```
<Terminal title="atmos validate stacks">
```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)
```
</Terminal>

<br/>

Expand Down
39 changes: 0 additions & 39 deletions website/docs/core-concepts/stacks/validation.md

This file was deleted.

68 changes: 68 additions & 0 deletions website/docs/core-concepts/stacks/validation.mdx
Original file line number Diff line number Diff line change
@@ -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
```

<br/>

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:

<Terminal title="atmos validate stacks">
```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)
```
</Terminal>

<br/>

:::tip
For more details, refer to [`atmos validate stacks`](/cli/commands/validate/stacks) CLI command
:::
2 changes: 1 addition & 1 deletion website/docs/integrations/atlantis.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ on:
branches: [ main ]
env:
ATMOS_VERSION: 1.76.0
ATMOS_VERSION: 1.77.0
ATMOS_CLI_CONFIG_PATH: ./
jobs:
Expand Down
2 changes: 1 addition & 1 deletion website/docs/integrations/github-actions/setup-atmos.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

0 comments on commit 6f7a5dd

Please sign in to comment.