Skip to content

Commit

Permalink
Minor Code Improvements (#3718)
Browse files Browse the repository at this point in the history
* Code improvements

* Imports update

* Common cicd config

* Env update

* Windows Terraform version fetching from env variables

* Opentofu engine version update
  • Loading branch information
denis256 authored Dec 31, 2024
1 parent 0498737 commit 95eda4c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
21 changes: 17 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ env: &env
environment:
GRUNTWORK_INSTALLER_VERSION: v0.0.39
MODULE_CI_VERSION: v0.57.0
TOFU_ENGINE_VERSION: "v0.0.9"
OPENTOFU_VERSION: "1.8.8"
TERRAFORM_VERSION: "1.9.7"
TFLINT_VERSION: "0.47.0"
TOFU_ENGINE_VERSION: "v0.0.11"

defaults: &defaults
docker:
Expand All @@ -20,7 +23,6 @@ install_terraform_latest: &install_terraform_latest
command: |
pushd .
cd /tmp
export TERRAFORM_VERSION=1.9.7
curl -L "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" -o terraform.zip
unzip -o terraform.zip
sudo install -m 0755 terraform /usr/local/bin/terraform
Expand All @@ -34,7 +36,7 @@ install_tofu: &install_tofu
command: |
pushd .
cd /tmp
curl -L "https://github.com/opentofu/opentofu/releases/download/v1.8.3/tofu_1.8.3_linux_amd64.zip" -o tofu.zip
curl -L "https://github.com/opentofu/opentofu/releases/download/v${OPENTOFU_VERSION}/tofu_${OPENTOFU_VERSION}_linux_amd64.zip" -o tofu.zip
unzip -o tofu.zip
sudo install -m 0755 tofu /usr/local/bin/tofu
rm -rf tofu
Expand All @@ -49,7 +51,7 @@ install_tflint: &install_tflint
command: |
pushd .
cd /tmp
curl -L "https://github.com/terraform-linters/tflint/releases/download/v0.47.0/tflint_linux_amd64.zip" -o tflint.zip
curl -L "https://github.com/terraform-linters/tflint/releases/download/v${TFLINT_VERSION}/tflint_linux_amd64.zip" -o tflint.zip
unzip -o tflint.zip
sudo install -m 0755 tflint /usr/local/bin/tflint
rm -rf tflint
Expand Down Expand Up @@ -151,6 +153,7 @@ jobs:
executor:
name: win/default
size: "large"
<<: *env
steps:
- checkout
- run:
Expand All @@ -172,6 +175,7 @@ jobs:
executor:
name: win/default
size: "large"
<<: *env
steps:
- checkout
- run:
Expand All @@ -197,6 +201,7 @@ jobs:
# performance penalty.
unit_test:
<<: *defaults
<<: *env
steps:
- checkout
# Run pre-commit hooks and fail the build if any hook finds required changes.
Expand Down Expand Up @@ -237,6 +242,7 @@ jobs:
integration_test_terraform_1_5:
resource_class: xlarge
<<: *defaults
<<: *env
steps:
- checkout
- run:
Expand All @@ -255,6 +261,7 @@ jobs:
integration_test_terraform_with_provider_cache:
resource_class: xlarge
<<: *defaults
<<: *env
steps:
- checkout
- run:
Expand All @@ -275,6 +282,7 @@ jobs:
integration_test_terraform_latest:
resource_class: xlarge
<<: *defaults
<<: *env
steps:
- checkout
- run:
Expand All @@ -295,6 +303,7 @@ jobs:
integration_test_tofu:
resource_class: xlarge
<<: *defaults
<<: *env
steps:
- checkout
- run:
Expand All @@ -317,6 +326,7 @@ jobs:
integration_test_tofu_with_provider_cache:
resource_class: xlarge
<<: *defaults
<<: *env
steps:
- checkout
- run:
Expand Down Expand Up @@ -494,6 +504,7 @@ jobs:
strict_lint:
resource_class: medium
<<: *defaults
<<: *env
steps:
- checkout
# The `run-strict-lint` target requires the `main` ref for comparison.
Expand All @@ -508,6 +519,7 @@ jobs:
integration_test_tflint:
resource_class: large
<<: *defaults
<<: *env
steps:
- checkout
- run:
Expand All @@ -528,6 +540,7 @@ jobs:
race_test:
resource_class: medium
<<: *defaults
<<: *env
steps:
- checkout
- run:
Expand Down
5 changes: 3 additions & 2 deletions _ci/install-opentofu.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ OpenTofuInstallPath = "C:\Program Files\tofu\tofu.exe"
$OpenTofuTmpPath = "C:\OpenTofutmp"
$OpenTofuTmpBinaryPath = "C:\OpenTofutmp\tofu.exe"
$OpenTofuPath = "C:\Program Files\tofu"
$OpenTofuVersion = $Env:OPENTOFU_VERSION
# Remove any old OpenTofu installation, if present
if (Test-Path -Path $OpenTofuInstallPath)
{
Remove-Item $OpenTofuInstallPath -Recurse
}
# Download OpenTofu and unpack it
$OpenTofuURI = "https://github.com/opentofu/opentofu/releases/download/v1.8.3/tofu_1.8.3_windows_amd64.zip"
$output = "tofu_1.8.3_windows_amd64.zip"
$OpenTofuURI = "https://github.com/opentofu/opentofu/releases/download/v$OpenTofuVersion/tofu_${OpenTofuVersion}_windows_amd64.zip"
$output = "tofu_${OpenTofuVersion}_windows_amd64.zip"
$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest -Uri $OpenTofuURI -OutFile $output
New-Item -ItemType "directory" -Path $OpenTofuTmpPath
Expand Down
3 changes: 2 additions & 1 deletion _ci/install-terraform.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Install terraform using Chocolatey
choco install terraform --version 1.9.7 -y
$TerraformVersion = $Env:TERRAFORM_VERSION
choco install terraform --version $TerraformVersion -y
# Verify installation
Get-Command terraform
terraform version
5 changes: 2 additions & 3 deletions config/config_partial.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"path/filepath"

"github.com/gruntwork-io/terragrunt/internal/strict"

clone "github.com/huandu/go-clone"
"github.com/huandu/go-clone"

"github.com/gruntwork-io/terragrunt/internal/cache"

Expand Down Expand Up @@ -290,7 +289,7 @@ func PartialParseConfigFile(ctx *ParsingContext, configPath string, include *Inc
func TerragruntConfigFromPartialConfig(ctx *ParsingContext, file *hclparse.File, includeFromChild *IncludeConfig) (*TerragruntConfig, error) {
var cacheKey = fmt.Sprintf("%#v-%#v-%#v-%#v", file.ConfigPath, file.Content(), includeFromChild, ctx.PartialParseDecodeList)

terragruntConfigCache := cache.ContextCache[*TerragruntConfig](ctx, RunCmdCacheContextKey)
terragruntConfigCache := cache.ContextCache[*TerragruntConfig](ctx, TerragruntConfigCacheContextKey)
if ctx.TerragruntOptions.UsePartialParseConfigCache {
if config, found := terragruntConfigCache.Get(ctx, cacheKey); found {
ctx.TerragruntOptions.Logger.Debugf("Cache hit for '%s' (partial parsing), decodeList: '%v'.", ctx.TerragruntOptions.TerragruntConfigPath, ctx.PartialParseDecodeList)
Expand Down
14 changes: 8 additions & 6 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ const (
engineCookieKey = "engine"
engineCookieValue = "terragrunt"

defaultCacheDir = ".cache"
defaultEngineCachePath = "terragrunt/plugins/iac-engine"
prefixTrim = "terragrunt-"
fileNameFormat = "terragrunt-iac-%s_%s_%s_%s_%s"
checksumFileNameFormat = "terragrunt-iac-%s_%s_%s_SHA256SUMS"

defaultCacheDir = ".cache"
defaultEngineCachePath = "terragrunt/plugins/iac-engine"
prefixTrim = "terragrunt-"
fileNameFormat = "terragrunt-iac-%s_%s_%s_%s_%s"
checksumFileNameFormat = "terragrunt-iac-%s_%s_%s_SHA256SUMS"
engineLogLevelEnv = "TG_ENGINE_LOG_LEVEL"
defaultEngineRepoRoot = "github.com/"
terraformCommandContextKey engineClientsKey = iota
locksContextKey engineLocksKey = iota
Expand Down Expand Up @@ -517,6 +517,8 @@ func createEngine(terragruntOptions *options.TerragruntOptions) (*proto.EngineCl
})

cmd := exec.Command(localEnginePath)
// pass log level to engine
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", engineLogLevelEnv, engineLogLevel))
client := plugin.NewClient(&plugin.ClientConfig{
Logger: logger,
HandshakeConfig: plugin.HandshakeConfig{
Expand Down

0 comments on commit 95eda4c

Please sign in to comment.