-
-
Notifications
You must be signed in to change notification settings - Fork 986
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: configstack code refactoring * fix: tests * fix: tests * fix: hclparse options * fix: parse config * fix: unit test * fix: unit test * chore: print diagnostics in a human-friendly format * fix: lint * chore: fix unit tests, improve locals diagnostic * fix: unit test * chore: add integration test * fix: fixture * chore: disable SONAR for unit tests * fix: test * chore: sonar properties * chore: code improvements * chore: update sonarcloud properties * chore: update docs * fix: grammar * chore: update docs * chore: custom errors renaming * chore: code improvements * fix: review commetns
- Loading branch information
1 parent
e47fa39
commit e37d71e
Showing
70 changed files
with
4,770 additions
and
3,310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Source File Exclusions: Patterns used to exclude some source files from analysis. | ||
sonar.exclusions=**/*_test.go | ||
# Test File Inclusions: Patterns used to include some test files and only these ones in analysis. | ||
sonar.test.inclusions=**/*_test.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package hclvalidate | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/gruntwork-io/terragrunt/config" | ||
"github.com/gruntwork-io/terragrunt/config/hclparse" | ||
"github.com/gruntwork-io/terragrunt/configstack" | ||
"github.com/gruntwork-io/terragrunt/internal/view" | ||
"github.com/gruntwork-io/terragrunt/internal/view/diagnostic" | ||
"github.com/gruntwork-io/terragrunt/options" | ||
"github.com/hashicorp/hcl/v2" | ||
) | ||
|
||
func Run(ctx context.Context, opts *Options) (er error) { | ||
var diags diagnostic.Diagnostics | ||
|
||
parseOptions := []hclparse.Option{ | ||
hclparse.WithDiagnosticsHandler(func(file *hcl.File, hclDiags hcl.Diagnostics) (hcl.Diagnostics, error) { | ||
for _, hclDiag := range hclDiags { | ||
if !diags.Contains(hclDiag) { | ||
newDiag := diagnostic.NewDiagnostic(file, hclDiag) | ||
diags = append(diags, newDiag) | ||
} | ||
} | ||
return nil, nil | ||
}), | ||
} | ||
|
||
opts.SkipOutput = true | ||
opts.NonInteractive = true | ||
opts.RunTerragrunt = func(ctx context.Context, opts *options.TerragruntOptions) error { | ||
_, err := config.ReadTerragruntConfig(ctx, opts, parseOptions) | ||
return err | ||
} | ||
|
||
stack, err := configstack.FindStackInSubfolders(ctx, opts.TerragruntOptions, configstack.WithParseOptions(parseOptions)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
stackErr := stack.Run(ctx, opts.TerragruntOptions) | ||
|
||
if len(diags) > 0 { | ||
if err := writeDiagnostics(opts, diags); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return stackErr | ||
} | ||
|
||
func writeDiagnostics(opts *Options, diags diagnostic.Diagnostics) error { | ||
render := view.NewHumanRender(opts.DisableLogColors) | ||
if opts.JSONOutput { | ||
render = view.NewJSONRender() | ||
} | ||
|
||
writer := view.NewWriter(opts.Writer, render) | ||
|
||
if opts.InvalidConfigPath { | ||
return writer.InvalidConfigPath(diags) | ||
} | ||
|
||
return writer.Diagnostics(diags) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// `hclvalidate` command recursively looks for hcl files in the directory tree starting at workingDir, and validates them | ||
// based on the language style guides provided by Hashicorp. This is done using the official hcl2 library. | ||
|
||
package hclvalidate | ||
|
||
import ( | ||
"github.com/gruntwork-io/terragrunt/options" | ||
"github.com/gruntwork-io/terragrunt/pkg/cli" | ||
) | ||
|
||
const ( | ||
CommandName = "hclvalidate" | ||
|
||
InvalidFlagName = "terragrunt-hclvalidate-invalid" | ||
InvalidEnvVarName = "TERRAGRUNT_HCLVALIDATE_INVALID" | ||
|
||
JSONOutputFlagName = "terragrunt-hclvalidate-json" | ||
JSONOutputEnvVarName = "TERRAGRUNT_HCLVALIDATE_JSON" | ||
) | ||
|
||
func NewFlags(opts *Options) cli.Flags { | ||
return cli.Flags{ | ||
&cli.BoolFlag{ | ||
Name: InvalidFlagName, | ||
EnvVar: InvalidEnvVarName, | ||
Usage: "Show a list of files with invalid configuration.", | ||
Destination: &opts.InvalidConfigPath, | ||
}, | ||
&cli.BoolFlag{ | ||
Name: JSONOutputFlagName, | ||
EnvVar: JSONOutputEnvVarName, | ||
Destination: &opts.JSONOutput, | ||
Usage: "Output the result in JSON format.", | ||
}, | ||
} | ||
} | ||
|
||
func NewCommand(generalOpts *options.TerragruntOptions) *cli.Command { | ||
opts := NewOptions(generalOpts) | ||
|
||
return &cli.Command{ | ||
Name: CommandName, | ||
Usage: "Find all hcl files from the config stack and validate them.", | ||
Flags: NewFlags(opts).Sort(), | ||
Action: func(ctx *cli.Context) error { return Run(ctx, opts) }, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package hclvalidate | ||
|
||
import "github.com/gruntwork-io/terragrunt/options" | ||
|
||
type Options struct { | ||
*options.TerragruntOptions | ||
|
||
InvalidConfigPath bool | ||
JSONOutput bool | ||
} | ||
|
||
func NewOptions(general *options.TerragruntOptions) *Options { | ||
return &Options{ | ||
TerragruntOptions: general, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.