mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-01 07:42:40 +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"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"regexp"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"github.com/hashicorp/terraform/helper/structure"
|
"github.com/hashicorp/terraform/helper/structure"
|
||||||
|
@ -493,15 +493,16 @@ type bigQueryTableId struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseBigQueryTableId(id string) (*bigQueryTableId, error) {
|
func parseBigQueryTableId(id string) (*bigQueryTableId, error) {
|
||||||
parts := strings.FieldsFunc(id, func(r rune) bool { return r == ':' || r == '.' })
|
// 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.
|
||||||
if len(parts) != 3 {
|
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 nil, fmt.Errorf("Invalid BigQuery table specifier. Expecting {project}:{dataset-id}.{table-id}, got %s", id)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &bigQueryTableId{
|
return &bigQueryTableId{
|
||||||
Project: parts[0],
|
Project: subMatches[1],
|
||||||
DatasetId: parts[1],
|
DatasetId: subMatches[2],
|
||||||
TableId: parts[2],
|
TableId: subMatches[3],
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user