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

Remove duplicate ProjectIDRegex variable #1878

Merged
merged 2 commits into from
Sep 11, 2018
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
3 changes: 1 addition & 2 deletions google/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ var (
// Format of default App Engine service accounts created by Google
AppEngineServiceAccountNameRegex = ProjectRegex + "@appspot.gserviceaccount.com"

ProjectIDRegex = "^[a-z][a-z0-9-]{4,28}[a-z0-9]$"
ProjectNameRegex = "^[A-Za-z0-9-'\"\\s!]{4,30}$"
)

Expand Down Expand Up @@ -166,7 +165,7 @@ func validateProjectID() schema.SchemaValidateFunc {
return func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)

if !regexp.MustCompile(ProjectIDRegex).MatchString(value) {
if !regexp.MustCompile("^" + ProjectRegex + "$").MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q project_id must be 6 to 30 with lowercase letters, digits, hyphens and start with a letter. Trailing hyphens are prohibited.", value))
}
Expand Down
13 changes: 6 additions & 7 deletions google/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package google

import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"regexp"
"strings"
"testing"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
)

func TestValidateGCPName(t *testing.T) {
Expand Down Expand Up @@ -247,15 +248,15 @@ func TestOrEmpty(t *testing.T) {
ExpectValidationErrors bool
}{
"accept empty value": {
Value: "",
Value: "",
ExpectValidationErrors: false,
},
"non empty value is accepted when valid": {
Value: "valid",
Value: "valid",
ExpectValidationErrors: false,
},
"non empty value is rejected if invalid": {
Value: "invalid",
Value: "invalid",
ExpectValidationErrors: true,
},
}
Expand All @@ -282,11 +283,9 @@ func TestValidateProjectID(t *testing.T) {

// With errors
{TestName: "empty", Value: "", ExpectError: true},
{TestName: "starts with a number", Value: "1foobar", ExpectError: true},
{TestName: "has an slash", Value: "foo/bar", ExpectError: true},
{TestName: "has an upercase letter", Value: "foo-Bar", ExpectError: true},
{TestName: "has a final hyphen", Value: "foo-bar-", ExpectError: true},
{TestName: "too long", Value: strings.Repeat("a", 31), ExpectError: true},
}

es := testStringValidationCases(x, validateProjectID())
Expand Down