Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS SES Configuration Set Tracking Options #20045

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions aws/resource_aws_ses_configuration_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"fmt"
"log"
"regexp"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -62,6 +63,20 @@ func resourceAwsSesConfigurationSet() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 64),
},
"tracking_options": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"custom_redirect_domain": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringDoesNotMatch(regexp.MustCompile(`\.$`), "cannot end with a period"),
},
},
},
},
},
}
}
Expand Down Expand Up @@ -120,6 +135,18 @@ func resourceAwsSesConfigurationSetCreate(d *schema.ResourceData, meta interface
}
}

if v, ok := d.GetOk("tracking_options"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input := &ses.CreateConfigurationSetTrackingOptionsInput{
ConfigurationSetName: aws.String(configurationSetName),
TrackingOptions: expandSesConfigurationSetTrackingOptions(v.([]interface{})),
}

_, err := conn.CreateConfigurationSetTrackingOptions(input)
if err != nil {
return fmt.Errorf("error adding SES configuration set (%s) tracking options: %w", configurationSetName, err)
}
}

return resourceAwsSesConfigurationSetRead(d, meta)
}

Expand Down Expand Up @@ -208,6 +235,18 @@ func resourceAwsSesConfigurationSetUpdate(d *schema.ResourceData, meta interface
}
}

if d.HasChange("tracking_options") {
input := &ses.UpdateConfigurationSetTrackingOptionsInput{
ConfigurationSetName: aws.String(d.Id()),
TrackingOptions: expandSesConfigurationSetTrackingOptions(d.Get("tracking_options").([]interface{})),
}

_, err := conn.UpdateConfigurationSetTrackingOptions(input)
if err != nil {
return fmt.Errorf("error updating SES configuration set (%s) tracking options: %w", d.Id(), err)
}
}

return resourceAwsSesConfigurationSetRead(d, meta)
}

Expand Down Expand Up @@ -258,3 +297,22 @@ func flattenSesConfigurationSetDeliveryOptions(options *ses.DeliveryOptions) []i

return []interface{}{m}
}

func expandSesConfigurationSetTrackingOptions(l []interface{}) *ses.TrackingOptions {
if len(l) == 0 || l[0] == nil {
return nil
}

tfMap, ok := l[0].(map[string]interface{})
if !ok {
return nil
}

options := &ses.TrackingOptions{}

if v, ok := tfMap["custom_redirect_domain"].(string); ok && v != "" {
options.CustomRedirectDomain = aws.String(v)
}

return options
}
5 changes: 5 additions & 0 deletions website/docs/r/ses_configuration_set.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ The following argument is optional:
* `delivery_options` - (Optional) Configuration block. Detailed below.
* `reputation_metrics_enabled` - (Optional) Whether or not Amazon SES publishes reputation metrics for the configuration set, such as bounce and complaint rates, to Amazon CloudWatch. The default value is `false`.
* `sending_enabled` - (Optional) Whether email sending is enabled or disabled for the configuration set. The default value is `true`.
* `tracking_options` - (Optional) Configuration block. Detailed below.

### delivery_options

* `tls_policy` - (Optional) Specifies whether messages that use the configuration set are required to use Transport Layer Security (TLS). If the value is `Require`, messages are only delivered if a TLS connection can be established. If the value is `Optional`, messages can be delivered in plain text if a TLS connection can't be established. Valid values: `Require` or `Optional`. Defaults to `Optional`.

### tracking_options

* `custom_redirect_domain` - (Optional) Specifies the custom subdomain that is used to redirect email recipients to the Amazon SES event tracking domain.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:
Expand Down