Remove duplicate ProjectIDRegex variable (#1878)

* Remove duplicate ProjectIDRegex variable

* update validation and test for new regex
This commit is contained in:
Michael Haro 2018-09-11 13:27:14 -07:00 committed by Dana Hoffman
parent 8596ae8535
commit 24c9cc7481
2 changed files with 4 additions and 6 deletions

View File

@ -51,7 +51,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}$"
)
@ -168,7 +167,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))
}

View File

@ -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) {
@ -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())