Skip to content

Commit

Permalink
Add TTL fields to Secret Manager (#4821) (#726)
Browse files Browse the repository at this point in the history
Co-authored-by: upodroid <[email protected]>
Signed-off-by: Modular Magician <[email protected]>

Co-authored-by: upodroid <[email protected]>
  • Loading branch information
modular-magician and upodroid authored Jun 18, 2021
1 parent ecaeaac commit e411e57
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions google/secretmanager_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

0 comments on commit e411e57

Please sign in to comment.