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_telnyx.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_telnyx Data Source - uptimekuma"
subcategory: ""
description: |-
Get Telnyx notification information by ID or name
---

# uptimekuma_notification_telnyx (Data Source)

Get Telnyx notification information by ID or name

## Example Usage

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

# Look up by ID
data "uptimekuma_notification_telnyx" "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_telnyx.alerts.id]
}
```

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

### Optional

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

# uptimekuma_notification_telnyx (Resource)

Telnyx notification resource

## Example Usage

```terraform
resource "uptimekuma_notification_telnyx" "example" {
name = "Telnyx Notifications"
api_key = "KEY0123456789ABCDEF"
phone_number = "+15550001111"
to_number = "+15550002222"
is_active = true
is_default = false
}

resource "uptimekuma_notification_telnyx" "with_messaging_profile" {
name = "Telnyx with Messaging Profile"
api_key = "KEY0123456789ABCDEF"
messaging_profile_id = "40017a13-3f93-4d2d-b29e-1a000000000a"
phone_number = "+15550001111"
to_number = "+15550002222"
is_active = true
is_default = false
}
```

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

### Required

- `api_key` (String, Sensitive) The Telnyx API key used to authenticate requests.
- `name` (String) Notification name
- `phone_number` (String) The sender phone number in E.164 format.
- `to_number` (String) The recipient phone number in E.164 format.

### Optional

- `apply_existing` (Boolean)
- `is_active` (Boolean)
- `is_default` (Boolean)
- `messaging_profile_id` (String) The Telnyx messaging profile ID used to send messages.

### Read-Only

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

# Look up by ID
data "uptimekuma_notification_telnyx" "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_telnyx.alerts.id]
}
18 changes: 18 additions & 0 deletions examples/resources/uptimekuma_notification_telnyx/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "uptimekuma_notification_telnyx" "example" {
name = "Telnyx Notifications"
api_key = "KEY0123456789ABCDEF"
phone_number = "+15550001111"
to_number = "+15550002222"
is_active = true
is_default = false
}

resource "uptimekuma_notification_telnyx" "with_messaging_profile" {
name = "Telnyx with Messaging Profile"
api_key = "KEY0123456789ABCDEF"
messaging_profile_id = "40017a13-3f93-4d2d-b29e-1a000000000a"
phone_number = "+15550001111"
to_number = "+15550002222"
is_active = true
is_default = false
}
139 changes: 139 additions & 0 deletions internal/provider/data_source_notification_telnyx.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 = &NotificationTelnyxDataSource{}

// NewNotificationTelnyxDataSource returns a new instance of the Telnyx notification data source.
func NewNotificationTelnyxDataSource() datasource.DataSource {
return &NotificationTelnyxDataSource{}
}

// NotificationTelnyxDataSource manages Telnyx notification data source operations.
type NotificationTelnyxDataSource struct {
client *kuma.Client
}

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

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

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

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

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

func (d *NotificationTelnyxDataSource) readByName(
ctx context.Context,
data *NotificationTelnyxDataSourceModel,
resp *datasource.ReadResponse,
) {
id, ok := findNotificationByName(ctx, d.client, data.Name.ValueString(), "telnyx", &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_telnyx_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 TestAccNotificationTelnyxDataSource(t *testing.T) {
name := acctest.RandomWithPrefix("TestNotificationTelnyx")

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

func testAccNotificationTelnyxDataSourceConfig(name string) string {
return providerConfig() + fmt.Sprintf(`
resource "uptimekuma_notification_telnyx" "test" {
name = %[1]q
is_active = true
api_key = "KEY0000000000000000000000000000000"
phone_number = "+15550001111"
to_number = "+15550002222"
}

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

func testAccNotificationTelnyxDataSourceConfigByID(name string) string {
return providerConfig() + fmt.Sprintf(`
resource "uptimekuma_notification_telnyx" "test" {
name = %[1]q
is_active = true
api_key = "KEY0000000000000000000000000000000"
phone_number = "+15550001111"
to_number = "+15550002222"
}

data "uptimekuma_notification_telnyx" "test" {
id = uptimekuma_notification_telnyx.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 @@ -439,6 +439,7 @@ func notificationResources() []func() resource.Resource {
NewNotificationSMTPResource,
NewNotificationTeamsResource,
NewNotificationTelegramResource,
NewNotificationTelnyxResource,
NewNotificationTwilioResource,
NewNotificationWAHAResource,
NewNotificationWhapiResource,
Expand Down Expand Up @@ -576,6 +577,7 @@ func notificationDataSources() []func() datasource.DataSource {
NewNotificationSMTPDataSource,
NewNotificationTeamsDataSource,
NewNotificationTelegramDataSource,
NewNotificationTelnyxDataSource,
NewNotificationTwilioDataSource,
NewNotificationWAHADataSource,
NewNotificationWhapiDataSource,
Expand Down
Loading
Loading