Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supported the atmos.d, allowing automatic inclusion of configuration files from the atmos.d directory #808

Open
wants to merge 65 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
892cfeb
feat: add support for importing configurations from local and remote …
haitham911 Nov 24, 2024
052673b
refactor: streamline configuration initialization and enhance import …
haitham911 Nov 24, 2024
63ffce1
fix: sort full matches instead of initial matches in GetGlobMatches f…
haitham911 Nov 24, 2024
000e439
fix: add json and mapstructure tags to Import field in CliConfiguration
haitham911 Nov 24, 2024
4493540
fix: handle unexpected errors when checking for atmos.d path in InitC…
haitham911 Nov 24, 2024
d1903c4
fix: update atmos.yaml to include wildcard import for YAML files and …
haitham911 Nov 24, 2024
d9a3517
fix: remove obsolete configuration files and update atmos.yaml for cl…
haitham911 Nov 24, 2024
089a82f
fix: validate import paths to prevent directory traversal in InitCliC…
haitham911 Nov 24, 2024
c020d63
fix: enhance downloadRemoteConfig to return temporary directory and h…
haitham911 Nov 24, 2024
31c844c
fix: remove environment variable from extra-config.yaml for cleaner c…
haitham911 Nov 30, 2024
d70f66f
feat: update YAML configurations to define commands and enhance compo…
haitham911 Dec 3, 2024
512e02e
fix: replace path package with filepath for consistent path handling
haitham911 Dec 3, 2024
c22624f
Merge branch 'main' into DEV-1534
osterman Dec 4, 2024
750f4b5
feat: enhance CLI configuration loading logic to prioritize ATMOS_CLI…
haitham911 Dec 7, 2024
8eeda00
feat: reorganize configuration files and enhance YAML support for log…
haitham911 Dec 11, 2024
a8d3528
feat: rename environment variable for clarity and improve test handli…
haitham911 Dec 11, 2024
d8a00ef
feat: update remote configuration URL in atmos.yaml for improved acce…
haitham911 Dec 11, 2024
8050589
feat: restructure configuration files and remove deprecated logging s…
haitham911 Dec 11, 2024
52b170d
feat: migrate custom import configuration files to a new structure fo…
haitham911 Dec 11, 2024
f85d53e
feat: remove deprecated custom import configuration files and update …
haitham911 Dec 11, 2024
73d9255
feat: add URL validation for remote imports to enhance error handling
haitham911 Dec 12, 2024
9913b54
feat: update configuration documentation to clarify CLI config loadin…
haitham911 Dec 12, 2024
cdb9fa1
fix: correct example paths in CLI configuration documentation for cla…
haitham911 Dec 12, 2024
7090975
fix: clarify environment variable usage in CLI configuration document…
haitham911 Dec 12, 2024
3dfb2e0
Update examples/demo-atmos-cli-imports/configs.d/vendor.yaml
osterman Dec 12, 2024
cdafe20
enhance CLI configuration documentation with detailed import examples…
haitham911 Dec 13, 2024
b702884
fix: improve atmos.d path validation and add support for .atmos.d dir…
haitham911 Dec 13, 2024
8704668
fix: update command in demo configuration and improve URL validation …
haitham911 Dec 13, 2024
989cd9e
Merge branch 'main' into DEV-1534
haitham911 Dec 17, 2024
a7414bb
add env demo
haitham911 Dec 17, 2024
3a24ee6
expose env variable ATMOS_CLI_CONFIG_PATH and ATMOS_BASE_PATH before…
haitham911 Dec 18, 2024
061ba9c
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
e57aacb
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
e6a3200
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
fa5f25e
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
86e2505
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
95cdf74
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
bc2c4bc
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
8e6998a
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
87d4b0f
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
31d71c1
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
e64d2eb
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
378897c
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
e8d8507
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
6e4bc4d
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
930fde6
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
94e99d6
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
85957a4
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
b75c251
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
a742412
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
30c82d2
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
0609a78
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
1c02902
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
792ff0a
Apply suggestions from code review
osterman Dec 20, 2024
33da5d0
Apply suggestions from code review
osterman Dec 20, 2024
885bd00
Apply suggestions from code review
osterman Dec 20, 2024
b933331
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 20, 2024
50cd50e
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 30, 2024
aafdf16
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 30, 2024
3bb33fa
Update examples/demo-env/stacks/deploy/prod.yaml
osterman Dec 30, 2024
a55f6f2
Update website/docs/cli/configuration/configuration.mdx
osterman Dec 30, 2024
66c0a59
Apply suggestions from code review
osterman Dec 30, 2024
27d3acd
Apply suggestions from code review
osterman Dec 30, 2024
1d46232
revise the docs for intended behavior
osterman Dec 30, 2024
9a27195
Make it more clear
osterman Dec 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ jobs:
# - demo-component-manifest
- demo-component-versions
- demo-context
- demo-configuration
# - demo-custom-command
# - demo-json-validation
# - demo-opa-validation
Expand Down
9 changes: 9 additions & 0 deletions examples/demo-atmos-cli-imports/atmos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Description: This is an example of a custom import configuration file.
# The import configuration file is used to load configurations from multiple files and directories.
# The configurations are merged together to create a single configuration object.
# The configurations are loaded in the order they are defined in the import section.
base_path: "./"
import:
- "https://raw.githubusercontent.com/cloudposse/atmos/refs/heads/main/atmos.yaml" # Load from a remote URL
osterman marked this conversation as resolved.
Show resolved Hide resolved
- "configs.d/**/*" # Recursively load configurations from a directory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

STRENGTHEN YOUR DEFENSES WITH SPECIFIC PATTERNS!

The recursive glob pattern configs.d/**/* might include unwanted files. Consider being more specific about file extensions.

- "configs.d/**/*"
+ "configs.d/**/*.{yaml,yml}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- "configs.d/**/*" # Recursively load configurations from a directory
- "configs.d/**/*.{yaml,yml}" # Recursively load configurations from a directory

- "./logs.yaml" # Load a specific file
7 changes: 7 additions & 0 deletions examples/demo-atmos-cli-imports/configs.d/commands.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Custom CLI commands
commands:
- name: "test"
description: "Run all tests"
steps:
- atmos describe config

7 changes: 7 additions & 0 deletions examples/demo-atmos-cli-imports/configs.d/tools/stack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
stacks:
base_path: "stacks"
included_paths:
- "deploy/**/*"
excluded_paths:
- "**/_defaults.yaml"
name_pattern: "{dev}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
components:
terraform:
base_path: "components/terraform"
apply_auto_approve: true
osterman marked this conversation as resolved.
Show resolved Hide resolved
deploy_run_init: true
init_run_reconfigure: true
auto_generate_backend_file: false
9 changes: 9 additions & 0 deletions examples/demo-atmos-cli-imports/configs.d/vendor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
vendor:
# Single file
base_path: "./vendor.yaml"

# Directory with multiple files
#base_path: "./vendor"

# Absolute path
#base_path: "vendor.d/vendor1.yaml"
3 changes: 3 additions & 0 deletions examples/demo-atmos-cli-imports/logs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
logs:
file: "/dev/stderr"
level: Debug
6 changes: 6 additions & 0 deletions examples/demo-configuration/atmos.d/commands.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Custom CLI commands
commands:
- name: "test"
description: "Run all tests with custom command"
steps:
- atmos describe config
3 changes: 3 additions & 0 deletions examples/demo-configuration/atmos.d/logs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
logs:
file: "/dev/stderr"
level: Debug
17 changes: 17 additions & 0 deletions examples/demo-configuration/atmos.d/tools/helmfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
components:
helmfile:
# Can also be set using 'ATMOS_COMPONENTS_HELMFILE_BASE_PATH' ENV var, or '--helmfile-dir' command-line argument
# Supports both absolute and relative paths
base_path: "components/helmfile"
# Can also be set using 'ATMOS_COMPONENTS_HELMFILE_USE_EKS' ENV var
# If not specified, defaults to 'true'
use_eks: true
# Can also be set using 'ATMOS_COMPONENTS_HELMFILE_KUBECONFIG_PATH' ENV var
kubeconfig_path: "/dev/shm"
# Can also be set using 'ATMOS_COMPONENTS_HELMFILE_HELM_AWS_PROFILE_PATTERN' ENV var
helm_aws_profile_pattern: "{namespace}-{tenant}-gbl-{stage}-helm"
# Can also be set using 'ATMOS_COMPONENTS_HELMFILE_CLUSTER_NAME_PATTERN' ENV var
cluster_name_pattern: "{namespace}-{tenant}-{environment}-{stage}-eks-cluster"



7 changes: 7 additions & 0 deletions examples/demo-configuration/atmos.d/tools/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
stacks:
base_path: "stacks"
included_paths:
- "deploy/**/*"
excluded_paths:
- "**/_defaults.yaml"
name_pattern: "{dev}"
23 changes: 23 additions & 0 deletions examples/demo-configuration/atmos.d/tools/terraform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
components:
terraform:
# Optional `command` specifies the executable to be called by `atmos` when running Terraform commands
# If not defined, `terraform` is used
# Examples:
# command: terraform
# command: /usr/local/bin/terraform
# command: /usr/local/bin/terraform-1.8
# command: tofu
# command: /usr/local/bin/tofu-1.7.1
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_COMMAND' ENV var, or '--terraform-command' command-line argument
command: terraform
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_BASE_PATH' ENV var, or '--terraform-dir' command-line argument
# Supports both absolute and relative paths
base_path: "components/terraform"
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_APPLY_AUTO_APPROVE' ENV var
apply_auto_approve: false
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_DEPLOY_RUN_INIT' ENV var, or '--deploy-run-init' command-line argument
deploy_run_init: true
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_INIT_RUN_RECONFIGURE' ENV var, or '--init-run-reconfigure' command-line argument
init_run_reconfigure: true
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_AUTO_GENERATE_BACKEND_FILE' ENV var, or '--auto-generate-backend-file' command-line argument
auto_generate_backend_file: true
5 changes: 5 additions & 0 deletions examples/demo-configuration/atmos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Description: Configuration file for the Atmos CLI
# default import path is ./atmos.d import .yaml files from the directory and merge them
base_path: "./"


Comment on lines +1 to +5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add configuration examples for atmos.d features.

The file should demonstrate the new features mentioned in the PR objectives, particularly:

  • Custom atmos.d path configuration
  • Import configurations
  • URL imports

Here's a suggested structure:

# Description: Configuration file for the Atmos CLI
# 
# Features:
# - Automatically imports and merges .yaml files from ./atmos.d directory
# - Processes files in lexicographical order
# - Supports glob patterns for file matching
# - Enables deep merging of configurations

# Base path for resolving relative paths in configurations
base_path: "./"

# Custom atmos.d directory path (optional)
atmos_d_path: "./atmos.d"

# Additional import configurations (optional)
import:
  # Local files and directories
  - path: "./configs/*.yaml"
  # Remote configurations
  - url: "https://example.com/shared-config.yaml"
🧰 Tools
🪛 yamllint (1.35.1)

[error] 5-5: trailing spaces

(trailing-spaces)

Comment on lines +4 to +5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Clean up file structure.

Remove trailing spaces and normalize empty lines.

 base_path: "./"
-
-  
🧰 Tools
🪛 yamllint (1.35.1)

[error] 5-5: trailing spaces

(trailing-spaces)

21 changes: 21 additions & 0 deletions examples/demo-env/atmos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
base_path: "./"

components:
terraform:
base_path: "components/terraform"
apply_auto_approve: false
deploy_run_init: true
init_run_reconfigure: true
auto_generate_backend_file: false

stacks:
base_path: "stacks"
included_paths:
- "deploy/**/*"
excluded_paths:
- "**/_defaults.yaml"
name_pattern: "{stage}"

logs:
file: "/dev/stderr"
level: Info
4 changes: 4 additions & 0 deletions examples/demo-env/components/terraform/example/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Fetch the required environment variables using the `environment_variables` data source
data "environment_variables" "required" {
filter = "ATMOS_.*" # Fetches all variables starting with "ATMOS_"
}
15 changes: 15 additions & 0 deletions examples/demo-env/components/terraform/example/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Output environment variables
output "atmos_cli_config_path" {
value = data.environment_variables.required.items["ATMOS_CLI_CONFIG_PATH"]
description = "The path to the Atmos CLI configuration file"
}

output "atmos_base_path" {
value = data.environment_variables.required.items["ATMOS_BASE_PATH"]
description = "The base path used by Atmos"
}

output "example" {
value = data.environment_variables.required.items["EXAMPLE"]
description = "Example environment variable"
}
10 changes: 10 additions & 0 deletions examples/demo-env/stacks/catalog/example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json
env:
EXAMPLE: "test"

components:
terraform:
example:
metadata:
component: example
vars: {}
12 changes: 12 additions & 0 deletions examples/demo-env/stacks/deploy/dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json

vars:
stage: dev

import:
- catalog/example
Comment on lines +6 to +7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

⚠️ The catalog import path needs attention

The import statement catalog/example doesn't match the actual catalog structure. The catalog directory contains only station.yaml, but no example.yaml file.

  • The import statement in examples/demo-env/stacks/deploy/dev.yaml references catalog/example
  • The actual catalog contains only station.yaml

Consider either:

  • Updating the import to catalog/station to match the existing file
  • Creating the missing example.yaml file in the catalog directory
🔗 Analysis chain

WELL STRUCTURED! Let's verify the catalog import.

The import statement follows the new atmos.d convention. However, let's verify the catalog structure.


The previous command failed because the catalog directory wasn't found. Let's first check the directory structure and then look for any example configuration files to understand the correct path.


We found multiple catalog directories, but we need to focus on the one in demo-env since that's where our import statement is located. Let's verify its contents.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the existence and structure of the catalog
fd -t f "example.yaml" -p "catalog/"

Length of output: 130


Script:

#!/bin/bash
# Let's try a broader search to understand the catalog structure
fd "catalog" --type directory
fd "example" --type file

Length of output: 649


Script:

#!/bin/bash
# Let's check the content of the catalog directory in demo-env specifically
ls -la examples/demo-env/stacks/catalog/
# And look for any yaml files that might be our target
fd -t f ".yaml$" -p "examples/demo-env/stacks/catalog/"

Length of output: 314


components:
terraform:
example:
vars: {}
12 changes: 12 additions & 0 deletions examples/demo-env/stacks/deploy/prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json

vars:
stage: prod

import:
- catalog/example

components:
terraform:
example:
vars: {}
12 changes: 12 additions & 0 deletions examples/demo-env/stacks/deploy/staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json

vars:
stage: staging

import:
- catalog/example

components:
terraform:
example:
vars: {}
2 changes: 2 additions & 0 deletions internal/exec/helmfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ func ExecuteHelmfile(info schema.ConfigAndStacksInfo) error {
if cliConfig.Components.Helmfile.UseEKS {
envVars = append(envVars, envVarsEKS...)
}
envVars = append(envVars, fmt.Sprintf("ATMOS_CLI_CONFIG_PATH=%s", cliConfig.CliConfigPath))
envVars = append(envVars, fmt.Sprintf("ATMOS_BASE_PATH=%s", cliConfig.BasePath))

u.LogTrace(cliConfig, "Using ENV vars:")
for _, v := range envVars {
Expand Down
2 changes: 2 additions & 0 deletions internal/exec/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error {
}
}

info.ComponentEnvList = append(info.ComponentEnvList, fmt.Sprintf("ATMOS_CLI_CONFIG_PATH=%s", cliConfig.CliConfigPath))
info.ComponentEnvList = append(info.ComponentEnvList, fmt.Sprintf("ATMOS_BASE_PATH=%s", cliConfig.BasePath))
// Set `TF_IN_AUTOMATION` ENV var to `true` to suppress verbose instructions after terraform commands
// https://developer.hashicorp.com/terraform/cli/config/environment-variables#tf_in_automation
info.ComponentEnvList = append(info.ComponentEnvList, "TF_IN_AUTOMATION=true")
Expand Down
Loading