Skip to content
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

fixed virtual field update issues #7318

Merged
merged 2 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mmv1/products/spanner/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
post_create: templates/terraform/post_create/sleep.go.erb
pre_delete: 'templates/terraform/pre_delete/spanner_instance.go.erb'
constants: 'templates/terraform/constants/spanner_instance.go.erb'
pre_update: 'templates/terraform/pre_update/spanner_instance.go.erb'
# This is for copying files over
files: !ruby/object:Provider::Config::Files
# These files have templating (ERB) code that will be run.
Expand Down
16 changes: 16 additions & 0 deletions mmv1/templates/terraform/constants/spanner_database.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,20 @@ func validateDatabaseRetentionPeriod(v interface{}, k string) (ws []string, erro
}

return
}

func resourceSpannerDBVirtualUpdate(d *schema.ResourceData, resourceSchema map[string]*schema.Schema) bool {
// deletion_protection is the only virtual field
if d.HasChange("deletion_protection") {
edwardmedia marked this conversation as resolved.
Show resolved Hide resolved
for field := range resourceSchema {
if field == "deletion_protection" {
continue
}
if d.HasChange(field) {
return false
}
}
return true
}
return false
}
18 changes: 17 additions & 1 deletion mmv1/templates/terraform/constants/spanner_instance.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,20 @@ func deleteSpannerBackups(d *schema.ResourceData, config *Config, res map[string
}
}
return nil
}
}

func resourceSpannerInstanceVirtualUpdate(d *schema.ResourceData, resourceSchema map[string]*schema.Schema) bool {
// force_destroy is the only virtual field
if d.HasChange("force_destroy") {
for field := range resourceSchema {
if field == "force_destroy" {
continue
}
if d.HasChange(field) {
return false
}
}
return true
}
return false
}
9 changes: 9 additions & 0 deletions mmv1/templates/terraform/pre_update/spanner_database.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ if len(obj["statements"].([]string)) == 0 {
// Return early to avoid making an API call that errors,
// due to containing no DDL SQL statements
return resourceSpannerDatabaseRead(d, meta)
}

if resourceSpannerDBVirtualUpdate(d, resourceSpannerInstance().Schema) {
if d.Get("deletion_protection") != nil {
if err := d.Set("deletion_protection", d.Get("deletion_protection")); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
}
return nil
}
8 changes: 8 additions & 0 deletions mmv1/templates/terraform/pre_update/spanner_instance.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if resourceSpannerInstanceVirtualUpdate(d, resourceSpannerInstance().Schema) {
if d.Get("force_destroy") != nil {
if err := d.Set("force_destroy", d.Get("force_destroy")); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
}
return nil
}