From b17c62bdd160525abf92bf618e0cad8fe637bbb6 Mon Sep 17 00:00:00 2001 From: Roberto Jung Drebes Date: Tue, 30 Jul 2019 14:22:06 +0000 Subject: [PATCH] Pub/Sub Geo Restriction Signed-off-by: Modular Magician --- google/pubsub_topic.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/google/pubsub_topic.go b/google/pubsub_topic.go index 665df294e..62398ce30 100644 --- a/google/pubsub_topic.go +++ b/google/pubsub_topic.go @@ -57,6 +57,12 @@ func GetPubsubTopicApiObject(d TerraformResourceData, config *Config) (map[strin } else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) { obj["labels"] = labelsProp } + messageStoragePolicyProp, err := expandPubsubTopicMessageStoragePolicy(d.Get("message_storage_policy"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("message_storage_policy"); !isEmptyValue(reflect.ValueOf(messageStoragePolicyProp)) && (ok || !reflect.DeepEqual(v, messageStoragePolicyProp)) { + obj["messageStoragePolicy"] = messageStoragePolicyProp + } return resourcePubsubTopicEncoder(d, config, obj) } @@ -84,3 +90,26 @@ func expandPubsubTopicLabels(v interface{}, d TerraformResourceData, config *Con } return m, nil } + +func expandPubsubTopicMessageStoragePolicy(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedAllowedPersistenceRegions, err := expandPubsubTopicMessageStoragePolicyAllowedPersistenceRegions(original["allowed_persistence_regions"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedAllowedPersistenceRegions); val.IsValid() && !isEmptyValue(val) { + transformed["allowedPersistenceRegions"] = transformedAllowedPersistenceRegions + } + + return transformed, nil +} + +func expandPubsubTopicMessageStoragePolicyAllowedPersistenceRegions(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +}