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

feat: disable terraform command validation #2697

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions cli/commands/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
FlagNameTerragruntIncludeModulePrefix = "terragrunt-include-module-prefix"
FlagNameTerragruntFailOnStateBucketCreation = "terragrunt-fail-on-state-bucket-creation"
FlagNameTerragruntDisableBucketUpdate = "terragrunt-disable-bucket-update"
FlagNameTerragruntDisableCommandValidation = "terragrunt-disable-command-validation"

FlagNameHelp = "help"
FlagNameVersion = "version"
Expand Down Expand Up @@ -231,6 +232,12 @@ func NewGlobalFlags(opts *options.TerragruntOptions) cli.Flags {
EnvVar: "TERRAGRUNT_DISABLE_BUCKET_UPDATE",
Usage: "When this flag is set Terragrunt will not update the remote state bucket.",
},
&cli.BoolFlag{
Name: FlagNameTerragruntDisableCommandValidation,
Destination: &opts.DisableCommandValidation,
EnvVar: "TERRAGRUNT_DISABLE_COMMAND_VALIDATION",
Usage: "When this flag is set, Terragrunt will not validate the terraform command.",
},
}

flags.Sort()
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/terraform/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func action(opts *options.TerragruntOptions) func(ctx *cli.Context) error {
opts.CheckDependentModules = true
}

if !collections.ListContainsElement(nativeTerraformCommands, opts.TerraformCommand) {
if !opts.DisableCommandValidation && !collections.ListContainsElement(nativeTerraformCommands, opts.TerraformCommand) {
return errors.WithStackTrace(WrongTerraformCommand(opts.TerraformCommand))
}

Expand Down
8 changes: 8 additions & 0 deletions docs/_docs/04_reference/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ prefix `--terragrunt-` (e.g., `--terragrunt-config`). The currently available op
- [terragrunt-include-module-prefix](#terragrunt-include-module-prefix)
- [terragrunt-fail-on-state-bucket-creation](#terragrunt-fail-on-state-bucket-creation)
- [terragrunt-disable-bucket-update](#terragrunt-disable-bucket-update)
- [terragrunt-disable-command-validation](#terragrunt-disable-command-validation)

### terragrunt-config

Expand Down Expand Up @@ -1000,3 +1001,10 @@ When this flag is set, Terragrunt will fail and exit if it is necessary to creat
**Environment Variable**: `TERRAGRUNT_DISABLE_BUCKET_UPDATE` (set to `true`)

When this flag is set, Terragrunt does not update the remote state bucket, which is useful to set if the state bucket is managed by a third party.

### terragrunt-disable-command-validation

**CLI Arg**: `--terragrunt-disable-command-validation`
**Environment Variable**: `TERRAGRUNT_DISABLE_COMMAND_VALIDATION` (set to `true`)

When this flag is set, Terragrunt will not validate the terraform command, which can be useful when need to use non-existent commands in hooks.
3 changes: 3 additions & 0 deletions options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ type TerragruntOptions struct {

// Controls if s3 bucket should be updated or skipped
DisableBucketUpdate bool

// Disalbes validation terraform command
DisableCommandValidation bool
}

// IAMOptions represents options that are used by Terragrunt to assume an IAM role.
Expand Down
7 changes: 5 additions & 2 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,11 @@ func TestTerraformCommandCliArgs(t *testing.T) {
"",
terraform.WrongTerraformCommand("paln"),
},
{
[]string{"paln", "--terragrunt-disable-command-validation"},
"Terraform invocation failed", // error caused by running terraform with the wrong command
nil,
},
}

for _, testCase := range testCases {
Expand All @@ -1309,8 +1314,6 @@ func TestTerraformCommandCliArgs(t *testing.T) {
err := runTerragruntCommand(t, cmd, &stdout, &stderr)
if testCase.expectedErr != nil {
assert.ErrorIs(t, err, testCase.expectedErr)
} else {
assert.NoError(t, err)
}

output := stdout.String()
Expand Down