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_whatsapp360messenger.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_whatsapp360messenger Data Source - uptimekuma"
subcategory: ""
description: |-
Get WhatsApp 360messenger notification information by ID or name
---

# uptimekuma_notification_whatsapp360messenger (Data Source)

Get WhatsApp 360messenger notification information by ID or name

## Example Usage

```terraform
# Look up an existing WhatsApp 360messenger notification by name
data "uptimekuma_notification_whatsapp360messenger" "alerts" {
name = "WhatsApp 360messenger Alerts"
}

# Look up by ID
data "uptimekuma_notification_whatsapp360messenger" "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_whatsapp360messenger.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_whatsapp360messenger.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_whatsapp360messenger Resource - uptimekuma"
subcategory: ""
description: |-
WhatsApp 360messenger notification resource
---

# uptimekuma_notification_whatsapp360messenger (Resource)

WhatsApp 360messenger notification resource

## Example Usage

```terraform
resource "uptimekuma_notification_whatsapp360messenger" "example" {
name = "WhatsApp 360messenger Notifications"
auth_token = "YOUR_360MESSENGER_AUTH_TOKEN"
recipient = "+15551234567,+15557654321"
is_active = true
is_default = false
}

resource "uptimekuma_notification_whatsapp360messenger" "with_template" {
name = "WhatsApp 360messenger with Template"
auth_token = "YOUR_360MESSENGER_AUTH_TOKEN"
recipient = "+15551234567"
group_ids = ["120363012345678901", "120363098765432109"]
use_template = true
template = "{{ name }} is {{ status }}"
is_active = true
is_default = false
}
```

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

### Required

- `auth_token` (String, Sensitive) The Bearer authentication token for the 360messenger API.
- `name` (String) Notification name
- `recipient` (String) A comma- or semicolon-separated list of phone numbers to send WhatsApp notifications to.

### Optional

- `apply_existing` (Boolean)
- `group_id` (String) Legacy single WhatsApp group ID, kept for backwards compatibility. Conflicts with `group_ids`.
- `group_ids` (List of String) A list of WhatsApp group IDs to send notifications to. Conflicts with `group_id`.
- `is_active` (Boolean)
- `is_default` (Boolean)
- `template` (String) The custom message template for WhatsApp notifications.
- `use_template` (Boolean) If true, use a custom message template for WhatsApp notifications.

### Read-Only

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

# Look up by ID
data "uptimekuma_notification_whatsapp360messenger" "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_whatsapp360messenger.alerts.id]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "uptimekuma_notification_whatsapp360messenger" "example" {
name = "WhatsApp 360messenger Notifications"
auth_token = "YOUR_360MESSENGER_AUTH_TOKEN"
recipient = "+15551234567,+15557654321"
is_active = true
is_default = false
}

resource "uptimekuma_notification_whatsapp360messenger" "with_template" {
name = "WhatsApp 360messenger with Template"
auth_token = "YOUR_360MESSENGER_AUTH_TOKEN"
recipient = "+15551234567"
group_ids = ["120363012345678901", "120363098765432109"]
use_template = true
template = "{{ name }} is {{ status }}"
is_active = true
is_default = false
}
141 changes: 141 additions & 0 deletions internal/provider/data_source_notification_whatsapp360messenger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
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 = &NotificationWhatsapp360messengerDataSource{}

// NewNotificationWhatsapp360messengerDataSource returns a new instance of the WhatsApp 360messenger
// notification data source.
func NewNotificationWhatsapp360messengerDataSource() datasource.DataSource {
return &NotificationWhatsapp360messengerDataSource{}
}

// NotificationWhatsapp360messengerDataSource manages WhatsApp 360messenger notification data source operations.
type NotificationWhatsapp360messengerDataSource struct {
client *kuma.Client
}

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

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

// Schema returns the schema for the data source.
func (*NotificationWhatsapp360messengerDataSource) Schema(
_ context.Context,
_ datasource.SchemaRequest,
resp *datasource.SchemaResponse,
) {
resp.Schema = schema.Schema{
MarkdownDescription: "Get WhatsApp 360messenger 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 *NotificationWhatsapp360messengerDataSource) 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 *NotificationWhatsapp360messengerDataSource) Read(
ctx context.Context,
req datasource.ReadRequest,
resp *datasource.ReadResponse,
) {
var data NotificationWhatsapp360messengerDataSourceModel

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 *NotificationWhatsapp360messengerDataSource) readByID(
ctx context.Context,
data *NotificationWhatsapp360messengerDataSourceModel,
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() != "Whatsapp360messenger" {
resp.Diagnostics.AddError(
"incorrect notification type",
fmt.Sprintf(
"notification with ID %d has type %q, expected \"Whatsapp360messenger\"",
data.ID.ValueInt64(),
notification.Type(),
),
)
return
}

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

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

data.ID = types.Int64Value(id)
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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 TestAccNotificationWhatsapp360messengerDataSource(t *testing.T) {
name := acctest.RandomWithPrefix("NotificationWhatsapp360messenger")

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

func testAccNotificationWhatsapp360messengerDataSourceConfig(name string) string {
return providerConfig() + fmt.Sprintf(`
resource "uptimekuma_notification_whatsapp360messenger" "test" {
name = %[1]q
is_active = true
auth_token = "auth-token-xxxxxxxx"
recipient = "+15551234567"
}

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

func testAccNotificationWhatsapp360messengerDataSourceConfigByID(name string) string {
return providerConfig() + fmt.Sprintf(`
resource "uptimekuma_notification_whatsapp360messenger" "test" {
name = %[1]q
is_active = true
auth_token = "auth-token-xxxxxxxx"
recipient = "+15551234567"
}

data "uptimekuma_notification_whatsapp360messenger" "test" {
id = uptimekuma_notification_whatsapp360messenger.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 @@ -442,6 +442,7 @@ func notificationResources() []func() resource.Resource {
NewNotificationTwilioResource,
NewNotificationWAHAResource,
NewNotificationWhapiResource,
NewNotificationWhatsapp360messengerResource,
NewNotificationWPushResource,
NewNotificationWebhookResource,
NewNotificationWeComResource,
Expand Down Expand Up @@ -579,6 +580,7 @@ func notificationDataSources() []func() datasource.DataSource {
NewNotificationTwilioDataSource,
NewNotificationWAHADataSource,
NewNotificationWhapiDataSource,
NewNotificationWhatsapp360messengerDataSource,
NewNotificationWPushDataSource,
NewNotificationWebhookDataSource,
NewNotificationWeComDataSource,
Expand Down
Loading
Loading