Skip to content

Commit 979efc8

Browse files
authored
feat: Adding stylecheck lint (#3354)
* fix: Adding workaround for DDB eventual consistency of tags * fix: Fixing dynamodb check * fix: Removing unnecessary extra wait * feat: Merging in `.golangci.yml` * feat: Addressing `stylecheck` lint errors * fix: Fixing tflint tests * fix: Fixing lints post rebase * fix: Resolving merge conflicts from `main` * fix: Privatizing fixture variable names * fix: Privatizing more test constants * fix: Resolving some merge conflicts * fix: Adjusting method receiver renames so that they aren't all single characters * fix: Fixing merge conflicts * fix: Setting refs to commits instead of tags * fix: Reseting fixtures to track `main` * fix: Fixing more tests * fix: Linting * fix: Trying to fix test by not using tenv * fix: Fixed grammer mistake
1 parent 64baa28 commit 979efc8

File tree

147 files changed

+1539
-1340
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+1539
-1340
lines changed

.golangci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,17 @@ linters:
6868
- wsl
6969
- thelper
7070
- wastedassign
71+
- stylecheck
7172

7273
enable-all: false
7374
disable:
7475
- depguard
7576
- gosec
7677
- gocyclo
7778
- exhaustruct
79+
- nolintlint
80+
- wrapcheck
81+
- varnamelen
7882

7983
fast: false
8084
mnd:

aws_helper/config.go awshelper/config.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package aws_helper
1+
// Package awshelper provides helper functions for working with AWS services.
2+
package awshelper
23

34
import (
45
"fmt"
@@ -20,7 +21,7 @@ import (
2021
"github.com/gruntwork-io/terragrunt/options"
2122
)
2223

23-
// A representation of the configuration options for an AWS Session
24+
// AwsSessionConfig is a representation of the configuration options for an AWS Session
2425
type AwsSessionConfig struct {
2526
Region string
2627
CustomS3Endpoint string
@@ -41,7 +42,7 @@ var addUserAgent = request.NamedHandler{
4142
"terragrunt", version.GetVersion()),
4243
}
4344

44-
// Returns an AWS session object for the given config region (required), profile name (optional), and IAM role to assume
45+
// CreateAwsSessionFromConfig returns an AWS session object for the given config region (required), profile name (optional), and IAM role to assume
4546
// (optional), ensuring that the credentials are available.
4647
func CreateAwsSessionFromConfig(config *AwsSessionConfig, terragruntOptions *options.TerragruntOptions) (*session.Session, error) {
4748
defaultResolver := endpoints.DefaultResolver()
@@ -185,7 +186,7 @@ func getCredentialsFromEnvs(opts *options.TerragruntOptions) *credentials.Creden
185186
return credentials.NewStaticCredentials(accessKeyID, secretAccessKey, sessionToken)
186187
}
187188

188-
// Returns an AWS session object. The session is configured by either:
189+
// CreateAwsSession returns an AWS session object. The session is configured by either:
189190
// - The provided AwsSessionConfig struct, which specifies region (required), profile name (optional), and IAM role to
190191
// assume (optional).
191192
// - The provided TerragruntOptions struct, which specifies any IAM role to assume (optional).
@@ -238,7 +239,7 @@ func CreateAwsSession(config *AwsSessionConfig, terragruntOptions *options.Terra
238239
return sess, nil
239240
}
240241

241-
// Make API calls to AWS to assume the IAM role specified and return the temporary AWS credentials to use that role
242+
// AssumeIamRole makes API calls to AWS to assume the IAM role specified and return the temporary AWS credentials to use that role.
242243
func AssumeIamRole(iamRoleOpts options.IAMRoleOptions) (*sts.Credentials, error) {
243244
sessionOptions := session.Options{SharedConfigState: session.SharedConfigEnable}
244245

@@ -318,7 +319,7 @@ func AssumeIamRole(iamRoleOpts options.IAMRoleOptions) (*sts.Credentials, error)
318319
return resp.Credentials, nil
319320
}
320321

321-
// Return the AWS caller identity associated with the current set of credentials
322+
// GetAWSCallerIdentity returns the AWS caller identity associated with the current set of credentials
322323
func GetAWSCallerIdentity(config *AwsSessionConfig, terragruntOptions *options.TerragruntOptions) (sts.GetCallerIdentityOutput, error) {
323324
sess, err := CreateAwsSession(config, terragruntOptions)
324325
if err != nil {
@@ -340,7 +341,7 @@ func ValidateAwsSession(config *AwsSessionConfig, terragruntOptions *options.Ter
340341
return err
341342
}
342343

343-
// Get the AWS Partition of the current session configuration
344+
// GetAWSPartition gets the AWS Partition of the current session configuration
344345
func GetAWSPartition(config *AwsSessionConfig, terragruntOptions *options.TerragruntOptions) (string, error) {
345346
identity, err := GetAWSCallerIdentity(config, terragruntOptions)
346347
if err != nil {
@@ -355,7 +356,7 @@ func GetAWSPartition(config *AwsSessionConfig, terragruntOptions *options.Terrag
355356
return arn.Partition, nil
356357
}
357358

358-
// Get the AWS account ID of the current session configuration
359+
// GetAWSAccountID gets the AWS account ID of the current session configuration.
359360
func GetAWSAccountID(config *AwsSessionConfig, terragruntOptions *options.TerragruntOptions) (string, error) {
360361
identity, err := GetAWSCallerIdentity(config, terragruntOptions)
361362
if err != nil {
@@ -365,7 +366,7 @@ func GetAWSAccountID(config *AwsSessionConfig, terragruntOptions *options.Terrag
365366
return *identity.Account, nil
366367
}
367368

368-
// Get the ARN of the AWS identity associated with the current set of credentials
369+
// GetAWSIdentityArn gets the ARN of the AWS identity associated with the current set of credentials.
369370
func GetAWSIdentityArn(config *AwsSessionConfig, terragruntOptions *options.TerragruntOptions) (string, error) {
370371
identity, err := GetAWSCallerIdentity(config, terragruntOptions)
371372
if err != nil {
@@ -375,7 +376,7 @@ func GetAWSIdentityArn(config *AwsSessionConfig, terragruntOptions *options.Terr
375376
return *identity.Arn, nil
376377
}
377378

378-
// Get the AWS user ID of the current session configuration
379+
// GetAWSUserID gets the AWS user ID of the current session configuration.
379380
func GetAWSUserID(config *AwsSessionConfig, terragruntOptions *options.TerragruntOptions) (string, error) {
380381
identity, err := GetAWSCallerIdentity(config, terragruntOptions)
381382
if err != nil {

aws_helper/config_test.go awshelper/config_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//go:build aws
22

3-
package aws_helper_test
3+
package awshelper_test
44

55
import (
66
"testing"
77

88
"github.com/aws/aws-sdk-go/aws/request"
99
"github.com/aws/aws-sdk-go/service/sts"
10-
"github.com/gruntwork-io/terragrunt/aws_helper"
10+
"github.com/gruntwork-io/terragrunt/awshelper"
1111
"github.com/gruntwork-io/terragrunt/options"
1212
"github.com/stretchr/testify/assert"
1313
"github.com/stretchr/testify/require"
@@ -16,7 +16,7 @@ import (
1616
func TestAwsIsAddedInUserAgent(t *testing.T) {
1717
t.Parallel()
1818

19-
sess, err := aws_helper.CreateAwsSession(nil, options.NewTerragruntOptions())
19+
sess, err := awshelper.CreateAwsSession(nil, options.NewTerragruntOptions())
2020
require.NoError(t, err)
2121

2222
op := &request.Operation{
@@ -36,7 +36,7 @@ func TestAwsIsAddedInUserAgent(t *testing.T) {
3636
func TestAwsSessionValidationFail(t *testing.T) {
3737
t.Parallel()
3838

39-
err := aws_helper.ValidateAwsSession(&aws_helper.AwsSessionConfig{
39+
err := awshelper.ValidateAwsSession(&awshelper.AwsSessionConfig{
4040
Region: "not-existing-region",
4141
CredsFilename: "/tmp/not-existing-file",
4242
}, options.NewTerragruntOptions())

aws_helper/policy.go awshelper/policy.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package aws_helper
1+
package awshelper
22

33
import "encoding/json"
44

@@ -34,10 +34,10 @@ func UnmarshalPolicy(policy string) (Policy, error) {
3434
}
3535

3636
func MarshalPolicy(policy Policy) ([]byte, error) {
37-
policyJson, err := json.Marshal(policy)
37+
policyJSON, err := json.Marshal(policy)
3838
if err != nil {
3939
return nil, err
4040
}
4141

42-
return policyJson, nil
42+
return policyJSON, nil
4343
}

aws_helper/policy_test.go awshelper/policy_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//go:build aws
22

3-
package aws_helper_test
3+
package awshelper_test
44

55
import (
66
"testing"
77

8-
"github.com/gruntwork-io/terragrunt/aws_helper"
8+
"github.com/gruntwork-io/terragrunt/awshelper"
99
"github.com/stretchr/testify/assert"
1010
"github.com/stretchr/testify/require"
1111
)
@@ -56,7 +56,7 @@ const arraysPolicy = `
5656
func TestAwsUnmarshalStringActionResource(t *testing.T) {
5757
t.Parallel()
5858

59-
bucketPolicy, err := aws_helper.UnmarshalPolicy(simplePolicy)
59+
bucketPolicy, err := awshelper.UnmarshalPolicy(simplePolicy)
6060
require.NoError(t, err)
6161
assert.NotNil(t, bucketPolicy)
6262
assert.Len(t, bucketPolicy.Statement, 1)
@@ -77,14 +77,14 @@ func TestAwsUnmarshalStringActionResource(t *testing.T) {
7777
assert.Fail(t, "Expected string type for Resource")
7878
}
7979

80-
out, err := aws_helper.MarshalPolicy(bucketPolicy)
80+
out, err := awshelper.MarshalPolicy(bucketPolicy)
8181
require.NoError(t, err)
8282
assert.NotContains(t, string(out), "null")
8383
}
8484

8585
func TestAwsUnmarshalActionResourceList(t *testing.T) {
8686
t.Parallel()
87-
bucketPolicy, err := aws_helper.UnmarshalPolicy(arraysPolicy)
87+
bucketPolicy, err := awshelper.UnmarshalPolicy(arraysPolicy)
8888
require.NoError(t, err)
8989
assert.NotNil(t, bucketPolicy)
9090
assert.Len(t, bucketPolicy.Statement, 1)
@@ -107,7 +107,7 @@ func TestAwsUnmarshalActionResourceList(t *testing.T) {
107107
assert.Fail(t, "Expected []string type for Resource")
108108
}
109109

110-
out, err := aws_helper.MarshalPolicy(bucketPolicy)
110+
out, err := awshelper.MarshalPolicy(bucketPolicy)
111111
require.NoError(t, err)
112112
assert.NotContains(t, string(out), "null")
113113
}

cli/app.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package cli configures the Terragrunt CLI app and its commands.
12
package cli
23

34
import (
@@ -146,7 +147,7 @@ func (app *App) RunContext(ctx context.Context, args []string) error {
146147
return nil
147148
}
148149

149-
// This set of commands is also used in unit tests
150+
// TerragruntCommands returns the set of Terragrunt commands.
150151
func TerragruntCommands(opts *options.TerragruntOptions) cli.Commands {
151152
cmds := cli.Commands{
152153
runall.NewCommand(opts), // runAction-all
@@ -171,7 +172,7 @@ func TerragruntCommands(opts *options.TerragruntOptions) cli.Commands {
171172
return cmds
172173
}
173174

174-
// Wrap CLI command execution with setting of telemetry context and labels, if telemetry is disabled, just runAction the command.
175+
// WrapWithTelemetry wraps CLI command execution with setting of telemetry context and labels, if telemetry is disabled, just runAction the command.
175176
func WrapWithTelemetry(opts *options.TerragruntOptions) func(ctx *cli.Context, action cli.ActionFunc) error {
176177
return func(ctx *cli.Context, action cli.ActionFunc) error {
177178
return telemetry.Telemetry(ctx.Context, opts, fmt.Sprintf("%s %s", ctx.Command.Name, opts.TerraformCommand), map[string]interface{}{

cli/commands/aws-provider-patch/action.go

+8-36
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,3 @@
1-
// `aws-provider-patch` command finds all Terraform modules nested in the current code (i.e., in the .terraform/modules
2-
// folder), looks for provider "aws" { ... } blocks in those modules, and overwrites the attributes in those provider
3-
// blocks with the attributes specified in terragrntOptions.
4-
//
5-
// For example, if were running Terragrunt against code that contained a module:
6-
//
7-
// module "example" {
8-
// source = "<URL>"
9-
// }
10-
//
11-
// When you run 'init', Terraform would download the code for that module into .terraform/modules. This function would
12-
// scan that module code for provider blocks:
13-
//
14-
// provider "aws" {
15-
// region = var.aws_region
16-
// }
17-
//
18-
// And if AwsProviderPatchOverrides in opts was set to map[string]string{"region": "us-east-1"}, then this
19-
// method would update the module code to:
20-
//
21-
// provider "aws" {
22-
// region = "us-east-1"
23-
// }
24-
//
25-
// This is a temporary workaround for a Terraform bug (https://github.com/hashicorp/terraform/issues/13018) where
26-
// any dynamic values in nested provider blocks are not handled correctly when you call 'terraform import', so by
27-
// temporarily hard-coding them, we can allow 'import' to work.
28-
291
package awsproviderpatch
302

313
import (
@@ -90,8 +62,8 @@ func runAwsProviderPatch(ctx context.Context, opts *options.TerragruntOptions, c
9062
return nil
9163
}
9264

93-
// The format we expect in the .terraform/modules/modules.json file
94-
type TerraformModulesJson struct {
65+
// TerraformModulesJSON is the format we expect in the .terraform/modules/modules.json file
66+
type TerraformModulesJSON struct {
9567
Modules []TerraformModule `json:"Modules"`
9668
}
9769

@@ -115,25 +87,25 @@ func findAllTerraformFilesInModules(opts *options.TerragruntOptions) ([]string,
11587
// API, so the way we parse/read this modules.json file may break in future Terraform versions. Note that we
11688
// can't use the official HashiCorp code to parse this file, as it's marked internal:
11789
// https://github.com/hashicorp/terraform/blob/master/internal/modsdir/manifest.go
118-
modulesJsonPath := util.JoinPath(opts.DataDir(), "modules", "modules.json")
90+
modulesJSONPath := util.JoinPath(opts.DataDir(), "modules", "modules.json")
11991

120-
if !util.FileExists(modulesJsonPath) {
92+
if !util.FileExists(modulesJSONPath) {
12193
return nil, nil
12294
}
12395

124-
modulesJsonContents, err := os.ReadFile(modulesJsonPath)
96+
modulesJSONContents, err := os.ReadFile(modulesJSONPath)
12597
if err != nil {
12698
return nil, errors.WithStackTrace(err)
12799
}
128100

129-
var terraformModulesJson TerraformModulesJson
130-
if err := json.Unmarshal(modulesJsonContents, &terraformModulesJson); err != nil {
101+
var terraformModulesJSON TerraformModulesJSON
102+
if err := json.Unmarshal(modulesJSONContents, &terraformModulesJSON); err != nil {
131103
return nil, errors.WithStackTrace(err)
132104
}
133105

134106
var terraformFiles []string
135107

136-
for _, module := range terraformModulesJson.Modules {
108+
for _, module := range terraformModulesJSON.Modules {
137109
if module.Key != "" && module.Dir != "" {
138110
moduleAbsPath := module.Dir
139111
if !filepath.IsAbs(moduleAbsPath) {

cli/commands/aws-provider-patch/command.go

+29
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
// Package awsproviderpatch provides the `aws-provider-patch` command.
2+
//
3+
// The `aws-provider-patch` command finds all Terraform modules nested in the current code (i.e., in the .terraform/modules
4+
// folder), looks for provider "aws" { ... } blocks in those modules, and overwrites the attributes in those provider
5+
// blocks with the attributes specified in terragrntOptions.
6+
//
7+
// For example, if were running Terragrunt against code that contained a module:
8+
//
9+
// module "example" {
10+
// source = "<URL>"
11+
// }
12+
//
13+
// When you run 'init', Terraform would download the code for that module into .terraform/modules. This function would
14+
// scan that module code for provider blocks:
15+
//
16+
// provider "aws" {
17+
// region = var.aws_region
18+
// }
19+
//
20+
// And if AwsProviderPatchOverrides in opts was set to map[string]string{"region": "us-east-1"}, then this
21+
// method would update the module code to:
22+
//
23+
// provider "aws" {
24+
// region = "us-east-1"
25+
// }
26+
//
27+
// This is a temporary workaround for a Terraform bug (https://github.com/hashicorp/terraform/issues/13018) where
28+
// any dynamic values in nested provider blocks are not handled correctly when you call 'terraform import', so by
29+
// temporarily hard-coding them, we can allow 'import' to work.
130
package awsproviderpatch
231

332
import (

cli/commands/catalog/command.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package catalog provides the ability to interact with a catalog of OpenTofu/Terraform modules
2+
// via the `terragrunt catalog` command.
13
package catalog
24

35
import (

cli/commands/catalog/module/module.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package module provides a struct to represent an OpenTofu/Terraform module.
12
package module
23

34
import (

cli/commands/catalog/module/repo.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,16 @@ func (repo *Repo) clone(ctx context.Context) error {
185185
}
186186
}
187187

188-
sourceUrl, err := terraform.ToSourceUrl(repo.cloneURL, "")
188+
sourceURL, err := terraform.ToSourceURL(repo.cloneURL, "")
189189
if err != nil {
190190
return err
191191
}
192192

193-
repo.cloneURL = sourceUrl.String()
193+
repo.cloneURL = sourceURL.String()
194194

195195
repo.logger.Infof("Cloning repository %q to temporary directory %q", repo.cloneURL, repo.path)
196196

197-
if err := getter.Get(repo.path, strings.Trim(sourceUrl.String(), "/"), getter.WithContext(ctx)); err != nil {
197+
if err := getter.Get(repo.path, strings.Trim(sourceURL.String(), "/"), getter.WithContext(ctx)); err != nil {
198198
return errors.WithStackTrace(err)
199199
}
200200

cli/commands/catalog/tui/command/scaffold.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package command provides the implementation of the terragrunt scaffold command
2+
// This command is used to scaffold a new Terragrunt unit in the current directory.
13
package command
24

35
import (

cli/commands/catalog/tui/components/buttonbar/buttonbar.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package buttonbar provides a bubbletea component that displays an inline list of buttons.
12
package buttonbar
23

34
import (

cli/commands/catalog/tui/tui.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package tui provides a text-based user interface for the Terragrunt catalog command.
12
package tui
23

34
import (

0 commit comments

Comments
 (0)