From ec59f729ec0671e3fdd9fcbc68cf4a6d8486ca23 Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 23 Apr 2020 20:46:19 -0400 Subject: [PATCH] Allow fields to be removed at a specific version (#3417) (#424) The healthcare API has deprecated a field at beta and removed it from the GA launch of the api. In order to support this without having to duplicate the entire resource this change supports defining a single field multiple times with a different configruation for each version. Specifically it allows a field to exist as deprecated at one version but not at another. This also introduces the removed_message field. Signed-off-by: Modular Magician --- google/config.go | 2 +- google/healthcare_hl7_v2_store.go | 43 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/google/config.go b/google/config.go index 40a5d72ea..8ce990086 100644 --- a/google/config.go +++ b/google/config.go @@ -38,7 +38,7 @@ import ( "google.golang.org/api/dns/v1" dnsBeta "google.golang.org/api/dns/v1beta2" file "google.golang.org/api/file/v1beta1" - healthcare "google.golang.org/api/healthcare/v1beta1" + healthcare "google.golang.org/api/healthcare/v1" "google.golang.org/api/iam/v1" iamcredentials "google.golang.org/api/iamcredentials/v1" cloudlogging "google.golang.org/api/logging/v2" diff --git a/google/healthcare_hl7_v2_store.go b/google/healthcare_hl7_v2_store.go index aadf5bb51..dc2ffb723 100644 --- a/google/healthcare_hl7_v2_store.go +++ b/google/healthcare_hl7_v2_store.go @@ -60,6 +60,12 @@ func GetHealthcareHl7V2StoreApiObject(d TerraformResourceData, config *Config) ( } else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) { obj["labels"] = labelsProp } + notificationConfigsProp, err := expandHealthcareHl7V2StoreNotificationConfigs(d.Get("notification_configs"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("notification_configs"); !isEmptyValue(reflect.ValueOf(notificationConfigsProp)) && (ok || !reflect.DeepEqual(v, notificationConfigsProp)) { + obj["notificationConfigs"] = notificationConfigsProp + } notificationConfigProp, err := expandHealthcareHl7V2StoreNotificationConfig(d.Get("notification_config"), d, config) if err != nil { return nil, err @@ -138,6 +144,43 @@ func expandHealthcareHl7V2StoreLabels(v interface{}, d TerraformResourceData, co return m, nil } +func expandHealthcareHl7V2StoreNotificationConfigs(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{}) + + transformedPubsubTopic, err := expandHealthcareHl7V2StoreNotificationConfigsPubsubTopic(original["pubsub_topic"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPubsubTopic); val.IsValid() && !isEmptyValue(val) { + transformed["pubsubTopic"] = transformedPubsubTopic + } + + transformedFilter, err := expandHealthcareHl7V2StoreNotificationConfigsFilter(original["filter"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedFilter); val.IsValid() && !isEmptyValue(val) { + transformed["filter"] = transformedFilter + } + + req = append(req, transformed) + } + return req, nil +} + +func expandHealthcareHl7V2StoreNotificationConfigsPubsubTopic(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandHealthcareHl7V2StoreNotificationConfigsFilter(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + func expandHealthcareHl7V2StoreNotificationConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { l := v.([]interface{}) if len(l) == 0 || l[0] == nil {