From 88b07268de3c636a7185eb1c26da1da52639bd77 Mon Sep 17 00:00:00 2001 From: Sam Levenick Date: Wed, 17 Jul 2019 20:14:54 +0000 Subject: [PATCH] Add project import regex Signed-off-by: Modular Magician --- google-beta/resource_google_project.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/google-beta/resource_google_project.go b/google-beta/resource_google_project.go index b271b63af7..ce1031d3d6 100644 --- a/google-beta/resource_google_project.go +++ b/google-beta/resource_google_project.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "net/http" + "regexp" "strconv" "strings" "time" @@ -448,6 +449,17 @@ func resourceGoogleProjectDelete(d *schema.ResourceData, meta interface{}) error } func resourceProjectImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + pid := d.Id() + // Project id must start with a letter. This prevents users from importing with project number + matched, err := regexp.MatchString("^[^\\d]", pid) + if err != nil { + return nil, fmt.Errorf("Error matching project %q: %s", pid, err) + } + + if matched == false { + return nil, fmt.Errorf("Error importing project %q, please use project_id", pid) + } + // Explicitly set to default as a workaround for `ImportStateVerify` tests, and so that users // don't see a diff immediately after import. d.Set("auto_create_network", true)