Skip to content

Conversation

jpadrianoGo
Copy link
Contributor

@jpadrianoGo jpadrianoGo commented Jun 16, 2025

Description

This PR updates DeliveryResponses field parsing of NotificationConfiguration. NotificationConfiguration now parses DeliveryResponses.

The change aims to be part of automating notification configuration management for workspaces. This aligns with API's NotificationConfiguration return for List, Create, Read, Update, and Verify operations.

curl
--header "Authorization: Bearer $TOKEN"
--request POST
--data @payload.json
https://app.terraform.io/api/v2/workspaces/ws-***/notification-configurations/

{
  "data": {
    "id": "nc-***",
    "type": "notification-configurations",
    "attributes": {
      "enabled": true,
      "name": "Notify organization users about run",
      "destination-type": "generic",
      "triggers": [
        "run:applying",
        "run:completed",
        "run:created",
        "run:errored",
        "run:needs_attention",
        "run:planning"
      ],
      "delivery-responses": [
        {
          "code": "200",
          "body": "{\"code\":200,\"description\":\"OK\"}",
          "headers": {
            "content-length": ["31"],
            "content-type": ["application/json"],
            "date": ["Mon, 16 Jun 2025 01:42:05 GMT"]
          },
          "sent-at": "2025-06-16T01:42:06+00:00",
          "successful": "true",
          "url": "***"
        }
      ],
      "created-at": "2025-06-16T01:42:06.447Z",
      "updated-at": "2025-06-16T01:42:06.447Z",
      "url": "***",
      "token": null
    },
    "relationships": {
      "subscribable": {
        "data": {
          "id": "ws-***",
          "type": "workspaces"
        }
      }
    },
    "links": {
      "self": "/api/v2/notification-configurations/nc-***"
    }
  }
}

A new function is added to parse DeliveryResponse func parseDeliveryResponses(nc *NotificationConfiguration).
The following functions have been updated to use parseDeliveryResponses:

  • NotificationConfigurations.List(ctx context.Context, subscribableID string, options *NotificationConfigurationListOptions) (*NotificationConfigurationList, error)
  • NotificationConfigurations.Create(ctx context.Context, subscribableID string, options NotificationConfigurationCreateOptions) (*NotificationConfiguration, error)
  • NotificationConfigurations.Read(ctx context.Context, notificationConfigurationID string) (*NotificationConfiguration, error)
  • NotificationConfigurations.Update(ctx context.Context, notificationConfigurationID string, options NotificationConfigurationUpdateOptions) (*NotificationConfiguration, error)

Testing plan

  1. Generate the required environment variables for go test, TFE_ADDRESS, TFE_TOKEN, and TFC_RUN_TASK_URL
  2. Run TFE_ADDRESS="https://example" TFE_TOKEN="example" TFC_RUN_TASK_URL="working-URL" go test ./... -v -run TestNotificationConfigurationReadDeliveryResponses . The new tests should pass.
  3. DeliveryResponses is read for NotificationConfigurations.
  4. Run all tests in notification_configuration_integration_test.go and existing tests should pass.

External links

Output from tests

Including output from tests may require access to a TFE instance. Ignore this section if you have no environment to test against.

$ TFE_ADDRESS="https://example" TFE_TOKEN="example"  TFC_RUN_TASK_URL="working-URL"  go test ./... -v -run TestNotificationConfigurationReadDeliveryResponses 
=== RUN   TestNotificationConfigurationReadDeliveryResponses
=== RUN   TestNotificationConfigurationReadDeliveryResponses/with_notification_configuration_create
=== RUN   TestNotificationConfigurationReadDeliveryResponses/with_notification_configuration_list
=== RUN   TestNotificationConfigurationReadDeliveryResponses/with_notification_configuration_read
=== RUN   TestNotificationConfigurationReadDeliveryResponses/with_notification_configuration_update
=== RUN   TestNotificationConfigurationReadDeliveryResponses/with_notification_configuration_verify
=== RUN   TestNotificationConfigurationReadDeliveryResponses/with_notification_configuration_disabled
--- PASS: TestNotificationConfigurationReadDeliveryResponses (17.20s)
    --- PASS: TestNotificationConfigurationReadDeliveryResponses/with_notification_configuration_create (2.28s)
    --- PASS: TestNotificationConfigurationReadDeliveryResponses/with_notification_configuration_list (3.35s)
    --- PASS: TestNotificationConfigurationReadDeliveryResponses/with_notification_configuration_read (2.45s)
    --- PASS: TestNotificationConfigurationReadDeliveryResponses/with_notification_configuration_update (2.74s)
    --- PASS: TestNotificationConfigurationReadDeliveryResponses/with_notification_configuration_verify (2.83s)
    --- PASS: TestNotificationConfigurationReadDeliveryResponses/with_notification_configuration_disabled (2.48s)
PASS
ok      github.com/hashicorp/go-tfe     17.211s

@jpadrianoGo jpadrianoGo requested a review from a team as a code owner June 16, 2025 01:53
@jpadrianoGo jpadrianoGo force-pushed the notificationConfiguration/deliveryResponses branch from 8cd2d75 to eef8acd Compare June 18, 2025 03:47
@jpadrianoGo jpadrianoGo force-pushed the notificationConfiguration/deliveryResponses branch from eef8acd to 058e5d1 Compare June 18, 2025 21:43
@ctrombley
Copy link
Collaborator

Superseded by #1190.

@ctrombley ctrombley closed this Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants