Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
Add support for accelerators to google_datafusion_instance (#6851) (#…
Browse files Browse the repository at this point in the history
…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 <magic-modules@google.com>
  • Loading branch information
modular-magician authored Mar 8, 2023
1 parent 86d9519 commit f88b8de
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
72 changes: 71 additions & 1 deletion converters/google/resources/datafusion_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit f88b8de

Please sign in to comment.