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

Improve terraform and helmfile help. Enable Go templating in the command field. Clean Terraform workspace before executing terraform init #759

Merged
merged 3 commits into from
Nov 2, 2024

Conversation

aknysh
Copy link
Member

@aknysh aknysh commented Nov 2, 2024

what

  • Improve terraform and helmfile help
  • Enable Go templating in the command field of stack config
  • Clean Terraform workspace before executing terraform init

why

  • Improve the help messages. When a user executes atmos terraform --help or atmos helmfile --help (or help for a subcommand), print a message describing the command and how to execute the terraform and helmfile help command

     atmos terraform --help

image


  • Enable Go templating in the command stack config in addition to the already supported sections.

    You can now use Go templates in the following Atmos sections to refer to values in the same or other sections:

    • vars
    • settings
    • env
    • providers
    • overrides
    • backend
    • backend_type
    • component
    • metadata.component
    • command

    Enabling Go templates in the command section allows specifying different Terraform/OpenTofu/Helmfile versions per component/stack, and get the value from different Atmos sections or from external data sources

  • Clean Terraform workspace before executing terraform init. When using multiple backends for the same component (e.g. separate backends per tenant or account), and if an Atmos command was executed that selected a Terraform workspace, Terraform will prompt the user to select one of the following workspaces:

     1. default
     2. <the previously used workspace>

    The prompt forces the user to always make a selection (which is error-prone), and also makes it complicated when running on CI/CD.

    The PR adds the logic that deletes the .terraform/environment file from the component directory before executing terraform init. The .terraform/environment file contains the name of the currently selected workspace, helping Terraform identify the active workspace context for managing your infrastructure. We delete the file before executing terraform init to prevent the Terraform prompt asking to select the default or the previously used workspace.

Summary by CodeRabbit

  • New Features

    • Updated Atmos tool version to 1.100.0.
    • Introduced a new function to clean Terraform workspace files.
  • Bug Fixes

    • Enhanced error handling and processing logic for commands and configurations.
  • Documentation

    • Improved clarity and detail in the "Stack Manifest Templating" and "Atlantis Integration" documentation.
  • Chores

    • Updated various dependencies to their latest versions for improved compatibility and performance.

@aknysh aknysh added the minor New features that do not break anything label Nov 2, 2024
@aknysh aknysh requested a review from osterman November 2, 2024 15:15
@aknysh aknysh self-assigned this Nov 2, 2024
@aknysh aknysh requested review from a team as code owners November 2, 2024 15:15
@aknysh aknysh requested review from hans-d and joe-niland November 2, 2024 15:15
Copy link
Contributor

coderabbitai bot commented Nov 2, 2024

Walkthrough

This pull request includes updates to multiple files, primarily focusing on version upgrades for dependencies and enhancements to functionality and documentation related to the Atmos tool. Key changes involve updating the Atmos version in the Dockerfile, modifying various Go module dependencies, improving help message formatting, reintroducing Terraform initialization logic, and adding a new function for cleaning the Terraform workspace. Additionally, documentation has been refined to clarify templating configurations and the Atlantis integration process.

Changes

File Path Change Summary
examples/quick-start-advanced/Dockerfile Updated ATMOS_VERSION from 1.99.0 to 1.100.0.
go.mod Multiple dependency version updates, including github.com/charmbracelet/lipgloss to v1.0.0, github.com/open-policy-agent/opa to v0.70.0, and others.
internal/exec/help.go Modified help messages to capitalize "Atmos" consistently; no changes to logic.
internal/exec/terraform.go Reinstated terraform init logic; added file deletion for clean state; refined command argument handling.
internal/exec/terraform_utils.go Added cleanTerraformWorkspace function to delete .terraform/environment file.
internal/exec/utils.go Enhanced error handling and processing logic; updated comments for clarity.
pkg/utils/file_utils.go Renamed variable in IsURL function for clarity; minor formatting changes in GetFileNameFromURL.
website/docs/core-concepts/stacks/templates/templates.mdx Refined documentation on templating configuration for Atmos stack manifests; added new entries and examples.
website/docs/integrations/atlantis.mdx Updated Atlantis integration documentation; emphasized settings.atlantis for configuration.
website/package.json Updated posthog-js dependency version from ^1.178.0 to ^1.180.1.

Possibly related PRs

Suggested labels

patch

Suggested reviewers

  • gberenice
  • osterman

Poem

🐰 In the garden where changes bloom,
Atmos rises, dispelling gloom.
With versions fresh and docs refined,
A brighter path for all to find.
So hop along, let’s celebrate,
For progress made, we can’t be late! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
internal/exec/help.go (1)

Line range hint 18-111: Consider documenting new features in help messages.

Given the PR objectives include new features like Go templating in the command field and Terraform workspace cleaning, consider adding documentation for these features in the relevant help sections:

  1. Add information about Go templating capabilities in the command field, explaining available template variables (vars, settings, env, etc.).
  2. Enhance the Terraform workspace documentation to explain the new workspace cleaning behavior before terraform init.

Example addition for the Terraform section:

 u.PrintMessage(" - before executing other 'terraform' commands, 'atmos' runs 'terraform init'")
+u.PrintMessage(" - before running 'terraform init', Atmos cleans the workspace by removing '.terraform/environment' to prevent backend selection prompts")
+u.PrintMessage(" - the 'command' field supports Go templating with access to vars, settings, env, providers, and other configuration values")
website/docs/core-concepts/stacks/templates/templates.mdx (1)

247-247: LGTM! Consider adding an example for the new command field.

The addition of command to the list of sections supporting Go templates aligns with the PR objectives. To make this addition even more helpful, consider adding a practical example demonstrating how to use Go templates in the command field, similar to how other sections are documented with examples.

Example addition could look like:

command:
  terraform:
    init:
      description: "Initialize Terraform working directory using the specified version"
      command: "terraform{{ `${TERRAFORM_BINARY_VERSION:+-${TERRAFORM_BINARY_VERSION}}` }} init"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a84bd53 and c0f7289.

⛔ Files ignored due to path filters (2)
  • go.sum is excluded by !**/*.sum
  • website/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (10)
  • examples/quick-start-advanced/Dockerfile (1 hunks)
  • go.mod (5 hunks)
  • internal/exec/help.go (2 hunks)
  • internal/exec/terraform.go (2 hunks)
  • internal/exec/terraform_utils.go (2 hunks)
  • internal/exec/utils.go (2 hunks)
  • pkg/utils/file_utils.go (1 hunks)
  • website/docs/core-concepts/stacks/templates/templates.mdx (1 hunks)
  • website/docs/integrations/atlantis.mdx (1 hunks)
  • website/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • website/package.json
🧰 Additional context used
📓 Learnings (2)
internal/exec/terraform_utils.go (1)
Learnt from: haitham911
PR: cloudposse/atmos#727
File: internal/exec/terraform_clean.go:215-223
Timestamp: 2024-10-27T04:41:49.199Z
Learning: In `internal/exec/terraform_clean.go`, the function `determineCleanPath` is necessary and should not be removed.
pkg/utils/file_utils.go (1)
Learnt from: osterman
PR: cloudposse/atmos#731
File: pkg/utils/file_utils.go:198-202
Timestamp: 2024-10-23T20:13:23.054Z
Learning: In `pkg/utils/file_utils.go`, the current implementation of the `IsURL` function is considered sufficient; avoid suggesting more complex URL validation in future reviews.
🔇 Additional comments (18)
internal/exec/terraform_utils.go (3)

4-5: LGTM! Clean import additions.

The new standard library imports are necessary for file operations and path manipulation.


21-26: Well-documented function with clear purpose.

The function documentation clearly explains its purpose and the problem it solves regarding workspace selection prompts.


27-28: Consider error handling and adding tests.

  1. The current implementation silently ignores errors from os.Remove. While this might be intentional since the file may not exist, consider logging the error at debug level for troubleshooting purposes.

  2. The function would benefit from unit tests to verify its behavior:

    • Test successful file deletion
    • Test handling of non-existent file
    • Test handling of invalid component paths

Let's check if there are any existing test files:

examples/quick-start-advanced/Dockerfile (2)

9-9: LGTM: Version bump to include new features.

The update to Atmos version 1.100.0 aligns with the PR objectives, incorporating the new features for terraform/helmfile help improvements, Go templating support, and Terraform workspace cleaning.


9-9: Verify version consistency across the project.

Let's ensure this version bump is consistently applied across all relevant files.

✅ Verification successful

Based on the search results, I can see that the Atmos version 1.100.0 is only referenced in the quick-start-advanced Dockerfile and there are no other version references in the codebase that would need to be synchronized. The version in the Dockerfile is used as a build argument to install a specific version of Atmos in the container image, which is an isolated use case.

No other version references need to be updated

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any inconsistent Atmos versions across the project
# Expected: All version references should be 1.100.0

echo "Checking for Atmos version references..."
rg -g '!*.md' -g '!*.mdx' -i "ATMOS_VERSION.*1\.[0-9]+\.[0-9]+"

echo -e "\nChecking package management files for version constraints..."
fd -e yaml -e yml -e json | xargs rg "atmos.*1\.[0-9]+\.[0-9]+"

Length of output: 426


Script:

#!/bin/bash
# Let's check for any other Dockerfile or configuration files that might reference Atmos
echo "Checking for Dockerfiles..."
fd Dockerfile

echo -e "\nChecking for any version references in other configuration files..."
fd -e yaml -e yml -e json -e tf -e hcl | xargs rg -i "atmos.*version|ATMOS.*VERSION"

echo -e "\nChecking for any version constraints in package files..."
fd "package.json|requirements.txt|go.mod" | xargs cat

Length of output: 17801


Script:

#!/bin/bash
# Let's check the content of the other Dockerfiles to see if they reference Atmos versions
echo "Checking content of all Dockerfiles..."
fd Dockerfile | xargs cat

echo -e "\nChecking for any version references in atmos configuration files..."
fd -e yaml -e yml -e json -g "*atmos*" | xargs cat

Length of output: 343048

pkg/utils/file_utils.go (2)

200-214: LGTM! Good formatting improvements.

The changes improve readability and follow Go best practices by:

  • Using a clearer variable name u to avoid shadowing the url package
  • Adding appropriate spacing for better code organization

222-236: LGTM! Good formatting improvements.

The changes improve readability while maintaining the robust error handling for:

  • Empty URLs
  • Invalid URL parsing
  • Invalid path extraction
internal/exec/help.go (2)

18-20: LGTM! Consistent branding in help messages.

The capitalization of "Atmos" improves consistency with branding while maintaining clear and informative messaging.


107-111: LGTM! Clear and consistent help message formatting.

The help message improvements maintain clear command examples while ensuring consistent branding. The structure effectively guides users through command usage.

go.mod (4)

238-238: Security and stability improvements

The updates to the following packages typically include important security fixes and improvements:

  • golang.org/x/crypto v0.28.0
  • golang.org/x/net v0.30.0
  • golang.org/x/text v0.19.0
  • golang.org/x/time v0.7.0

Also applies to: 241-241, 246-247


100-101: Review containerd updates

The updates to containerd packages:

  • containerd v1.7.23
  • errdefs v0.3.0

These changes appear to be maintenance updates. The minor version bump in errdefs might introduce new error definitions that could be leveraged for better error handling.

#!/bin/bash
# Search for containerd error handling patterns that might benefit from the update
rg 'containerd/errdefs'

14-14: Verify compatibility with lipgloss v1.0.0

The major version bump from v0.13.1 to v1.0.0 for github.com/charmbracelet/lipgloss might introduce breaking changes. Please ensure all existing lipgloss usage in the codebase is compatible with v1.0.0.

✅ Verification successful

Let me analyze the lipgloss usage to verify if there are any breaking changes by checking the changelog.


Based on the analysis of the lipgloss usage in the codebase, I can generate the final response:

Lipgloss v1.0.0 update appears safe to proceed

The codebase uses basic lipgloss functionality that has been stable across versions:

  • Simple styling with NewStyle(), Padding(), Margin(), Height(), and Width()
  • Basic borders with RoundedBorder() and HiddenBorder()
  • Common layout functions like JoinHorizontal() and JoinVertical()
  • Standard color operations using Color()

These are core features that are unlikely to have breaking changes even in a major version bump.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for lipgloss usage patterns that might be affected by the v1.0.0 update
rg -l 'lipgloss\.' | xargs rg 'lipgloss\.'

Length of output: 2010


Script:

#!/bin/bash
# Check if there's a CHANGELOG.md in the vendor directory for lipgloss
fd -t f "CHANGELOG.md" vendor/github.com/charmbracelet/lipgloss/

# Alternatively, try to find any documentation about breaking changes
fd -t f "README.md" vendor/github.com/charmbracelet/lipgloss/

Length of output: 384


34-34: Verify OPA compatibility

The update to github.com/open-policy-agent/opa v0.70.0 aligns with the PR objectives for improved templating support. Please verify that existing OPA policies remain compatible.

✅ Verification successful

Let me gather more information about OPA usage in the codebase.


Let me check the actual OPA policy usage patterns and validation logic to ensure compatibility.


OPA v0.70.0 update is compatible with existing policies

The existing OPA policies use standard Rego features that are stable across versions:

  • Basic package declarations and imports
  • Standard built-ins like count(), re_match()
  • Common data structures and rule patterns
  • No usage of experimental or version-specific features

The policies follow OPA best practices and use well-established syntax that remains compatible with v0.70.0.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for OPA policy files and usage patterns
fd -e rego
rg 'opa\.' 

Length of output: 271


Script:

#!/bin/bash
# Search for OPA policy files and related code
fd -e rego
rg -l "opa" --type go
rg "opa\.New|rego\." -A 3

Length of output: 1500


Script:

#!/bin/bash
# Check OPA policy content and validation patterns
cat examples/quick-start-advanced/stacks/schemas/opa/vpc/validate-vpc-component.rego
cat examples/tests/stacks/schemas/opa/test-component/validate-test-component.rego

# Check for any version-specific OPA features or syntax
rg "package\s+|import\s+|default\s+" examples/quick-start-advanced/stacks/schemas/opa/ examples/tests/stacks/schemas/opa/

Length of output: 5316

internal/exec/terraform.go (1)

263-274: LGTM! The init control flow logic is well-structured.

The conditions for running or skipping terraform init are comprehensive and properly handle all edge cases.

website/docs/core-concepts/stacks/templates/templates.mdx (1)

Line range hint 1-24: Documentation is comprehensive and well-structured!

The documentation effectively covers all aspects of stack manifest templating, including:

  • Clear configuration instructions
  • Comprehensive examples
  • Detailed explanations of template processing
  • Important warnings and gotchas
website/docs/integrations/atlantis.mdx (1)

676-676: LGTM! Verify version consistency.

The Atmos version update from 1.99.0 to 1.100.0 looks good.

Let's verify that this version is consistent across the codebase:

✅ Verification successful

Version update is consistent across the codebase

The Atmos version update from 1.99.0 to 1.100.0 has been verified in both locations where it appears:

  • website/docs/integrations/atlantis.mdx: ATMOS_VERSION: 1.100.0
  • examples/quick-start-advanced/Dockerfile: ARG ATMOS_VERSION=1.100.0
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any other occurrences of Atmos version numbers to ensure consistency
rg -g '!website/docs/integrations/atlantis.mdx' "ATMOS_VERSION.*1\.(99|100)\.0"

Length of output: 148


Script:

#!/bin/bash
# Let's search for any other version patterns to ensure we haven't missed anything
rg -g '!{website/docs/integrations/atlantis.mdx,examples/quick-start-advanced/Dockerfile}' "atmos.*1\.(99|100)\.0" -i

Length of output: 119

internal/exec/utils.go (2)

Line range hint 512-548: LGTM! Clean implementation of manifest section processing.

The code follows a consistent pattern for safely processing each Atmos manifest section after Go template processing, with proper type assertions and default values.


549-551: LGTM! Command field processing enables Go templating support.

The implementation correctly enables Go templating in the command field, allowing dynamic configurations as specified in the PR objectives.

Let's verify the command field usage in stack configurations:

✅ Verification successful

Command field processing implementation is correctly integrated

Based on the codebase analysis, the command field processing is properly implemented and follows the established patterns:

  • The code correctly processes command fields from component sections using the same pattern as other sections
  • Command field values are properly extracted and type-checked across different component types (terraform, helmfile)
  • The implementation supports both direct command values and inheritance from base components
  • While no explicit Go template usage was found in the current configurations, the processing code allows for template interpolation as it handles string values
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find examples of command field usage with Go templates in stack configurations

# Test: Search for command field usage with Go template syntax
rg -A 5 'command:\s*\{\{.*\}\}'

Length of output: 33


Script:

#!/bin/bash
# Let's try a broader search for command field usage in yaml/json files
fd -e yaml -e yml -e json --exec rg -l 'command:' {}

# Then let's look at the actual command field implementations
fd -e yaml -e yml -e json --exec cat {} | grep -A 2 'command:'

# Also search for test files that might contain command field examples
fd -e go | xargs rg -l 'command.*test'

# And check the actual test implementations
ast-grep --pattern 'func Test$_($_) {
  $$$
  command $$$
  $$$
}'

Length of output: 11432


Script:

#!/bin/bash
# Let's check test files for command field templating examples
rg -l "command.*\{\{.*\}\}" internal/exec/

# Look for command field processing tests
ast-grep --pattern 'func Test$_(t *testing.T) {
  $$$
  command := $$$
  $$$
}'

# Check for template processing related to command field
rg -A 3 "CommandSectionName|Command.*template" internal/exec/

Length of output: 4720

internal/exec/terraform.go Show resolved Hide resolved
internal/exec/terraform.go Show resolved Hide resolved
@aknysh aknysh merged commit d25bb50 into main Nov 2, 2024
25 of 26 checks passed
@aknysh aknysh deleted the update-templating branch November 2, 2024 22:01
Copy link

github-actions bot commented Nov 2, 2024

These changes were released in v1.100.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor New features that do not break anything
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants