Skip to content
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.1.0 (Unreleased)

FEATURES:

* **New Resource:** `sendgrid_bounce_settings` - Manage bounce settings for your SendGrid account, including soft bounce purge configuration
* **New Data Source:** `sendgrid_bounce_settings` - Retrieve current bounce settings from your SendGrid account

IMPROVEMENTS:

* **Bounce Settings API Migration:** Moved bounce settings API implementation from terraform provider to sendgrid library for better maintainability and consistency
39 changes: 39 additions & 0 deletions docs/data-sources/bounce_settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "sendgrid_bounce_settings Data Source - terraform-provider-sendgrid"
subcategory: ""
description: |-
Retrieve bounce settings for your SendGrid account.
Bounce settings allow you to configure how long soft bounces are retained in your suppression list. Soft bounces are temporary delivery failures, such as a full mailbox or temporary server issues.
The Soft Bounces setting specifies the number of days soft bounces will be kept in your soft bounces suppression list. Any soft bounces older than this value will be purged.
For more information, see the SendGrid Mail Settings Guide https://support.sendgrid.com/hc/en-us/articles/9489871931803-Mail-Settings-Guide-within-a-SendGrid-Account.
---

# sendgrid_bounce_settings (Data Source)

Retrieve bounce settings for your SendGrid account.

Bounce settings allow you to configure how long soft bounces are retained in your suppression list.
Soft bounces are temporary delivery failures, such as a full mailbox or temporary server issues.

The Soft Bounces setting specifies the number of days soft bounces will be kept in your soft bounces suppression list.
Any soft bounces older than this value will be purged.

For more information, see the [SendGrid Mail Settings Guide](https://support.sendgrid.com/hc/en-us/articles/9489871931803-Mail-Settings-Guide-within-a-SendGrid-Account).

## Example Usage

```terraform
data "sendgrid_bounce_settings" "example" {}

output "soft_bounce_purge_days" {
value = data.sendgrid_bounce_settings.example.soft_bounce_purge_days
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Read-Only

- `soft_bounce_purge_days` (Number) The number of days soft bounces will be kept in your soft bounces suppression list. Any soft bounces older than this value will be purged.
47 changes: 47 additions & 0 deletions docs/resources/bounce_settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "sendgrid_bounce_settings Resource - terraform-provider-sendgrid"
subcategory: ""
description: |-
Manage bounce settings for your SendGrid account.
Bounce settings allow you to configure how long soft bounces are retained in your suppression list. Soft bounces are temporary delivery failures, such as a full mailbox or temporary server issues.
The Soft Bounces setting specifies the number of days soft bounces will be kept in your soft bounces suppression list. Any soft bounces older than this value will be purged.
For more information, see the SendGrid Mail Settings Guide https://support.sendgrid.com/hc/en-us/articles/9489871931803-Mail-Settings-Guide-within-a-SendGrid-Account.
---

# sendgrid_bounce_settings (Resource)

Manage bounce settings for your SendGrid account.

Bounce settings allow you to configure how long soft bounces are retained in your suppression list.
Soft bounces are temporary delivery failures, such as a full mailbox or temporary server issues.

The Soft Bounces setting specifies the number of days soft bounces will be kept in your soft bounces suppression list.
Any soft bounces older than this value will be purged.

For more information, see the [SendGrid Mail Settings Guide](https://support.sendgrid.com/hc/en-us/articles/9489871931803-Mail-Settings-Guide-within-a-SendGrid-Account).

## Example Usage

```terraform
resource "sendgrid_bounce_settings" "example" {
soft_bounce_purge_days = 30
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `soft_bounce_purge_days` (Number) The number of days soft bounces will be kept in your soft bounces suppression list. Any soft bounces older than this value will be purged. Must be between 1 and 3650 days.

## Import

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
% terraform import sendgrid_bounce_settings.example ""
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data "sendgrid_bounce_settings" "example" {}

output "soft_bounce_purge_days" {
value = data.sendgrid_bounce_settings.example.soft_bounce_purge_days
}
3 changes: 3 additions & 0 deletions examples/resources/sendgrid_bounce_settings/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "sendgrid_bounce_settings" "example" {
soft_bounce_purge_days = 30
}
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jhump/protoreflect v1.17.0 h1:qOEr613fac2lOuTgWN4tPAtLL7fUSbuJL5X5XumQh94=
github.com/jhump/protoreflect v1.17.0/go.mod h1:h9+vUUL38jiBzck8ck+6G/aeMX8Z4QUY/NiJPwPNi+8=
github.com/kenzo0107/sendgrid v1.7.0 h1:ZaPwWcjR3EE974qsrkCgFFYmQq2hE9Y4jRfp4qR7JVc=
github.com/kenzo0107/sendgrid v1.7.0/go.mod h1:o93EmGpbWbhaxLoiGB+x6g3tLof7TwbUlzjHNLvpDP8=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down Expand Up @@ -199,8 +197,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
Expand Down
112 changes: 112 additions & 0 deletions internal/provider/bounce_settings_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package provider

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/kenzo0107/sendgrid"
)

// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &bounceSettingsDataSource{}
_ datasource.DataSourceWithConfigure = &bounceSettingsDataSource{}
)

func newBounceSettingsDataSource() datasource.DataSource {
return &bounceSettingsDataSource{}
}

type bounceSettingsDataSource struct {
client *sendgrid.Client
}

type bounceSettingsDataSourceModel struct {
SoftBouncePurgeDays types.Int64 `tfsdk:"soft_bounce_purge_days"`
}

func (d *bounceSettingsDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_bounce_settings"
}

func (d *bounceSettingsDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
return
}

client, ok := req.ProviderData.(*sendgrid.Client)
if !ok {
resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type",
fmt.Sprintf("Expected *sendgrid.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
)
return
}

d.client = client
}

func (d *bounceSettingsDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: `
Retrieve bounce settings for your SendGrid account.

Bounce settings allow you to configure how long soft bounces are retained in your suppression list.
Soft bounces are temporary delivery failures, such as a full mailbox or temporary server issues.

The Soft Bounces setting specifies the number of days soft bounces will be kept in your soft bounces suppression list.
Any soft bounces older than this value will be purged.

For more information, see the [SendGrid Mail Settings Guide](https://support.sendgrid.com/hc/en-us/articles/9489871931803-Mail-Settings-Guide-within-a-SendGrid-Account).
`,
Attributes: map[string]schema.Attribute{
"soft_bounce_purge_days": schema.Int64Attribute{
MarkdownDescription: "The number of days soft bounces will be kept in your soft bounces suppression list. Any soft bounces older than this value will be purged.",
Computed: true,
},
},
}
}

func (d *bounceSettingsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var state bounceSettingsDataSourceModel

resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
return
}

res, err := retryOnRateLimit(ctx, func() (interface{}, error) {
return d.client.GetBounceSettings(ctx)
})
if err != nil {
resp.Diagnostics.AddError(
"Reading bounce settings",
fmt.Sprintf("Unable to get bounce settings, got error: %s", err),
)
return
}

o, ok := res.(*sendgrid.BounceSettings)
if !ok {
resp.Diagnostics.AddError(
"Reading bounce settings",
"Failed to assert type *sendgrid.BounceSettings",
)
return
}

state.SoftBouncePurgeDays = types.Int64Value(o.SoftBouncePurgeDays)

resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
return
}
}
30 changes: 30 additions & 0 deletions internal/provider/bounce_settings_data_source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package provider

import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccBounceSettingsDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Read testing
{
Config: testAccBounceSettingsDataSourceConfig,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("data.sendgrid_bounce_settings.test", "soft_bounce_purge_days"),
),
},
},
})
}

const testAccBounceSettingsDataSourceConfig = `
data "sendgrid_bounce_settings" "test" {}
`
Loading
Loading