From f88b8de6c938da93a14567d4587c1e71501ae561 Mon Sep 17 00:00:00 2001 From: The Magician Date: Wed, 8 Mar 2023 14:09:46 -0800 Subject: [PATCH] Add support for accelerators to google_datafusion_instance (#6851) (#1440) Added support to the field for Data Fusion, updated corresponding generated and handwritten tests, and added a custom diffsuppressfunc. Currently suggests a manual fix to a potential diff issue, will be able to update down line based on feedback from API team. Signed-off-by: Modular Magician --- .../google/resources/datafusion_instance.go | 72 ++++++++++++++++++- go.mod | 2 +- go.sum | 4 +- 3 files changed, 74 insertions(+), 4 deletions(-) diff --git a/converters/google/resources/datafusion_instance.go b/converters/google/resources/datafusion_instance.go index 4254d368c..54189e52b 100644 --- a/converters/google/resources/datafusion_instance.go +++ b/converters/google/resources/datafusion_instance.go @@ -14,7 +14,34 @@ package google -import "reflect" +import ( + "reflect" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +var instanceAcceleratorOptions = []string{ + "delta.default.checkpoint.directory", + "ui.feature.cdc", +} + +func instanceOptionsDiffSuppress(k, old, new string, d *schema.ResourceData) bool { + // Suppress diffs for the options generated by adding an accelerator to a data fusion instance + for _, option := range instanceAcceleratorOptions { + if strings.Contains(k, option) && new == "" { + return true + } + } + + // Let diff be determined by options (above) + if strings.Contains(k, "options.%") { + return true + } + + // For other keys, don't suppress diff. + return false +} const DataFusionInstanceAssetType string = "datafusion.googleapis.com/Instance" @@ -144,6 +171,12 @@ func GetDataFusionInstanceApiObject(d TerraformResourceData, config *Config) (ma } else if v, ok := d.GetOkExists("event_publish_config"); !isEmptyValue(reflect.ValueOf(eventPublishConfigProp)) && (ok || !reflect.DeepEqual(v, eventPublishConfigProp)) { obj["eventPublishConfig"] = eventPublishConfigProp } + acceleratorsProp, err := expandDataFusionInstanceAccelerators(d.Get("accelerators"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("accelerators"); !isEmptyValue(reflect.ValueOf(acceleratorsProp)) && (ok || !reflect.DeepEqual(v, acceleratorsProp)) { + obj["accelerators"] = acceleratorsProp + } return obj, nil } @@ -304,3 +337,40 @@ func expandDataFusionInstanceEventPublishConfigEnabled(v interface{}, d Terrafor func expandDataFusionInstanceEventPublishConfigTopic(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } + +func expandDataFusionInstanceAccelerators(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedAcceleratorType, err := expandDataFusionInstanceAcceleratorsAcceleratorType(original["accelerator_type"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedAcceleratorType); val.IsValid() && !isEmptyValue(val) { + transformed["acceleratorType"] = transformedAcceleratorType + } + + transformedState, err := expandDataFusionInstanceAcceleratorsState(original["state"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedState); val.IsValid() && !isEmptyValue(val) { + transformed["state"] = transformedState + } + + req = append(req, transformed) + } + return req, nil +} + +func expandDataFusionInstanceAcceleratorsAcceleratorType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDataFusionInstanceAcceleratorsState(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} diff --git a/go.mod b/go.mod index c147b8e8f..3d8c1ac66 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.2 github.com/hashicorp/terraform-json v0.14.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0 - github.com/hashicorp/terraform-provider-google v1.20.1-0.20230308201858-dd44b9f5e6a5 + github.com/hashicorp/terraform-provider-google v1.20.1-0.20230308220420-98228a7baef2 github.com/mitchellh/go-homedir v1.1.0 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.9.0 diff --git a/go.sum b/go.sum index dbd28ae20..bd1c8b727 100644 --- a/go.sum +++ b/go.sum @@ -514,8 +514,8 @@ github.com/hashicorp/terraform-plugin-log v0.7.0 h1:SDxJUyT8TwN4l5b5/VkiTIaQgY6R github.com/hashicorp/terraform-plugin-log v0.7.0/go.mod h1:p4R1jWBXRTvL4odmEkFfDdhUjHf9zcs/BCoNHAc7IK4= github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0 h1:FtCLTiTcykdsURXPt/ku7fYXm3y19nbzbZcUxHx9RbI= github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0/go.mod h1:80wf5oad1tW+oLnbXS4UTYmDCrl7BuN1Q+IA91X1a4Y= -github.com/hashicorp/terraform-provider-google v1.20.1-0.20230308201858-dd44b9f5e6a5 h1:cYnufBSjAB7ljFTqVa9/7QdgfVorj18A/RSGmI6TYFs= -github.com/hashicorp/terraform-provider-google v1.20.1-0.20230308201858-dd44b9f5e6a5/go.mod h1:Me09EooskxD1HNA2k+14YdLghnF8lt2HOda03gBkNpc= +github.com/hashicorp/terraform-provider-google v1.20.1-0.20230308220420-98228a7baef2 h1:JwePt8xiyWy55MRLLf/kiWvDjXvs+HtbyKkvyQAkyGY= +github.com/hashicorp/terraform-provider-google v1.20.1-0.20230308220420-98228a7baef2/go.mod h1:Me09EooskxD1HNA2k+14YdLghnF8lt2HOda03gBkNpc= github.com/hashicorp/terraform-registry-address v0.1.0 h1:W6JkV9wbum+m516rCl5/NjKxCyTVaaUBbzYcMzBDO3U= github.com/hashicorp/terraform-registry-address v0.1.0/go.mod h1:EnyO2jYO6j29DTHbJcm00E5nQTFeTtyZH3H5ycydQ5A= github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=