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

Actualize dependencies, fix tests and solve bugs #699

Merged
merged 33 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d3a8473
Just update the hardcoded version to start a pull request.
jocgir Jul 9, 2024
93f376e
chore(deps): update github/codeql-action action to v3
renovate-coveooss[bot] Jul 10, 2024
9605f46
fix(deps): update module github.com/hashicorp/go-getter to v2
renovate-coveooss[bot] Jul 10, 2024
ab901fb
fix(deps): update module github.com/urfave/cli to v2
renovate-coveooss[bot] Jul 10, 2024
e151a90
Fix go mod
jocgir Jul 10, 2024
c4c7845
Fix bug with last renovate updates
jocgir Jul 10, 2024
9f5bbcc
Fix format
jocgir Jul 10, 2024
14243ff
Update a newer version of go-getter
jocgir Jul 10, 2024
4d31e23
Remove vulnerability for grpc
jocgir Jul 10, 2024
e4ed426
Update staticcheck to support newest version of golang
jocgir Jul 10, 2024
d51f42c
Update to go 1.22
jocgir Jul 10, 2024
0f0c23a
Fix all deprecations
jocgir Jul 10, 2024
8f49761
Just update the hardcoded version to start a pull request.
jocgir Jul 9, 2024
88d1e43
chore(deps): update github/codeql-action action to v3
renovate-coveooss[bot] Jul 10, 2024
abd11bb
fix(deps): update module github.com/hashicorp/go-getter to v2
renovate-coveooss[bot] Jul 10, 2024
cff2a5c
fix(deps): update module github.com/urfave/cli to v2
renovate-coveooss[bot] Jul 10, 2024
faf5319
Fix go mod
jocgir Jul 10, 2024
a9fd951
Fix bug with last renovate updates
jocgir Jul 10, 2024
40a29d4
Fix format
jocgir Jul 10, 2024
7904d5d
Update a newer version of go-getter
jocgir Jul 10, 2024
0d20d16
Remove vulnerability for grpc
jocgir Jul 10, 2024
5d73c0a
Update staticcheck to support newest version of golang
jocgir Jul 10, 2024
4120067
Update to go 1.22
jocgir Jul 10, 2024
8870118
Fix all deprecations
jocgir Jul 10, 2024
57c89e4
Update dependencies
jocgir Oct 2, 2024
300b6c9
Remove dependency to terrarform 0.15
jocgir Oct 2, 2024
301c0a3
Merge remote-tracking branch 'coveooss/DT-7003-Build-new-terragrunt-v…
jocgir Oct 3, 2024
c798cfd
Update go version and build tools
jocgir Oct 3, 2024
fb217a9
Fix error reporting when no position is identified while an error occ…
jocgir Oct 3, 2024
840ef00
Fix pr action
jocgir Oct 3, 2024
2ee324a
Fix goreleaser to use the right tag
jocgir Oct 3, 2024
a3266c7
Fix last non-working test :D
jocgir Oct 5, 2024
056ad11
Update dependencies
jocgir Oct 5, 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
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -58,7 +58,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -71,6 +71,6 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
31 changes: 20 additions & 11 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ on:
branches:
- master
- main
env:
GoVersion: '1.23'

jobs:
static:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.18'
go-version: ${{ env.GoVersion }}
cache: false
- uses: actions/checkout@v4

- name: Run static checks
Expand All @@ -22,7 +25,8 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.18'
go-version: ${{ env.GoVersion }}
cache: false
- uses: actions/checkout@v4

- run: make build
Expand All @@ -32,10 +36,11 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.18'
go-version: ${{ env.GoVersion }}
cache: false
- uses: actions/checkout@v4

- run: make fmtcheck
- run: make fmt

test:
runs-on: ubuntu-latest
Expand All @@ -48,7 +53,9 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.18'
go-version: ${{ env.GoVersion }}
cache: false

- uses: actions/checkout@v4

- name: Install Terraform
Expand All @@ -64,12 +71,13 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.18'
go-version: ${{ env.GoVersion }}
cache: false

- uses: goreleaser/goreleaser-action@d33b6f6aeabd7fed8bb3fbf32c4d890d29f48545
- uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
version: '~> v2'
args: check

goreleaser-test-release:
Expand All @@ -80,12 +88,13 @@ jobs:
fetch-depth: 0 # goreleaser needs the whole history to build the release notes
- uses: actions/setup-go@v5
with:
go-version: '1.18'
go-version: ${{ env.GoVersion }}
cache: false

- uses: goreleaser/goreleaser-action@d33b6f6aeabd7fed8bb3fbf32c4d890d29f48545
- uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
version: '~> v2'
args: release --snapshot --clean

- uses: actions/upload-artifact@v4
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.18'
go-version: '1.23'
cache: false

- name: Checkout
uses: actions/checkout@v4
Expand All @@ -44,10 +45,10 @@ jobs:
make full-test

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@d33b6f6aeabd7fed8bb3fbf32c4d890d29f48545
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
version: '~> v2'
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7 changes: 7 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Build customization
version: 2
builds:
- binary: terragrunt
ldflags: -s -w -X main.VERSION={{.Version}}
Expand Down Expand Up @@ -32,3 +33,9 @@ archives:
# GitHub release customization
release:
prerelease: auto

git:
tag_sort: -version:creatordate
prerelease_suffix: "-"
ignore_tags:
- download_test
14 changes: 4 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor)

fmtcheck:
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"

fmt:
@echo "Running source files through gofmt..."
gofmt -w $(GOFMT_FILES)
@echo "Running source files through go fmt ..."
go fmt ./...

test:
go test -v -short ./...
Expand All @@ -14,15 +9,14 @@ full-test:
go test -v ./...

static:
go install honnef.co/go/tools/cmd/staticcheck@2022.1
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck --version

staticcheck ./...

pre-commit: fmt static test

build:
go install golang.org/x/tools/cmd/stringer@v0.19.0
go install golang.org/x/tools/cmd/stringer@v0.25.0
go install github.com/cheekybits/[email protected]

go generate -x ./...
Expand Down
6 changes: 3 additions & 3 deletions awshelper/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"regexp"
Expand Down Expand Up @@ -136,7 +136,7 @@ func SaveS3Status(bucketInfo *BucketInfo, folder string) (err error) {
if err != nil {
return
}
err = ioutil.WriteFile(filepath.Join(folder, CacheFile), jsonString, 0644)
err = os.WriteFile(filepath.Join(folder, CacheFile), jsonString, 0644)
return
}

Expand All @@ -153,7 +153,7 @@ func CheckS3Status(sourceBucketInfo *BucketInfo, folder string) error {
return fmt.Errorf("error while reading %s: %w", *sourceBucketInfo, err)
}

content, err := ioutil.ReadFile(filepath.Join(folder, CacheFile))
content, err := os.ReadFile(filepath.Join(folder, CacheFile))
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions cli/cli_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/coveooss/terragrunt/v2/tgerrors"
"github.com/coveooss/terragrunt/v2/util"
"github.com/fatih/color"
"github.com/hashicorp/terraform/configs"
"github.com/hashicorp/terraform-config-inspect/tfconfig"
"github.com/rs/xid"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
Expand Down Expand Up @@ -149,7 +149,7 @@ AUTHOR(S):
`

// This uses the constraint syntax from https://github.com/hashicorp/go-version
const defaultTerraformVersionConstaint = ">= v1.0.0"
const defaultTerraformVersionConstraint = ">= v1.7.0"

var terragruntVersion string
var terragruntRunID string
Expand Down Expand Up @@ -215,7 +215,7 @@ func runApp(cliContext *cli.Context) (finalErr error) {
}
}

if err := CheckTerraformVersion(defaultTerraformVersionConstaint, terragruntOptions); err != nil {
if err := CheckTerraformVersion(defaultTerraformVersionConstraint, terragruntOptions); err != nil {
return err
}

Expand Down Expand Up @@ -501,7 +501,7 @@ func runTerragrunt(terragruntOptions *options.TerragruntOptions) (finalStatus er

// Export Terragrunt variables to the paths defined in export_variables blocks
for _, folder := range foldersWithTerraformFiles {
var existingVariables map[string]*configs.Variable
var existingVariables map[string]*tfconfig.Variable
_, existingVariables, err = util.LoadDefaultValues(folder, terragruntOptions.Logger, false)
if stopOnError(err) {
return err
Expand Down Expand Up @@ -558,7 +558,7 @@ func runTerragrunt(terragruntOptions *options.TerragruntOptions) (finalStatus er
}
if terragruntOptions.PluginsDirectory != "" {
// As of Terraform 0.13.5, the -get-plugins=false argument doesn't work, so we don't use it
// Passing a plugin-dir explicitely disallows downloads correctly
// Passing a plugin-dir explicitly disallows downloads correctly
initArgs = append(initArgs, fmt.Sprintf("-plugin-dir=%s", terragruntOptions.PluginsDirectory))
}
if err = shell.NewTFCmd(terragruntOptions).Args(initArgs...).WithRetries(3).LogOutput(logrus.DebugLevel); stopOnError(err) {
Expand Down
35 changes: 17 additions & 18 deletions cli/download_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cli

import (
"fmt"
"io/ioutil"
"net/url"
"os"
"regexp"
Expand Down Expand Up @@ -130,7 +129,7 @@ func readVersionFile(terraformSource *TerraformSource) (string, error) {
// calculated using the encodeSourceVersion method.
func writeVersionFile(terraformSource *TerraformSource) error {
version := encodeSourceVersion(terraformSource.CanonicalSourceURL)
return tgerrors.WithStackTrace(ioutil.WriteFile(terraformSource.VersionFile, []byte(version), 0640))
return tgerrors.WithStackTrace(os.WriteFile(terraformSource.VersionFile, []byte(version), 0640))
}

// Take the given source path and create a TerraformSource struct from it, including the folder where the source should
Expand All @@ -141,25 +140,25 @@ func writeVersionFile(terraformSource *TerraformSource) error {
// To maximize reuse, given a working directory w and a source URL s, we download code from S into the folder /T/W/H
// where:
//
// 1. S is the part of s before the double-slash (//). This typically represents the root of the repo (e.g.
// github.com/foo/infrastructure-modules). We download the entire repo so that relative paths to other files in that
// repo resolve correctly. If no double-slash is specified, all of s is used.
// 1. T is the OS temp dir (e.g. /tmp).
// 2. W is the base 64 encoded sha1 hash of w. This ensures that if you are running Terragrunt concurrently in
// multiple folders (e.g. during automated tests), then even if those folders are using the same source URL s, they
// do not overwrite each other.
// 3. H is the base 64 encoded sha1 of S without its query string. For remote source URLs (e.g. Git
// URLs), this is based on the assumption that the scheme/host/path of the URL (e.g. git::github.com/foo/bar)
// identifies the repo, and we always want to download the same repo into the same folder (see the encodeSourceName
// method). We also assume the version of the module is stored in the query string (e.g. ref=v0.0.3), so we store
// the base 64 encoded sha1 of the query string in a file called .terragrunt-source-version within /T/W/H.
// 1. S is the part of s before the double-slash (//). This typically represents the root of the repo (e.g.
// github.com/foo/infrastructure-modules). We download the entire repo so that relative paths to other files in that
// repo resolve correctly. If no double-slash is specified, all of s is used.
// 1. T is the OS temp dir (e.g. /tmp).
// 2. W is the base 64 encoded sha1 hash of w. This ensures that if you are running Terragrunt concurrently in
// multiple folders (e.g. during automated tests), then even if those folders are using the same source URL s, they
// do not overwrite each other.
// 3. H is the base 64 encoded sha1 of S without its query string. For remote source URLs (e.g. Git
// URLs), this is based on the assumption that the scheme/host/path of the URL (e.g. git::github.com/foo/bar)
// identifies the repo, and we always want to download the same repo into the same folder (see the encodeSourceName
// method). We also assume the version of the module is stored in the query string (e.g. ref=v0.0.3), so we store
// the base 64 encoded sha1 of the query string in a file called .terragrunt-source-version within /T/W/H.
//
// The downloadTerraformSourceIfNecessary decides when we should download the Terraform code and when not to. It uses
// the following rules:
//
// 1. Always download source URLs pointing to local file paths.
// 2. Only download source URLs pointing to remote paths if /T/W/H doesn't already exist or, if it does exist, if the
// version number in /T/W/H/.terragrunt-source-version doesn't match the current version.
// 1. Always download source URLs pointing to local file paths.
// 2. Only download source URLs pointing to remote paths if /T/W/H doesn't already exist or, if it does exist, if the
// version number in /T/W/H/.terragrunt-source-version doesn't match the current version.
func processTerraformSource(source string, terragruntOptions *options.TerragruntOptions) (*TerraformSource, error) {
canonicalWorkingDir, err := util.CanonicalPath(terragruntOptions.WorkingDir, "")
if err != nil {
Expand Down Expand Up @@ -304,7 +303,7 @@ func isLocalSource(sourceURL *url.URL) bool {
}

// If this temp folder already exists, simply delete all the Terraform files within it
// (the terraform init command will redownload the latest ones), but leave all the other files, such
// (the terraform init command will re-download the latest ones), but leave all the other files, such
// as the .terraform folder with the downloaded modules and remote state settings.
func cleanupTerraformFiles(path string, terragruntOptions *options.TerragruntOptions) error {
if !util.FileExists(path) {
Expand Down
8 changes: 4 additions & 4 deletions cli/download_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cli

import (
"fmt"
"io/ioutil"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -115,7 +114,7 @@ func TestDownloadTerraformSourceIfNecessaryRemoteUrlToAlreadyDownloadedDir(t *te
func TestDownloadTerraformSourceIfNecessaryRemoteUrlToAlreadyDownloadedDirDifferentVersion(t *testing.T) {
t.Parallel()

canonicalURL := "github.com/coveooss/terragrunt//test/fixture-download-source/hello-world?ref=v0.9.7"
canonicalURL := "github.com/coveooss/terragrunt//test/fixture-download-source/hello-world?ref=v1.0.0"
downloadDir := tmpDir(t)
defer os.Remove(downloadDir)

Expand All @@ -127,6 +126,7 @@ func TestDownloadTerraformSourceIfNecessaryRemoteUrlToAlreadyDownloadedDirDiffer
func TestDownloadTerraformSourceIfNecessaryRemoteUrlToAlreadyDownloadedDirSameVersion(t *testing.T) {
t.Parallel()

// The version specified does not have to exist, we just want to compare the hash computed from the url with the content of the file
canonicalURL := "github.com/coveooss/terragrunt//test/fixture-download-source/hello-world?ref=v0.9.7"
downloadDir := tmpDir(t)
defer os.Remove(downloadDir)
Expand All @@ -139,7 +139,7 @@ func TestDownloadTerraformSourceIfNecessaryRemoteUrlToAlreadyDownloadedDirSameVe
func TestDownloadTerraformSourceIfNecessaryRemoteUrlOverrideSource(t *testing.T) {
t.Parallel()

canonicalURL := "github.com/coveooss/terragrunt//test/fixture-download-source/hello-world?ref=v0.9.7"
canonicalURL := "github.com/coveooss/terragrunt//test/fixture-download-source/hello-world?ref=v1.0.0"
downloadDir := tmpDir(t)
defer os.Remove(downloadDir)

Expand Down Expand Up @@ -183,7 +183,7 @@ func testAlreadyHaveLatestCode(t *testing.T, canonicalURL string, downloadDir st
}

func tmpDir(t *testing.T) string {
dir, err := ioutil.TempDir("", "download-source-test")
dir, err := os.MkdirTemp("", "download-source-test")
if err != nil {
t.Fatal(err)
}
Expand Down
Loading
Loading