-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support suppressions unsubscribe group
Provide a resource to manage suppresions unsubscribe group.
- Loading branch information
Showing
12 changed files
with
562 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "sendgrid_unsubscribe_group Data Source - terraform-provider-sendgrid" | ||
subcategory: "" | ||
description: |- | ||
Provides a subuser resource. | ||
Suppression groups, or unsubscribe groups, are specific types or categories of emails from which you would like your recipients to be able to unsubscribe. For example: Daily Newsletters, Invoices, and System Alerts are all potential suppression groups. | ||
Visit the main documentation to [learn more about suppression/unsubscribe groups](https://sendgrid.com/docs/ui/sending-email/unsubscribe-groups/). | ||
--- | ||
|
||
# sendgrid_unsubscribe_group (Data Source) | ||
|
||
Provides a subuser resource. | ||
|
||
Suppression groups, or unsubscribe groups, are specific types or categories of emails from which you would like your recipients to be able to unsubscribe. For example: Daily Newsletters, Invoices, and System Alerts are all potential suppression groups. | ||
|
||
Visit the main documentation to [learn more about suppression/unsubscribe groups](https://sendgrid.com/docs/ui/sending-email/unsubscribe-groups/). | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `id` (String) The ID of the verified sender. | ||
|
||
### Read-Only | ||
|
||
- `description` (String) This will display to the user as the email address that sent this email. We will send the verification email to the address you enter in this field. If you have not received your verification email after some time, please refer back to the Sender settings and confirm that the "From" email is a valid address. | ||
- `is_default` (Boolean) This is a user-friendly name that is displayed to your recipient when they receive their email. | ||
- `name` (String) A label for your sender identity to help you identify it more quickly. This label is not visible to your recipients. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "sendgrid_unsubscribe_group Resource - terraform-provider-sendgrid" | ||
subcategory: "" | ||
description: |- | ||
Provides a subuser resource. | ||
Suppression groups, or unsubscribe groups, are specific types or categories of emails from which you would like your recipients to be able to unsubscribe. For example: Daily Newsletters, Invoices, and System Alerts are all potential suppression groups. | ||
Visit the main documentation to learn more about suppression/unsubscribe groups https://sendgrid.com/docs/ui/sending-email/unsubscribe-groups/. | ||
--- | ||
|
||
# sendgrid_unsubscribe_group (Resource) | ||
|
||
Provides a subuser resource. | ||
|
||
Suppression groups, or unsubscribe groups, are specific types or categories of emails from which you would like your recipients to be able to unsubscribe. For example: Daily Newsletters, Invoices, and System Alerts are all potential suppression groups. | ||
|
||
Visit the main documentation to [learn more about suppression/unsubscribe groups](https://sendgrid.com/docs/ui/sending-email/unsubscribe-groups/). | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "sendgrid_unsubscribe_group" "example" { | ||
name = "dummy" | ||
description = "dummy" | ||
is_default = false | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) The name of your suppression group. | ||
|
||
### Optional | ||
|
||
- `description` (String) A brief description of your suppression group. | ||
- `is_default` (Boolean) Indicates if you would like this to be your default suppression group. | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The user ID of the unsubscribe group. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
terraform { | ||
required_providers { | ||
hashicups = { | ||
source = "kenzo0107/sendgrid" | ||
sendgrid = { | ||
source = "registry.terraform.io/kenzo0107/sendgrid" | ||
} | ||
} | ||
} | ||
|
||
provider "sendgrid" { | ||
api_key = "<your api key>" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
resource "sendgrid_unsubscribe_group" "example" { | ||
name = "dummy" | ||
description = "dummy" | ||
is_default = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package provider | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strconv" | ||
|
||
"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 = &unsubscribeGroupDataSource{} | ||
_ datasource.DataSourceWithConfigure = &unsubscribeGroupDataSource{} | ||
) | ||
|
||
func newUnsubscribeGroupDataSource() datasource.DataSource { | ||
return &unsubscribeGroupDataSource{} | ||
} | ||
|
||
type unsubscribeGroupDataSource struct { | ||
client *sendgrid.Client | ||
} | ||
|
||
type unsubscribeGroupDataSourceModel struct { | ||
ID types.String `tfsdk:"id"` | ||
Name types.String `tfsdk:"name"` | ||
Description types.String `tfsdk:"description"` | ||
IsDefault types.Bool `tfsdk:"is_default"` | ||
} | ||
|
||
func (d *unsubscribeGroupDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_unsubscribe_group" | ||
} | ||
|
||
func (d *unsubscribeGroupDataSource) 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 *unsubscribeGroupDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
MarkdownDescription: ` | ||
Provides a subuser resource. | ||
Suppression groups, or unsubscribe groups, are specific types or categories of emails from which you would like your recipients to be able to unsubscribe. For example: Daily Newsletters, Invoices, and System Alerts are all potential suppression groups. | ||
Visit the main documentation to [learn more about suppression/unsubscribe groups](https://sendgrid.com/docs/ui/sending-email/unsubscribe-groups/). | ||
`, | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
MarkdownDescription: "The ID of the unsubscribe group.", | ||
Required: true, | ||
}, | ||
"name": schema.StringAttribute{ | ||
MarkdownDescription: "The name of your suppression group.", | ||
Computed: true, | ||
}, | ||
"description": schema.StringAttribute{ | ||
MarkdownDescription: "A brief description of your suppression group.", | ||
Computed: true, | ||
}, | ||
"is_default": schema.BoolAttribute{ | ||
MarkdownDescription: "Indicates if you would like this to be your default suppression group.", | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *unsubscribeGroupDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var s unsubscribeGroupDataSourceModel | ||
|
||
resp.Diagnostics.Append(req.Config.Get(ctx, &s)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
groupID := s.ID.ValueString() | ||
id, _ := strconv.ParseInt(groupID, 10, 64) | ||
o, err := d.client.GetSuppressionGroup(ctx, id) | ||
if err != nil { | ||
resp.Diagnostics.AddError( | ||
"Reading unsubscribe group", | ||
fmt.Sprintf("Unable to get unsubscribe group, got error: %s", err), | ||
) | ||
return | ||
} | ||
|
||
s.ID = types.StringValue(groupID) | ||
s.Name = types.StringValue(o.Name) | ||
s.Description = types.StringValue(o.Description) | ||
s.IsDefault = types.BoolValue(o.IsDefault) | ||
|
||
resp.Diagnostics.Append(resp.State.Set(ctx, &s)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestAccUnsubscribeGroupDataSource(t *testing.T) { | ||
resourceName := "data.sendgrid_unsubscribe_group.test" | ||
|
||
name := fmt.Sprintf("test-acc-%s", acctest.RandString(16)) | ||
description := fmt.Sprintf("test-acc-%s", acctest.RandString(16)) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Read testing | ||
{ | ||
Config: testAccUnsubscribeGroupDataSourceConfig(name, description, false), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(resourceName, "id"), | ||
resource.TestCheckResourceAttr(resourceName, "name", name), | ||
resource.TestCheckResourceAttr(resourceName, "description", description), | ||
resource.TestCheckResourceAttr(resourceName, "is_default", "false"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccUnsubscribeGroupDataSourceConfig(name, description string, is_default bool) string { | ||
return fmt.Sprintf(` | ||
resource "sendgrid_unsubscribe_group" "test" { | ||
name = "%s" | ||
description = "%s" | ||
is_default = %t | ||
} | ||
data "sendgrid_unsubscribe_group" "test" { | ||
id = sendgrid_unsubscribe_group.test.id | ||
} | ||
`, name, description, is_default) | ||
} |
Oops, something went wrong.