-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
213 additions
and
568 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
templates/terraform/custom_expand/spanner_instance_config.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<%- # the license inside this block applies to this file | ||
# Copyright 2018 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
-%> | ||
func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { | ||
r := regexp.MustCompile("projects/(.+)/notes/(.+)") | ||
if r.MatchString(v.(string)) { | ||
return v.(string), nil | ||
} | ||
|
||
project, err := getProject(d, config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return fmt.Sprintf("projects/%s/notes/%s", project, v.(string)), nil | ||
} |
27 changes: 27 additions & 0 deletions
27
templates/terraform/custom_expand/spanner_instance_config.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<%- # the license inside this block applies to this file | ||
# Copyright 2018 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
-%> | ||
func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { | ||
r := regexp.MustCompile("projects/(.+)/instanceConfigs/(.+)") | ||
if r.MatchString(v.(string)) { | ||
return v.(string), nil | ||
} | ||
|
||
project, err := getProject(d, config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return fmt.Sprintf("projects/%s/instanceConfigs/%s", project, v.(string)), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
config := meta.(*Config) | ||
d.SetId(res["name"].(string)) | ||
if err := parseImportId([]string{"projects/(?P<project>[^/]+)/instances/(?P<name>[^/]+)"}, d, config); err != nil { | ||
return nil, err | ||
} | ||
res["project"] = d.Get("project").(string) | ||
res["name"] = d.Get("name").(string) | ||
id, err := replaceVars(d, config, "{{project}}/{{name}}") | ||
if err != nil { | ||
return nil, err | ||
} | ||
d.SetId(id) | ||
return res, nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
newObj := make(map[string]interface{}) | ||
newObj["instance"] = obj | ||
if obj["name"] == nil { | ||
d.Set("name", resource.PrefixedUniqueId("tfgen-spanid-")[:30]) | ||
newObj["instanceId"] = d.Get("name").(string) | ||
} else { | ||
newObj["instanceId"] = obj["name"] | ||
} | ||
delete(obj, "name") | ||
return newObj, nil |
19 changes: 19 additions & 0 deletions
19
templates/terraform/encoders/spanner_instance_update.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
project, err := getProject(d, meta.(*Config)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
obj["name"] = fmt.Sprintf("projects/%s/instances/%s", project, obj["name"]) | ||
newObj := make(map[string]interface{}) | ||
newObj["instance"] = obj | ||
updateMask := make([]string, 0) | ||
if d.HasChange("num_nodes") { | ||
updateMask = append(updateMask, "nodeCount") | ||
} | ||
if d.HasChange("display_name") { | ||
updateMask = append(updateMask, "displayName") | ||
} | ||
if d.HasChange("labels") { | ||
updateMask = append(updateMask, "labels") | ||
} | ||
newObj["fieldMask"] = strings.Join(updateMask, ",") | ||
return newObj, nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
resource "google_spanner_instance" "example" { | ||
config = "regional-us-central1" | ||
display_name = "Test Spanner Instance" | ||
num_nodes = 2 | ||
labels { | ||
"foo" = "bar" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This is useful if the resource in question doesn't have a perfectly consistent API | ||
// That is, the Operation for Create might return before the Get operation shows the | ||
// completed state of the resource. | ||
time.Sleep(5 * time.Second) |
Oops, something went wrong.