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

chore: Bumping golangci-lint to v1.63.4 #3818

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ linters:
- wrapcheck
- varnamelen

# TODO: We intentionally mix and match pointer and non-pointer
# receivers in the codebase. We might want to revisit this,
# but not while upgrading the linter.
- recvcheck

fast: false
mnd:
ignored-functions: strconv.Format*,os.*,strconv.Parse*,strings.SplitN,bytes.SplitN
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ clean:
rm -f terragrunt

install-lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.63.4

run-lint:
golangci-lint run -v --timeout=10m ./...
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/terraform/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func mockOptions(t *testing.T, terragruntConfigPath string, workingDir string, t
func createTempFile(t *testing.T) string {
t.Helper()

tmpFile, err := os.CreateTemp("", "")
tmpFile, err := os.CreateTemp(t.TempDir(), "")
if err != nil {
t.Fatalf("Failed to create temp directory: %s\n", err.Error())
}
Expand Down
8 changes: 3 additions & 5 deletions cli/commands/terraform/download_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,9 @@ func testAlreadyHaveLatestCode(t *testing.T, canonicalURL string, downloadDir st
func tmpDir(t *testing.T) string {
t.Helper()

dir, err := os.MkdirTemp("", "download-source-test")
if err != nil {
t.Fatal(err)
}
return filepath.FromSlash(dir)
tmpDir := t.TempDir()

return filepath.FromSlash(tmpDir)
}

func absPath(t *testing.T, path string) string {
Expand Down
4 changes: 2 additions & 2 deletions config/variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ func TestScanDefaultVariables(t *testing.T) {
assert.Equal(t, "0", varByName["number_default"].DefaultValuePlaceholder)

assert.Equal(t, "object", varByName["object_var"].Type)
assert.Equal(t, "{\"num\":42,\"str\":\"default\"}", varByName["object_var"].DefaultValue)
assert.JSONEq(t, "{\"num\":42,\"str\":\"default\"}", varByName["object_var"].DefaultValue)

assert.Equal(t, "map", varByName["map_var"].Type)
assert.Equal(t, "{\"key\":\"value42\"}", varByName["map_var"].DefaultValue)
assert.JSONEq(t, "{\"key\":\"value42\"}", varByName["map_var"].DefaultValue)

assert.Equal(t, "bool", varByName["enabled"].Type)
assert.Equal(t, "true", varByName["enabled"].DefaultValue)
Expand Down
6 changes: 3 additions & 3 deletions configstack/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ digraph {
"h" -> "c";
}
`)
assert.True(t, strings.Contains(stdout.String(), expected))
assert.Contains(t, stdout.String(), expected)
}

func TestGraphTrimPrefix(t *testing.T) {
Expand Down Expand Up @@ -89,7 +89,7 @@ digraph {
"alpha/beta/h" -> "c";
}
`)
assert.True(t, strings.Contains(stdout.String(), expected))
assert.Contains(t, stdout.String(), expected)
}

func TestGraphFlagExcluded(t *testing.T) {
Expand Down Expand Up @@ -128,7 +128,7 @@ digraph {
"h" -> "c";
}
`)
assert.True(t, strings.Contains(stdout.String(), expected))
assert.Contains(t, stdout.String(), expected)
}

func TestCheckForCycles(t *testing.T) {
Expand Down
7 changes: 2 additions & 5 deletions configstack/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,9 @@ func createTestStack() *configstack.Stack {
func createTempFolder(t *testing.T) string {
t.Helper()

tmpFolder, err := os.MkdirTemp("", "")
if err != nil {
t.Fatalf("Failed to create temp directory: %s\n", err.Error())
}
tmpDir := t.TempDir()

return filepath.ToSlash(tmpFolder)
return filepath.ToSlash(tmpDir)
}

// Create a dummy Terragrunt config file at each of the given paths
Expand Down
2 changes: 2 additions & 0 deletions docs/_docs/03_community/01-contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ any go command that compiles the code (`build`, `run`, `test`, etc.).

Terragrunt uses [golangci-lint](https://golangci-lint.run/) to lint the golang code in the codebase. This is a helpful form of static analysis that can catch common bugs and issues related to performance, style and maintainability.

To ensure that you're using the same version of `golangci-lint` as the maintainers, you can use the `make install-lint` Makefile recipe to install the version of `golangci-lint` that we use locally, and in CI.

We use the linter as a guide to learn about how we can improve the Terragrunt codebase. We do not enforce 100% compliance with the linter. If you believe that an error thrown by the linter is irrelevant, use the documentation on [false-positives](https://golangci-lint.run/usage/false-positives/) to suppress that error, along with an explanation of why you believe the error is a false positive.

If you feel like the linter is missing a check that would be useful for improving the code quality of Terragrunt, please open an issue to discuss it, then open a pull request to add the check.
Expand Down
2 changes: 1 addition & 1 deletion docs/_docs/04_reference/02-cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ Other credential configurations will be supported in the future, but until then,
**Requires an argument**: `--terragrunt-iam-role "arn:aws:iam::ACCOUNT_ID:role/ROLE_NAME"`<br/>

Assume the specified IAM role ARN for running OpenTofu/Terraform or AWS commands. This is a convenient way to use Terragrunt
and OpenTofu/Terraform with multiple AWS accounts.
and OpenTofu/Terraform with multiple AWS accounts.

When using this option, AWS authentication takes place right before an OpenTofu/Terraform run. This takes place after `terragrunt.hcl` files are fully parsed, so HCL functions like [`get_aws_account_id`](/docs/reference/built-in-functions/#get_aws_account_id) and [`run_cmd`](/docs/reference/built-in-functions/#run_cmd) will not run after assuming the role. If you need roles to be assumed prior to parsing Terragrunt configurations, use [`terragrunt-auth-provider-cmd`](#terragrunt-auth-provider-cmd) instead.

Expand Down
5 changes: 2 additions & 3 deletions shell/run_shell_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package shell_test
import (
"bytes"
"context"
"strings"
"testing"

"github.com/gruntwork-io/terragrunt/internal/cache"
Expand Down Expand Up @@ -42,7 +41,7 @@ func TestRunShellOutputToStderrAndStdout(t *testing.T) {
cmd := shell.RunShellCommand(context.Background(), terragruntOptions, "terraform", "--version")
require.NoError(t, cmd)

assert.True(t, strings.Contains(stdout.String(), "Terraform"), "Output directed to stdout")
assert.Contains(t, stdout.String(), "Terraform", "Output directed to stdout")
assert.Empty(t, stderr.String(), "No output to stderr")

stdout = new(bytes.Buffer)
Expand All @@ -55,7 +54,7 @@ func TestRunShellOutputToStderrAndStdout(t *testing.T) {
cmd = shell.RunShellCommand(context.Background(), terragruntOptions, "terraform", "--version")
require.NoError(t, cmd)

assert.True(t, strings.Contains(stderr.String(), "Terraform"), "Output directed to stderr")
assert.Contains(t, stderr.String(), "Terraform", "Output directed to stderr")
assert.Empty(t, stdout.String(), "No output to stdout")
}

Expand Down
13 changes: 6 additions & 7 deletions terraform/cliconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ func TestConfig(t *testing.T) {
exclude = []string{"registry.opentofu.org/*/*"}
)

tempCacheDir, err := os.MkdirTemp("", "*")
require.NoError(t, err)
tmpDir := t.TempDir()

testCases := []struct {
providerInstallationMethods []cliconfig.ProviderInstallationMethod
Expand All @@ -30,7 +29,7 @@ func TestConfig(t *testing.T) {
}{
{
providerInstallationMethods: []cliconfig.ProviderInstallationMethod{
cliconfig.NewProviderInstallationFilesystemMirror(tempCacheDir, include, exclude),
cliconfig.NewProviderInstallationFilesystemMirror(tmpDir, include, exclude),
cliconfig.NewProviderInstallationNetworkMirror("https://network-mirror.io/providers/", include, exclude),
cliconfig.NewProviderInstallationDirect(include, exclude),
},
Expand All @@ -54,7 +53,7 @@ host "registry.terraform.io" {
provider_installation {

"filesystem_mirror" {
path = "` + tempCacheDir + `"
path = "` + tmpDir + `"
include = ["registry.terraform.io/*/*"]
exclude = ["registry.opentofu.org/*/*"]
}
Expand All @@ -73,11 +72,11 @@ provider_installation {
{
config: cliconfig.Config{
DisableCheckpoint: false,
PluginCacheDir: tempCacheDir,
PluginCacheDir: tmpDir,
},
expectedHCL: `disable_checkpoint = false
disable_checkpoint_signature = false
plugin_cache_dir = "` + tempCacheDir + `"
plugin_cache_dir = "` + tmpDir + `"

provider_installation {
}
Expand All @@ -99,7 +98,7 @@ provider_installation {
}
testCase.config.AddProviderInstallationMethods(testCase.providerInstallationMethods...)

err = testCase.config.Save(configFile)
err := testCase.config.Save(configFile)
require.NoError(t, err)

hclBytes, err := os.ReadFile(configFile)
Expand Down
2 changes: 1 addition & 1 deletion terraform/getproviders/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func createFakeZipArchive(t *testing.T, content []byte) string {
t.Helper()

file, err := os.CreateTemp("", "*")
file, err := os.CreateTemp(t.TempDir(), "*")
require.NoError(t, err)
defer file.Close()

Expand Down
13 changes: 4 additions & 9 deletions terraform/getter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package terraform_test
import (
"context"
"net/url"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -111,12 +110,10 @@ func TestTFRGetterRootDir(t *testing.T) {
testModuleURL, err := url.Parse("tfr://registry.terraform.io/terraform-aws-modules/vpc/aws?version=3.3.0")
require.NoError(t, err)

dstPath, err := os.MkdirTemp("", "")
require.NoError(t, err)
defer os.RemoveAll(dstPath)
tmpDir := t.TempDir()

// The dest path must not exist for go getter to work
moduleDestPath := filepath.Join(dstPath, "terraform-aws-vpc")
moduleDestPath := filepath.Join(tmpDir, "terraform-aws-vpc")
assert.False(t, files.FileExists(filepath.Join(moduleDestPath, "main.tf")))

tfrGetter := new(terraform.RegistryGetter)
Expand All @@ -132,12 +129,10 @@ func TestTFRGetterSubModule(t *testing.T) {
testModuleURL, err := url.Parse("tfr://registry.terraform.io/terraform-aws-modules/vpc/aws//modules/vpc-endpoints?version=3.3.0")
require.NoError(t, err)

dstPath, err := os.MkdirTemp("", "")
require.NoError(t, err)
defer os.RemoveAll(dstPath)
tmpDir := t.TempDir()

// The dest path must not exist for go getter to work
moduleDestPath := filepath.Join(dstPath, "terraform-aws-vpc")
moduleDestPath := filepath.Join(tmpDir, "terraform-aws-vpc")
assert.False(t, files.FileExists(filepath.Join(moduleDestPath, "main.tf")))

tfrGetter := new(terraform.RegistryGetter)
Expand Down
24 changes: 6 additions & 18 deletions test/helpers/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ type TerraformOutput struct {
func CopyEnvironment(t *testing.T, environmentPath string, includeInCopy ...string) string {
t.Helper()

tmpDir, err := os.MkdirTemp("", "terragrunt-test")
if err != nil {
t.Fatalf("Failed to create temp dir due to error: %v", err)
}
tmpDir := t.TempDir()

t.Logf("Copying %s to %s", environmentPath, tmpDir)

Expand All @@ -99,12 +96,9 @@ func CopyEnvironment(t *testing.T, environmentPath string, includeInCopy ...stri
func CreateTmpTerragruntConfig(t *testing.T, templatesPath string, s3BucketName string, lockTableName string, configFileName string) string {
t.Helper()

tmpFolder, err := os.MkdirTemp("", "terragrunt-test")
if err != nil {
t.Fatalf("Failed to create temp folder due to error: %v", err)
}
tmpDir := t.TempDir()

tmpTerragruntConfigFile := util.JoinPath(tmpFolder, configFileName)
tmpTerragruntConfigFile := util.JoinPath(tmpDir, configFileName)
originalTerragruntConfigPath := util.JoinPath(templatesPath, configFileName)
CopyTerragruntConfigAndFillPlaceholders(t, originalTerragruntConfigPath, tmpTerragruntConfigFile, s3BucketName, lockTableName, "not-used")

Expand All @@ -114,12 +108,9 @@ func CreateTmpTerragruntConfig(t *testing.T, templatesPath string, s3BucketName
func CreateTmpTerragruntConfigContent(t *testing.T, contents string, configFileName string) string {
t.Helper()

tmpFolder, err := os.MkdirTemp("", "terragrunt-test")
if err != nil {
t.Fatalf("Failed to create temp folder due to error: %v", err)
}
tmpDir := t.TempDir()

tmpTerragruntConfigFile := util.JoinPath(tmpFolder, configFileName)
tmpTerragruntConfigFile := util.JoinPath(tmpDir, configFileName)

if err := os.WriteFile(tmpTerragruntConfigFile, []byte(contents), readPermissions); err != nil {
t.Fatalf("Error writing temp Terragrunt config to %s: %v", tmpTerragruntConfigFile, err)
Expand Down Expand Up @@ -838,10 +829,7 @@ func RunTerragruntValidateInputs(t *testing.T, moduleDir string, extraArgs []str
func CreateTmpTerragruntConfigWithParentAndChild(t *testing.T, parentPath string, childRelPath string, s3BucketName string, parentConfigFileName string, childConfigFileName string) string {
t.Helper()

tmpDir, err := os.MkdirTemp("", "terragrunt-parent-child-test")
if err != nil {
t.Fatalf("Failed to create temp dir due to error: %v", err)
}
tmpDir := t.TempDir()

childDestPath := util.JoinPath(tmpDir, childRelPath)

Expand Down
10 changes: 4 additions & 6 deletions test/integration_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,9 @@ func TestTerragruntValidateInputsWithStrictModeDisabledAndUnusedInputs(t *testin
func TestRenderJSONConfig(t *testing.T) {
t.Parallel()

tmpDir, err := os.MkdirTemp("", "terragrunt-render-json-*")
require.NoError(t, err)
tmpDir := t.TempDir()

jsonOut := filepath.Join(tmpDir, "terragrunt_rendered.json")
defer os.RemoveAll(tmpDir)

helpers.CleanupTerraformFolder(t, fixtureRenderJSONMainModulePath)
helpers.CleanupTerraformFolder(t, fixtureRenderJSONDepModulePath)
Expand Down Expand Up @@ -292,10 +291,9 @@ func TestRenderJSONConfig(t *testing.T) {
func TestRenderJSONConfigWithIncludesDependenciesAndLocals(t *testing.T) {
t.Parallel()

tmpDir, err := os.MkdirTemp("", "terragrunt-render-json-*")
require.NoError(t, err)
tmpDir := t.TempDir()

jsonOut := filepath.Join(tmpDir, "terragrunt_rendered.json")
defer os.RemoveAll(tmpDir)

tmpEnvPath := helpers.CopyEnvironment(t, fixtureRenderJSONRegression)
workDir := filepath.Join(tmpEnvPath, fixtureRenderJSONRegression)
Expand Down
5 changes: 2 additions & 3 deletions test/integration_destroy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -42,7 +41,7 @@ func TestTerragruntDestroyOrder(t *testing.T) {

stdout, _, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt run-all destroy --terragrunt-non-interactive --terragrunt-forward-tf-stdout --terragrunt-working-dir "+rootPath)
require.NoError(t, err)
assert.Regexp(t, regexp.MustCompile(`(?smi)(?:(Module E|Module D|Module B).*){3}(?:(Module A|Module C).*){2}`), stdout)
assert.Regexp(t, `(?smi)(?:(Module E|Module D|Module B).*){3}(?:(Module A|Module C).*){2}`, stdout)
}

func TestTerragruntApplyDestroyOrder(t *testing.T) {
Expand All @@ -56,7 +55,7 @@ func TestTerragruntApplyDestroyOrder(t *testing.T) {

stdout, _, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt run-all apply -destroy --terragrunt-non-interactive --terragrunt-forward-tf-stdout --terragrunt-working-dir "+rootPath)
require.NoError(t, err)
assert.Regexp(t, regexp.MustCompile(`(?smi)(?:(Module E|Module D|Module B).*){3}(?:(Module A|Module C).*){2}`), stdout)
assert.Regexp(t, `(?smi)(?:(Module E|Module D|Module B).*){3}(?:(Module A|Module C).*){2}`, stdout)
}

func TestPreventDestroyOverride(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion test/integration_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func TestGetRepoRoot(t *testing.T) {
repoRoot, ok := outputs["repo_root"]

assert.True(t, ok)
assert.Regexp(t, "/tmp/terragrunt-.*/fixtures/get-repo-root", repoRoot.Value)
assert.Regexp(t, ".*/fixtures/get-repo-root", repoRoot.Value)
}

func TestGetWorkingDirBuiltInFunc(t *testing.T) {
Expand Down
Loading