-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial autogeneration of Spanner instance in Terraform. #1266
Changes from all commits
31cc3f3
21ed3d2
f458185
0675628
b478a2f
c6fca69
def6f08
76372ac
25e59c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
+63 −47 | lib/ansible/modules/cloud/google/gcp_spanner_instance.py | |
+7 −20 | lib/ansible/modules/cloud/google/gcp_spanner_instance_facts.py |
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 | ||
} |
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 | ||
} |
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 |
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 |
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need new code for this updatemask instead of the existing MM support / existing custom code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question - the resource update function takes |
||
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 |
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" | ||
} | ||
} |
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be marked
input
, andrequired
? From the website docs:For Terraform, we can preserve the optional name w/ overrides of course!