Skip to content

Commit

Permalink
Allow fields to be removed at a specific version (#3417) (#424)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
modular-magician authored Apr 24, 2020
1 parent e296467 commit ec59f72
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
43 changes: 43 additions & 0 deletions google/healthcare_hl7_v2_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ec59f72

Please sign in to comment.