mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-06-29 06:42:36 +00:00
Fix invalid assumptions about Project ID's in BQ table (#3486)
The bigquery table resource tries to infer the project and dataset from the table's full name. However, it does so incorrectly as it assumes that the project ID cannot have : or . characters in it, yet both are valid.
This commit is contained in:
parent
f86a85aab7
commit
ce1d1f6ee3
|
@ -4,7 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"regexp"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/hashicorp/terraform/helper/structure"
|
||||
|
@ -493,15 +493,16 @@ type bigQueryTableId struct {
|
|||
}
|
||||
|
||||
func parseBigQueryTableId(id string) (*bigQueryTableId, error) {
|
||||
parts := strings.FieldsFunc(id, func(r rune) bool { return r == ':' || r == '.' })
|
||||
|
||||
if len(parts) != 3 {
|
||||
// Expected format is "PROJECT:DATASET.TABLE", but the project can itself have . and : in it.
|
||||
// Those characters are not valid dataset or table components, so just split on the last two.
|
||||
matchRegex := regexp.MustCompile("^(.+):([^:.]+)\\.([^:.]+)$")
|
||||
subMatches := matchRegex.FindStringSubmatch(id)
|
||||
if subMatches == nil {
|
||||
return nil, fmt.Errorf("Invalid BigQuery table specifier. Expecting {project}:{dataset-id}.{table-id}, got %s", id)
|
||||
}
|
||||
|
||||
return &bigQueryTableId{
|
||||
Project: parts[0],
|
||||
DatasetId: parts[1],
|
||||
TableId: parts[2],
|
||||
Project: subMatches[1],
|
||||
DatasetId: subMatches[2],
|
||||
TableId: subMatches[3],
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user