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

allow cache values to be overridable for terraform and terragrunt #1873

Merged
merged 7 commits into from
Feb 4, 2025

Conversation

motatoes
Copy link
Contributor

@motatoes motatoes commented Jan 20, 2025

Summary by CodeRabbit

  • New Features
    • Added configurable cache directory options for Terraform and Terragrunt in GitHub Actions.
    • Introduced a new step for setting up Terraform in the workflow, enhancing the setup process.

Copy link
Contributor

coderabbitai bot commented Jan 20, 2025

Walkthrough

The pull request modifies the GitHub Action configuration by introducing a new optional input parameter: terraform-cache-dir. This input allows users to specify a custom cache directory for Terraform, defaulting to an empty string if not provided. A new step named "retrieve cache dir" has been added to determine the cache directory based on this input, defaulting to ${{github.workspace}}/cache if empty. Additionally, a new step for setting up Terraform has been introduced in the workflow, along with logging enhancements in the RunJobs function to improve observability.

Changes

File Change Summary
action.yml Added a new optional input: terraform-cache-dir with a default empty string value. Updated logic to set environment variables and added a new step to determine the cache directory.
.github/workflows/libs_test.yml Added a new step named "Setup terraform" utilizing hashicorp/setup-terraform@v3 with parameters for terraform_wrapper and terraform_version.
cli/pkg/digger/digger.go Introduced logging statements in the RunJobs function to print values of TF_PLUGIN_CACHE_DIR and TERRAGRUNT_PROVIDER_CACHE_DIR.

Possibly related PRs

  • Update action.yml #1856: The changes in the main PR introduce a new input parameter and modify the caching logic in action.yml, while the retrieved PR focuses on optimizing the caching mechanism without adding new parameters, indicating a direct relationship in their modifications to the caching functionality within the same file.

Poem

🐰 In the garden of code, we hop with glee,
A cache for Terraform, as sweet as can be.
With inputs so flexible, our paths now align,
Setting up Terraform, oh what a fine design!
Hopping through workflows, with joy we declare,
A world of new caching, beyond compare! 🚀

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 51c8f8b and e2de522.

📒 Files selected for processing (1)
  • cli/pkg/digger/digger.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • cli/pkg/digger/digger.go
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai 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: 0

🧹 Nitpick comments (2)
action.yml (2)

381-392: Fix inconsistency in environment variable comments.

The comment for TERRAGRUNT_PROVIDER_CACHE_DIR is missing while it's present in the release mode configuration (line 435).

Add the missing comment:

        TF_PLUGIN_CACHE_DIR: ${{
          inputs.terraform-cache-dir == '' &&
          format('{0}/cache', github.workspace) ||
          inputs.terraform-cache-dir
        }}
        TERRAGRUNT_PROVIDER_CACHE: ${{ inputs.cache-dependencies == 'true' && 1 || 0 }}
+       # if terragrunt-cache-dir is set then we set it to that otherwise set it to '${{github.workspace}}/cache'
        TERRAGRUNT_PROVIDER_CACHE_DIR: ${{

428-440: Consider extracting repeated logic into composite expressions.

The cache directory configuration logic is duplicated between development and release modes. This could lead to maintenance issues if the logic needs to be updated.

Consider defining these as composite expressions at the top of the file:

# Add at the top level of the action.yml
env:
  TERRAFORM_CACHE_DIR: ${{ inputs.terraform-cache-dir == '' && format('{0}/cache', github.workspace) || inputs.terraform-cache-dir }}
  TERRAGRUNT_CACHE_DIR: ${{ inputs.terragrunt-cache-dir == '' && format('{0}/cache', github.workspace) || inputs.terragrunt-cache-dir }}

Then reference these in both development and release mode sections:

        TF_PLUGIN_CACHE_DIR: ${{ env.TERRAFORM_CACHE_DIR }}
        TERRAGRUNT_PROVIDER_CACHE_DIR: ${{ env.TERRAGRUNT_CACHE_DIR }}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e88db8 and 11d68c4.

📒 Files selected for processing (1)
  • action.yml (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (71)
  • GitHub Check: binary (386, windows)
  • GitHub Check: binary (386, windows)
  • GitHub Check: binary (386, windows)
  • GitHub Check: binary (386, windows)
  • GitHub Check: binary (386, freebsd)
  • GitHub Check: binary (386, linux)
  • GitHub Check: binary (386, freebsd)
  • GitHub Check: binary (386, freebsd)
  • GitHub Check: binary (386, freebsd)
  • GitHub Check: binary (amd64, windows)
  • GitHub Check: binary (386, linux)
  • GitHub Check: binary (386, linux)
  • GitHub Check: binary (386, linux)
  • GitHub Check: binary (amd64, freebsd)
  • GitHub Check: binary (amd64, windows)
  • GitHub Check: binary (amd64, windows)
  • GitHub Check: binary (amd64, windows)
  • GitHub Check: binary (amd64, freebsd)
  • GitHub Check: binary (amd64, darwin)
  • GitHub Check: binary (amd64, freebsd)
  • GitHub Check: binary (amd64, freebsd)
  • GitHub Check: binary (amd64, linux)
  • GitHub Check: binary (amd64, darwin)
  • GitHub Check: binary (amd64, darwin)
  • GitHub Check: binary (amd64, darwin)
  • GitHub Check: binary (arm64, windows)
  • GitHub Check: binary (amd64, linux)
  • GitHub Check: binary (amd64, linux)
  • GitHub Check: binary (amd64, linux)
  • GitHub Check: binary (arm64, freebsd)
  • GitHub Check: binary (arm64, windows)
  • GitHub Check: binary (arm64, windows)
  • GitHub Check: binary (arm64, windows)
  • GitHub Check: binary (arm64, darwin)
  • GitHub Check: binary (arm64, freebsd)
  • GitHub Check: binary (arm64, freebsd)
  • GitHub Check: binary (arm64, freebsd)
  • GitHub Check: binary (arm64, darwin)
  • GitHub Check: binary (arm64, darwin)
  • GitHub Check: binary (arm64, linux)
  • GitHub Check: binary (arm64, darwin)
  • GitHub Check: binary (arm, windows)
  • GitHub Check: binary (arm64, linux)
  • GitHub Check: binary (arm64, linux)
  • GitHub Check: binary (arm64, linux)
  • GitHub Check: binary (arm, freebsd)
  • GitHub Check: Build
  • GitHub Check: binary (arm, windows)
  • GitHub Check: binary (arm, windows)
  • GitHub Check: binary (arm, windows)
  • GitHub Check: binary
  • GitHub Check: binary (arm, linux)
  • GitHub Check: Build
  • GitHub Check: binary (arm, freebsd)
  • GitHub Check: binary (arm, freebsd)
  • GitHub Check: binary (arm, freebsd)
  • GitHub Check: binary
  • GitHub Check: binary (arm, linux)
  • GitHub Check: binary (arm, linux)
  • GitHub Check: binary (arm, linux)
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
🔇 Additional comments (2)
action.yml (2)

170-177: LGTM! Well-structured input parameters.

The new input parameters are well-defined with clear descriptions and appropriate defaults. The optional nature allows for backward compatibility.


Line range hint 170-440: Verify the impact on existing cache implementations.

The new cache directory overrides might affect existing implementations that rely on the default cache location.

Let's check for any hardcoded references to the default cache path:

✅ Verification successful

Cache directory overrides are safely implemented

The implementation uses environment variables and proper fallback mechanisms without any hardcoded dependencies on the default cache location. The changes maintain backward compatibility while adding flexibility for custom cache paths.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for hardcoded references to the default cache path
# This helps identify any places that might break with custom cache directories

echo "Searching for hardcoded cache path references..."
rg -l "/cache" --type yaml --type typescript --type javascript --type go

echo "Searching for cache-related environment variable usage..."
rg -l "TF_PLUGIN_CACHE_DIR|TERRAGRUNT_PROVIDER_CACHE_DIR" --type yaml --type typescript --type javascript --type go

Length of output: 492


Script:

#!/bin/bash
# Search with explicit file extensions and broader patterns
echo "Searching for cache path and workspace references..."
rg -l "cache|workspace" --type yaml
rg -l "cache|workspace" -g "*.ts" -g "*.js" -g "*.go"

echo "Searching for environment variables..."
rg -l "TF_PLUGIN_CACHE_DIR|TERRAGRUNT_PROVIDER_CACHE_DIR" --type yaml
rg -l "TF_PLUGIN_CACHE_DIR|TERRAGRUNT_PROVIDER_CACHE_DIR" -g "*.ts" -g "*.js" -g "*.go"

echo "Searching for github.workspace references..."
rg -l "github.workspace" --type yaml

Length of output: 1562


Script:

#!/bin/bash
# Examine cache implementation details
echo "Checking cache implementation in Go files..."
rg -A 5 -B 5 "cache.*dir" libs/execution/tf.go libs/execution/opentofu.go backend/models/cache.go

echo "Checking for workspace path handling..."
rg -A 5 -B 5 "workspace.*path" libs/execution/tf.go libs/execution/opentofu.go backend/models/cache.go

echo "Looking for cache directory initialization..."
ast-grep --pattern 'func $_($$_) {
  $$$
  cache
  $$$
}'

Length of output: 553

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: 0

🧹 Nitpick comments (3)
action.yml (3)

170-178: Improve input parameter descriptions for consistency and clarity.

The descriptions could be more precise and consistent:

-    description: "allows overriding of the terraform cache dir which defaults to ${github.workspace}/cache"
+    description: "Override the terraform plugin cache directory (defaults to ${github.workspace}/cache)"
-    description: "allows overriding of the terragrunt cache dir to ${github.workspace}/cache"
+    description: "Override the terragrunt provider cache directory (defaults to ${github.workspace}/cache)"

381-384: LGTM! Consider simplifying the comment.

The conditional logic for setting TF_PLUGIN_CACHE_DIR is correct.

-        # if terraform-cache-dir is set then we set it to that otherwise set it to '${{github.workspace}}/cache'
+        # Set terraform plugin cache directory (defaults to workspace cache)

424-432: Fix trailing spaces and consider extracting environment variables.

  1. Remove trailing spaces in the conditional expressions
  2. Consider extracting common environment variables to reduce duplication between the two run blocks
-        TF_PLUGIN_CACHE_DIR: ${{ inputs.terraform-cache-dir == '' && 
-          format('{0}/cache', github.workspace) || 
+        TF_PLUGIN_CACHE_DIR: ${{ inputs.terraform-cache-dir == '' &&
+          format('{0}/cache', github.workspace) ||
           inputs.terraform-cache-dir }}

Consider moving the environment variable definitions to a composite step or a shell script that can be reused by both run blocks to reduce duplication.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 425-425: trailing spaces

(trailing-spaces)


[error] 426-426: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 11d68c4 and 814b105.

📒 Files selected for processing (1)
  • action.yml (3 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
action.yml

[error] 425-425: trailing spaces

(trailing-spaces)


[error] 426-426: trailing spaces

(trailing-spaces)

⏰ Context from checks skipped due to timeout of 90000ms (75)
  • GitHub Check: binary (386, windows)
  • GitHub Check: binary (386, windows)
  • GitHub Check: binary (386, windows)
  • GitHub Check: binary (386, freebsd)
  • GitHub Check: binary (386, windows)
  • GitHub Check: binary (386, freebsd)
  • GitHub Check: binary (386, linux)
  • GitHub Check: binary (386, freebsd)
  • GitHub Check: binary (386, linux)
  • GitHub Check: binary (386, freebsd)
  • GitHub Check: binary (amd64, windows)
  • GitHub Check: binary (386, linux)
  • GitHub Check: binary (amd64, windows)
  • GitHub Check: binary (386, linux)
  • GitHub Check: binary (amd64, freebsd)
  • GitHub Check: binary (amd64, windows)
  • GitHub Check: binary (amd64, freebsd)
  • GitHub Check: binary (amd64, windows)
  • GitHub Check: binary (amd64, darwin)
  • GitHub Check: binary (amd64, freebsd)
  • GitHub Check: binary (amd64, darwin)
  • GitHub Check: binary (amd64, freebsd)
  • GitHub Check: binary (amd64, linux)
  • GitHub Check: binary (amd64, darwin)
  • GitHub Check: binary (amd64, darwin)
  • GitHub Check: binary (amd64, linux)
  • GitHub Check: binary (arm64, windows)
  • GitHub Check: binary (amd64, linux)
  • GitHub Check: binary (arm64, windows)
  • GitHub Check: binary (amd64, linux)
  • GitHub Check: binary (arm64, windows)
  • GitHub Check: binary (arm64, freebsd)
  • GitHub Check: binary (arm64, windows)
  • GitHub Check: binary (arm64, freebsd)
  • GitHub Check: binary (arm64, freebsd)
  • GitHub Check: binary (arm64, darwin)
  • GitHub Check: binary (arm64, freebsd)
  • GitHub Check: binary (arm64, darwin)
  • GitHub Check: binary (arm64, linux)
  • GitHub Check: binary (arm64, darwin)
  • GitHub Check: binary (arm64, linux)
  • GitHub Check: binary (arm64, darwin)
  • GitHub Check: binary (arm64, linux)
  • GitHub Check: binary (arm64, linux)
  • GitHub Check: binary (arm, windows)
  • GitHub Check: binary (arm, windows)
  • GitHub Check: binary (arm, windows)
  • GitHub Check: binary (arm, freebsd)
  • GitHub Check: binary (arm, windows)
  • GitHub Check: binary (arm, freebsd)
  • GitHub Check: binary (arm, linux)
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: build-and-push-image
  • GitHub Check: binary
  • GitHub Check: build-and-push-image
  • GitHub Check: binary (arm, freebsd)
  • GitHub Check: binary (arm, linux)
  • GitHub Check: binary (arm, freebsd)
  • GitHub Check: Build
  • GitHub Check: build-and-push-image
  • GitHub Check: build-and-push-image
  • GitHub Check: binary (arm, linux)
  • GitHub Check: binary
  • GitHub Check: binary (arm, linux)
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
🔇 Additional comments (1)
action.yml (1)

386-388: LGTM! The implementation is consistent with terraform cache.

The conditional logic for setting TERRAGRUNT_PROVIDER_CACHE_DIR follows the same pattern as TF_PLUGIN_CACHE_DIR, maintaining consistency.

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: 1

🧹 Nitpick comments (1)
.github/workflows/libs_test.yml (1)

19-19: Remove trailing whitespace.

There are trailing spaces on this line that should be removed.

-          
+
🧰 Tools
🪛 yamllint (1.35.1)

[error] 19-19: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a0c734f and c9cf88e.

📒 Files selected for processing (1)
  • .github/workflows/libs_test.yml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
.github/workflows/libs_test.yml

[error] 19-19: trailing spaces

(trailing-spaces)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build
  • GitHub Check: Build

.github/workflows/libs_test.yml Show resolved Hide resolved
@motatoes motatoes merged commit f3e523d into develop Feb 4, 2025
12 checks passed
@motatoes motatoes deleted the feat/allow-overridable-cache-values branch February 4, 2025 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant