Skip to content

Commit

Permalink
Merge pull request #53 from Szasza/feature/adding-click-tracking-to-d…
Browse files Browse the repository at this point in the history
…omain

adding click_tracking support, updating documentation on open_tracking availability
  • Loading branch information
wgebis authored Apr 30, 2024
2 parents 4726345 + 08a5fe8 commit 74e9e08
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/data-sources/domain.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ The following attributes are exported:
* `smtp_password` - The password to the SMTP server.
* `wildcard` - Whether or not the domain will accept email for sub-domains.
* `spam_action` - The spam filtering setting.
* `open_tracking` - The open tracking setting.
* `click_tracking` - The click tracking setting.
* `web_scheme` - The tracking web scheme.
* `receiving_records` - A list of DNS records for receiving validation.
* `priority` - The priority of the record.
Expand Down
3 changes: 3 additions & 0 deletions docs/resources/domain.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ The following arguments are supported:
* `dkim_selector` - (Optional) The name of your DKIM selector if you want to specify it whereas MailGun will make it's own choice.
* `force_dkim_authority` - (Optional) If set to true, the domain will be the DKIM authority for itself even if the root domain is registered on the same mailgun account. If set to false, the domain will have the same DKIM authority as the root domain registered on the same mailgun account. The default is `false`.
* `open_tracking` - (Optional) (Enum: `yes` or `no`) The open tracking settings for the domain. Default: `no`
* `click_tracking` - (Optional) (Enum: `yes` or `no`) The click tracking settings for the domain. Default: `no`
* `web_scheme` - (Optional) (`http` or `https`) The tracking web scheme. Default: `http`

## Attributes Reference
Expand All @@ -50,6 +51,8 @@ The following attributes are exported:
* `smtp_password` - The password to the SMTP server.
* `wildcard` - Whether or not the domain will accept email for sub-domains.
* `spam_action` - The spam filtering setting.
* `open_tracking` - The open tracking setting.
* `click_tracking` - The click tracking setting.
* `web_scheme` - The tracking web scheme.
* `receiving_records` - A list of DNS records for receiving validation. **Deprecated** Use `receiving_records_set` instead.
* `priority` - The priority of the record.
Expand Down
35 changes: 35 additions & 0 deletions mailgun/resource_mailgun_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ func resourceMailgunDomain() *schema.Resource {
Default: false,
},

"click_tracking": {
Type: schema.TypeBool,
Optional: true,
ForceNew: false,
Default: false,
},

"web_scheme": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -274,6 +281,7 @@ func resourceMailgunDomainUpdate(ctx context.Context, d *schema.ResourceData, me
var newPassword string = d.Get("smtp_password").(string)
var smtpLogin string = d.Get("smtp_login").(string)
var openTracking = d.Get("open_tracking").(bool)
var clickTracking = d.Get("click_tracking").(bool)
var webScheme = d.Get("web_scheme").(string)

// Retrieve and update state of domain
Expand Down Expand Up @@ -304,10 +312,23 @@ func resourceMailgunDomainUpdate(ctx context.Context, d *schema.ResourceData, me
}
}

if currentData.Get("click_tracking") != clickTracking {
var clickTrackingValue = "no"
if clickTracking {
clickTrackingValue = "yes"
}
errc = client.UpdateClickTracking(ctx, d.Get("name").(string), clickTrackingValue)

if errc != nil {
return diag.FromErr(errc)
}
}

if currentData.Get("web_scheme") != webScheme {
opts := mailgun.UpdateDomainOptions{}
opts.WebScheme = webScheme
errc = client.UpdateDomain(ctx, name, &opts)

if errc != nil {
return diag.FromErr(errc)
}
Expand All @@ -334,6 +355,7 @@ func resourceMailgunDomainCreate(ctx context.Context, d *schema.ResourceData, me
opts.WebScheme = d.Get("web_scheme").(string)
var dkimSelector = d.Get("dkim_selector").(string)
var openTracking = d.Get("open_tracking").(bool)
var clickTracking = d.Get("click_tracking").(bool)

log.Printf("[DEBUG] Domain create configuration: %#v", opts)

Expand All @@ -357,6 +379,13 @@ func resourceMailgunDomainCreate(ctx context.Context, d *schema.ResourceData, me
return diag.FromErr(errc)
}
}
if clickTracking {
errc = client.UpdateClickTracking(ctx, d.Get("name").(string), "yes")

if errc != nil {
return diag.FromErr(errc)
}
}

d.SetId(name)

Expand Down Expand Up @@ -470,5 +499,11 @@ func resourceMailgunDomainRetrieve(id string, client *mailgun.MailgunImpl, d *sc
}
d.Set("open_tracking", openTracking)

var clickTracking = false
if info.Click.Active {
clickTracking = true
}
d.Set("click_tracking", clickTracking)

return &resp, nil
}
5 changes: 5 additions & 0 deletions mailgun/resource_mailgun_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func TestAccMailgunDomain_Basic(t *testing.T) {
"mailgun_domain.foobar", "force_dkim_authority", "true"),
resource.TestCheckResourceAttr(
"mailgun_domain.foobar", "open_tracking", "true"),
resource.TestCheckResourceAttr(
"mailgun_domain.foobar", "click_tracking", "true"),
resource.TestCheckResourceAttr(
"mailgun_domain.foobar", "receiving_records.0.priority", "10"),
resource.TestCheckResourceAttr(
"mailgun_domain.foobar", "web_scheme", "https"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -171,6 +175,7 @@ resource "mailgun_domain" "foobar" {
wildcard = true
force_dkim_authority = true
open_tracking = true
click_tracking = true
web_scheme = "https"
}`
}

0 comments on commit 74e9e08

Please sign in to comment.