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

Support long terraform variable names in ErrMissingVar #110

Merged
merged 2 commits into from
Nov 27, 2020
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
2 changes: 1 addition & 1 deletion tfexec/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var (
// The "Required variable not set:" case is for 0.11
missingVarErrRegexp = regexp.MustCompile(`Error: No value for required variable|Error: Required variable not set:`)
missingVarNameRegexp = regexp.MustCompile(`The root module input variable "(.+)" is not set, and has no default|Error: Required variable not set: (.+)`)
missingVarNameRegexp = regexp.MustCompile(`The root module input variable\s"(.+)"\sis\snot\sset,\sand\shas\sno\sdefault|Error: Required variable not set: (.+)`)
radeksimko marked this conversation as resolved.
Show resolved Hide resolved

usageRegexp = regexp.MustCompile(`Too many command line arguments|^Usage: .*Options:.*|Error: Invalid -\d+ option`)

Expand Down
27 changes: 23 additions & 4 deletions tfexec/internal/e2etest/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ func TestMissingVar(t *testing.T) {
t.Fatalf("err during init: %s", err)
}

_, err = tf.Plan(context.Background())
// Variable names from testdata/var/main.tf
shortVarName := "no_default"
longVarName := "no_default_really_long_variable_name_that_will_line_wrap_tf_output"

// Test for ErrMissingVar and properly formatted error message on shorter variable names
_, err = tf.Plan(context.Background(), tfexec.Var(longVarName+"=foo"))
if err == nil {
t.Fatalf("expected error running Plan, none returned")
}
Expand All @@ -52,11 +57,25 @@ func TestMissingVar(t *testing.T) {
t.Fatalf("expected ErrMissingVar, got %T, %s", err, err)
}

if e.VariableName != "no_default" {
t.Fatalf("expected missing no_default, got %q", e.VariableName)
if e.VariableName != shortVarName {
t.Fatalf("expected missing %s, got %q", shortVarName, e.VariableName)
}

// Test for ErrMissingVar and properly formatted error message on long variable names
_, err = tf.Plan(context.Background(), tfexec.Var(shortVarName+"=foo"))
if err == nil {
t.Fatalf("expected error running Plan, none returned")
}
if !errors.As(err, &e) {
t.Fatalf("expected ErrMissingVar, got %T, %s", err, err)
}

if e.VariableName != longVarName {
t.Fatalf("expected missing %s, got %q", longVarName, e.VariableName)
}

_, err = tf.Plan(context.Background(), tfexec.Var("no_default=foo"))
// Test for no error when all variables have a value
_, err = tf.Plan(context.Background(), tfexec.Var(shortVarName+"=foo"), tfexec.Var(longVarName+"=foo"))
if err != nil {
t.Fatalf("expected no error, got %s", err)
}
Expand Down
5 changes: 4 additions & 1 deletion tfexec/internal/e2etest/testdata/var/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ variable "default" {
}

variable "no_default" {
}
}

variable "no_default_really_long_variable_name_that_will_line_wrap_tf_output" {
}