Skip to content

Commit

Permalink
Add deadLetterPolicy to Pub/Sub Subscription resource (#3305) (#408)
Browse files Browse the repository at this point in the history
* Add deadLetterPolicy to Pub/Sub subscription resource

* fix: disable allow_empty_objects, fix docstring, add example

* fix: set max_delivery_attempts

* fix: block and topic name

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Mar 30, 2020
1 parent ff59998 commit 9ed9de7
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions google/pubsub_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ func GetPubsubSubscriptionApiObject(d TerraformResourceData, config *Config) (ma
} else if v, ok := d.GetOkExists("expiration_policy"); ok || !reflect.DeepEqual(v, expirationPolicyProp) {
obj["expirationPolicy"] = expirationPolicyProp
}
deadLetterPolicyProp, err := expandPubsubSubscriptionDeadLetterPolicy(d.Get("dead_letter_policy"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("dead_letter_policy"); ok || !reflect.DeepEqual(v, deadLetterPolicyProp) {
obj["deadLetterPolicy"] = deadLetterPolicyProp
}

return resourcePubsubSubscriptionEncoder(d, config, obj)
}
Expand Down Expand Up @@ -271,3 +277,37 @@ func expandPubsubSubscriptionExpirationPolicy(v interface{}, d TerraformResource
func expandPubsubSubscriptionExpirationPolicyTtl(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandPubsubSubscriptionDeadLetterPolicy(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{})

transformedDeadLetterTopic, err := expandPubsubSubscriptionDeadLetterPolicyDeadLetterTopic(original["dead_letter_topic"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedDeadLetterTopic); val.IsValid() && !isEmptyValue(val) {
transformed["deadLetterTopic"] = transformedDeadLetterTopic
}

transformedMaxDeliveryAttempts, err := expandPubsubSubscriptionDeadLetterPolicyMaxDeliveryAttempts(original["max_delivery_attempts"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedMaxDeliveryAttempts); val.IsValid() && !isEmptyValue(val) {
transformed["maxDeliveryAttempts"] = transformedMaxDeliveryAttempts
}

return transformed, nil
}

func expandPubsubSubscriptionDeadLetterPolicyDeadLetterTopic(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandPubsubSubscriptionDeadLetterPolicyMaxDeliveryAttempts(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

0 comments on commit 9ed9de7

Please sign in to comment.