Skip to content

Commit 976f463

Browse files
nat-hendersonmodular-magician
authored andcommitted
Initial addition of generated spanner database to terraform.
Signed-off-by: Modular Magician <[email protected]>
1 parent bb4697d commit 976f463

8 files changed

+361
-254
lines changed

google/iam_spanner_database.go

+23-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ func NewSpannerDatabaseIamUpdater(d *schema.ResourceData, config *Config) (Resou
5151
}
5252

5353
func SpannerDatabaseIdParseFunc(d *schema.ResourceData, config *Config) error {
54-
_, err := resourceSpannerDatabaseImport("database")(d, config)
55-
return err
54+
return parseImportId([]string{"(?P<project>[^/]+)/(?P<instance>[^/]+)/(?P<database>[^/]+)"}, d, config)
5655
}
5756

5857
func (u *SpannerDatabaseIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
@@ -130,3 +129,25 @@ func spannerToResourceManagerPolicy(p *spanner.Policy) (*cloudresourcemanager.Po
130129
}
131130
return out, nil
132131
}
132+
133+
type spannerDatabaseId struct {
134+
Project string
135+
Instance string
136+
Database string
137+
}
138+
139+
func (s spannerDatabaseId) terraformId() string {
140+
return fmt.Sprintf("%s/%s/%s", s.Project, s.Instance, s.Database)
141+
}
142+
143+
func (s spannerDatabaseId) parentProjectUri() string {
144+
return fmt.Sprintf("projects/%s", s.Project)
145+
}
146+
147+
func (s spannerDatabaseId) parentInstanceUri() string {
148+
return fmt.Sprintf("%s/instances/%s", s.parentProjectUri(), s.Instance)
149+
}
150+
151+
func (s spannerDatabaseId) databaseUri() string {
152+
return fmt.Sprintf("%s/databases/%s", s.parentInstanceUri(), s.Database)
153+
}

google/import.go

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package google
22

33
import (
44
"fmt"
5+
"log"
56
"regexp"
67
"strconv"
78
"strings"
@@ -23,10 +24,12 @@ func parseImportId(idRegexes []string, d TerraformResourceData, config *Config)
2324
}
2425

2526
if fieldValues := re.FindStringSubmatch(d.Id()); fieldValues != nil {
27+
log.Printf("[DEBUG] matching ID %s to regex %s.", d.Id(), idFormat)
2628
// Starting at index 1, the first match is the full string.
2729
for i := 1; i < len(fieldValues); i++ {
2830
fieldName := re.SubexpNames()[i]
2931
fieldValue := fieldValues[i]
32+
log.Printf("[DEBUG] importing %s = %s", fieldName, fieldValue)
3033
// Because we do not know at this point whether 'fieldName'
3134
// corresponds to a TypeString or a TypeInteger in the resource
3235
// schema, we need to determine the type in an unintutitive way.

google/provider_spanner_gen.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Magic Modules and manual
8+
// changes will be clobbered when the file is regenerated.
9+
//
10+
// Please read more about how to change this file in
11+
// .github/CONTRIBUTING.md.
12+
//
13+
// ----------------------------------------------------------------------------
14+
15+
package google
16+
17+
import "github.com/hashicorp/terraform/helper/schema"
18+
19+
var GeneratedSpannerResourcesMap = map[string]*schema.Resource{
20+
"google_spanner_database": resourceSpannerDatabase(),
21+
}

0 commit comments

Comments
 (0)