Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add project import regex
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
slevenick authored and modular-magician committed Jul 17, 2019

Unverified

This user has not yet uploaded their public signing key.
1 parent 195f974 commit a266cee
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions google/resource_google_project.go
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit a266cee

Please sign in to comment.