Skip to content
Open
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
40 changes: 40 additions & 0 deletions docs/data-sources/notification_resend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "uptimekuma_notification_resend Data Source - uptimekuma"
subcategory: ""
description: |-
Get Resend notification information by ID or name
---

# uptimekuma_notification_resend (Data Source)

Get Resend notification information by ID or name

## Example Usage

```terraform
# Look up an existing Resend notification by name
data "uptimekuma_notification_resend" "alerts" {
name = "Resend Alerts"
}

# Look up by ID
data "uptimekuma_notification_resend" "by_id" {
id = 1
}

# Use with a monitor resource
resource "uptimekuma_monitor_http" "api" {
name = "API Monitor"
url = "https://api.example.com/health"
notification_ids = [data.uptimekuma_notification_resend.alerts.id]
}
```

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

### Optional

- `id` (Number) Notification identifier
- `name` (String) Notification name
57 changes: 57 additions & 0 deletions docs/resources/notification_resend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "uptimekuma_notification_resend Resource - uptimekuma"
subcategory: ""
description: |-
Resend notification resource
---

# uptimekuma_notification_resend (Resource)

Resend notification resource

## Example Usage

```terraform
resource "uptimekuma_notification_resend" "example" {
name = "Resend Notifications"
api_key = "re_your_api_key_here"
from_email = "monitoring@example.com"
to_email = "alerts@example.com"
is_active = true
is_default = false
}

resource "uptimekuma_notification_resend" "with_subject" {
name = "Resend with Custom Subject"
api_key = "re_your_api_key_here"
from_email = "monitoring@example.com"
from_name = "Uptime Kuma"
to_email = "alerts@example.com,oncall@example.com"
subject = "Uptime Alert Notification"
is_active = true
is_default = false
}
```

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

### Required

- `api_key` (String, Sensitive) The Resend API key used to send notifications.
- `from_email` (String) The sender email address.
- `name` (String) Notification name
- `to_email` (String) The recipient email address(es). Multiple recipients can be specified as a comma-separated list.

### Optional

- `apply_existing` (Boolean)
- `from_name` (String) The sender display name.
- `is_active` (Boolean)
- `is_default` (Boolean)
- `subject` (String) The subject of the email notification.

### Read-Only

- `id` (Number) Notification identifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Look up an existing Resend notification by name
data "uptimekuma_notification_resend" "alerts" {
name = "Resend Alerts"
}

# Look up by ID
data "uptimekuma_notification_resend" "by_id" {
id = 1
}

# Use with a monitor resource
resource "uptimekuma_monitor_http" "api" {
name = "API Monitor"
url = "https://api.example.com/health"
notification_ids = [data.uptimekuma_notification_resend.alerts.id]
}
19 changes: 19 additions & 0 deletions examples/resources/uptimekuma_notification_resend/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
resource "uptimekuma_notification_resend" "example" {
name = "Resend Notifications"
api_key = "re_your_api_key_here"
from_email = "monitoring@example.com"
to_email = "alerts@example.com"
is_active = true
is_default = false
}

resource "uptimekuma_notification_resend" "with_subject" {
name = "Resend with Custom Subject"
api_key = "re_your_api_key_here"
from_email = "monitoring@example.com"
from_name = "Uptime Kuma"
to_email = "alerts@example.com,oncall@example.com"
subject = "Uptime Alert Notification"
is_active = true
is_default = false
}
139 changes: 139 additions & 0 deletions internal/provider/data_source_notification_resend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
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"

kuma "github.com/breml/go-uptime-kuma-client"
)

var _ datasource.DataSource = &NotificationResendDataSource{}

// NewNotificationResendDataSource returns a new instance of the Resend notification data source.
func NewNotificationResendDataSource() datasource.DataSource {
return &NotificationResendDataSource{}
}

// NotificationResendDataSource manages Resend notification data source operations.
type NotificationResendDataSource struct {
client *kuma.Client
}

// NotificationResendDataSourceModel describes the data model for Resend notification data source.
type NotificationResendDataSourceModel struct {
ID types.Int64 `tfsdk:"id"`
Name types.String `tfsdk:"name"`
}

// Metadata returns the metadata for the data source.
func (*NotificationResendDataSource) Metadata(
_ context.Context,
req datasource.MetadataRequest,
resp *datasource.MetadataResponse,
) {
resp.TypeName = req.ProviderTypeName + "_notification_resend"
}

// Schema returns the schema for the data source.
func (*NotificationResendDataSource) Schema(
_ context.Context,
_ datasource.SchemaRequest,
resp *datasource.SchemaResponse,
) {
resp.Schema = schema.Schema{
MarkdownDescription: "Get Resend notification information by ID or name",
Attributes: map[string]schema.Attribute{
"id": schema.Int64Attribute{
MarkdownDescription: "Notification identifier",
Optional: true,
Computed: true,
},
"name": schema.StringAttribute{
MarkdownDescription: "Notification name",
Optional: true,
Computed: true,
},
},
}
}

// Configure configures the data source with the API client.
func (d *NotificationResendDataSource) Configure(
_ context.Context,
req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse,
) {
d.client = configureClient(req.ProviderData, &resp.Diagnostics)
}

// Read reads the current state of the data source.
func (d *NotificationResendDataSource) Read(
ctx context.Context,
req datasource.ReadRequest,
resp *datasource.ReadResponse,
) {
var data NotificationResendDataSourceModel

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

if !validateNotificationDataSourceInput(resp, data.ID, data.Name) {
return
}

// Attempt to read by ID if provided.
if !data.ID.IsNull() && !data.ID.IsUnknown() {
d.readByID(ctx, &data, resp)
return
}

// Attempt to read by name if ID not provided.
d.readByName(ctx, &data, resp)
}

func (d *NotificationResendDataSource) readByID(
ctx context.Context,
data *NotificationResendDataSourceModel,
resp *datasource.ReadResponse,
) {
notification, err := d.client.GetNotification(ctx, data.ID.ValueInt64())
if err != nil {
resp.Diagnostics.AddError("failed to read notification", err.Error())
return
}

if notification.Type() != "Resend" {
resp.Diagnostics.AddError(
"incorrect notification type",
fmt.Sprintf(
"notification with ID %d has type %q, expected \"Resend\"",
data.ID.ValueInt64(),
notification.Type(),
),
)
return
}

data.Name = types.StringValue(notification.Name)
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}

func (d *NotificationResendDataSource) readByName(
ctx context.Context,
data *NotificationResendDataSourceModel,
resp *datasource.ReadResponse,
) {
id, ok := findNotificationByName(ctx, d.client, data.Name.ValueString(), "Resend", &resp.Diagnostics)
if !ok {
return
}

data.ID = types.Int64Value(id)
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
80 changes: 80 additions & 0 deletions internal/provider/data_source_notification_resend_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package provider

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
"github.com/hashicorp/terraform-plugin-testing/statecheck"
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
)

func TestAccNotificationResendDataSource(t *testing.T) {
name := acctest.RandomWithPrefix("NotificationResend")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccNotificationResendDataSourceConfig(name),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(
"data.uptimekuma_notification_resend.test",
tfjsonpath.New("name"),
knownvalue.StringExact(name),
),
statecheck.ExpectKnownValue(
"data.uptimekuma_notification_resend.test",
tfjsonpath.New("id"),
knownvalue.NotNull(),
),
},
},
{
Config: testAccNotificationResendDataSourceConfigByID(name),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(
"data.uptimekuma_notification_resend.test",
tfjsonpath.New("name"),
knownvalue.StringExact(name),
),
},
},
},
})
}

func testAccNotificationResendDataSourceConfig(name string) string {
return providerConfig() + fmt.Sprintf(`
resource "uptimekuma_notification_resend" "test" {
name = %[1]q
is_active = true
api_key = "re_test_apikey"
from_email = "monitoring@example.com"
to_email = "alerts@example.com"
}

data "uptimekuma_notification_resend" "test" {
name = uptimekuma_notification_resend.test.name
}
`, name)
}

func testAccNotificationResendDataSourceConfigByID(name string) string {
return providerConfig() + fmt.Sprintf(`
resource "uptimekuma_notification_resend" "test" {
name = %[1]q
is_active = true
api_key = "re_test_apikey"
from_email = "monitoring@example.com"
to_email = "alerts@example.com"
}

data "uptimekuma_notification_resend" "test" {
id = uptimekuma_notification_resend.test.id
}
`, name)
}
2 changes: 2 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ func notificationResources() []func() resource.Resource {
NewNotificationPushoverResource,
NewNotificationPushPlusResource,
NewNotificationPushyResource,
NewNotificationResendResource,
NewNotificationRocketChatResource,
NewNotificationSendgridResource,
NewNotificationServerChanResource,
Expand Down Expand Up @@ -554,6 +555,7 @@ func notificationDataSources() []func() datasource.DataSource {
NewNotificationPushoverDataSource,
NewNotificationPushPlusDataSource,
NewNotificationPushyDataSource,
NewNotificationResendDataSource,
NewNotificationRocketChatDataSource,
NewNotificationSendgridDataSource,
NewNotificationServerChanDataSource,
Expand Down
Loading
Loading