From e411e57259764e382e55f947bcdee15c40342613 Mon Sep 17 00:00:00 2001 From: The Magician Date: Fri, 18 Jun 2021 16:21:41 -0700 Subject: [PATCH] Add TTL fields to Secret Manager (#4821) (#726) Co-authored-by: upodroid Signed-off-by: Modular Magician Co-authored-by: upodroid --- google/secretmanager_secret.go | 92 ++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/google/secretmanager_secret.go b/google/secretmanager_secret.go index e0f0f1f18..0d2aa376b 100644 --- a/google/secretmanager_secret.go +++ b/google/secretmanager_secret.go @@ -51,6 +51,30 @@ func GetSecretManagerSecretApiObject(d TerraformResourceData, config *Config) (m } else if v, ok := d.GetOkExists("replication"); !isEmptyValue(reflect.ValueOf(replicationProp)) && (ok || !reflect.DeepEqual(v, replicationProp)) { obj["replication"] = replicationProp } + topicsProp, err := expandSecretManagerSecretTopics(d.Get("topics"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("topics"); !isEmptyValue(reflect.ValueOf(topicsProp)) && (ok || !reflect.DeepEqual(v, topicsProp)) { + obj["topics"] = topicsProp + } + expireTimeProp, err := expandSecretManagerSecretExpireTime(d.Get("expire_time"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("expire_time"); !isEmptyValue(reflect.ValueOf(expireTimeProp)) && (ok || !reflect.DeepEqual(v, expireTimeProp)) { + obj["expireTime"] = expireTimeProp + } + ttlProp, err := expandSecretManagerSecretTtl(d.Get("ttl"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("ttl"); !isEmptyValue(reflect.ValueOf(ttlProp)) && (ok || !reflect.DeepEqual(v, ttlProp)) { + obj["ttl"] = ttlProp + } + rotationProp, err := expandSecretManagerSecretRotation(d.Get("rotation"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("rotation"); !isEmptyValue(reflect.ValueOf(rotationProp)) && (ok || !reflect.DeepEqual(v, rotationProp)) { + obj["rotation"] = rotationProp + } return obj, nil } @@ -174,3 +198,71 @@ func expandSecretManagerSecretReplicationUserManagedReplicasCustomerManagedEncry func expandSecretManagerSecretReplicationUserManagedReplicasCustomerManagedEncryptionKmsKeyName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } + +func expandSecretManagerSecretTopics(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{}) + + transformedName, err := expandSecretManagerSecretTopicsName(original["name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedName); val.IsValid() && !isEmptyValue(val) { + transformed["name"] = transformedName + } + + req = append(req, transformed) + } + return req, nil +} + +func expandSecretManagerSecretTopicsName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandSecretManagerSecretExpireTime(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandSecretManagerSecretTtl(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandSecretManagerSecretRotation(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{}) + + transformedNextRotationTime, err := expandSecretManagerSecretRotationNextRotationTime(original["next_rotation_time"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedNextRotationTime); val.IsValid() && !isEmptyValue(val) { + transformed["nextRotationTime"] = transformedNextRotationTime + } + + transformedRotationPeriod, err := expandSecretManagerSecretRotationRotationPeriod(original["rotation_period"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedRotationPeriod); val.IsValid() && !isEmptyValue(val) { + transformed["rotationPeriod"] = transformedRotationPeriod + } + + return transformed, nil +} + +func expandSecretManagerSecretRotationNextRotationTime(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandSecretManagerSecretRotationRotationPeriod(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +}