notifications

package
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2025 License: MPL-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package notifications sends notifications for run state transitions and workspace events.

Index

Constants

View Source
const (
	DestinationGeneric   Destination = "generic"
	DestinationSlack     Destination = "slack"
	DestinationGCPPubSub Destination = "gcppubsub"
	// Email type is only accepted in order to pass the `go-tfe` API tests,
	// which create configs with this type. It otherwise is entirely
	// unfunctional; no emails are sent.
	DestinationEmail Destination = "email"

	TriggerCreated        Trigger = "run:created"
	TriggerPlanning       Trigger = "run:planning"
	TriggerNeedsAttention Trigger = "run:needs_attention"
	TriggerApplying       Trigger = "run:applying"
	TriggerCompleted      Trigger = "run:completed"
	TriggerErrored        Trigger = "run:errored"
)

Variables

View Source
var (
	ErrInvalidGoogleProjectID    = errors.New("URL host must be a valid GCP project ID")
	ErrInvalidGooglePubSubTopic  = errors.New("URL path must be a valid GCP pubsub topic ID")
	ErrInvalidGooglePubSubScheme = errors.New("URL scheme must be: " + gcpPubSubScheme)
)
View Source
var (
	ErrUnsupportedDestination = errors.New("unsupported notification destination")
	ErrDestinationRequiresURL = errors.New("URL must be specified for this destination")
	ErrInvalidTrigger         = errors.New("invalid notification trigger")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	ID              resource.TfeID `json:"notification_configuration_id" db:"notification_configuration_id"`
	CreatedAt       time.Time      `json:"created_at" db:"created_at"`
	UpdatedAt       time.Time      `json:"updated_at" db:"updated_at"`
	DestinationType Destination    `json:"destination_type" db:"destination_type"`
	Enabled         bool
	Name            string
	Triggers        []Trigger
	URL             *string
	WorkspaceID     resource.TfeID `json:"workspace_id" db:"workspace_id"`
}

Config represents a Notification Configuration.

func NewConfig

func NewConfig(workspaceID resource.TfeID, opts CreateConfigOptions) (*Config, error)

func (*Config) LogValue

func (c *Config) LogValue() slog.Value

type CreateConfigOptions

type CreateConfigOptions struct {
	// Required: The destination type of the notification configuration
	DestinationType Destination

	// Required: Whether the notification configuration should be enabled or not
	Enabled *bool

	// Required: The name of the notification configuration
	Name *string

	// Optional: The token of the notification configuration
	Token *string

	// Optional: The list of run events that will trigger notifications.
	Triggers []Trigger

	// Optional: The url of the notification configuration
	URL *string
}

type Destination

type Destination string

Destination is the destination platform for an event.

type Event added in v0.3.23

type Event struct {
	ID          resource.TfeID `json:"run_id"`
	WorkspaceID resource.TfeID `json:"workspace_id"`
}

type GenericPayload

type GenericPayload struct {
	PayloadVersion              int
	NotificationConfigurationID resource.TfeID
	RunURL                      string
	RunID                       resource.TfeID
	RunMessage                  string
	RunCreatedAt                time.Time
	RunCreatedBy                string
	WorkspaceID                 resource.TfeID
	WorkspaceName               string
	OrganizationName            organization.Name
	Notifications               []genericNotificationPayload
}

GenericPayload is the information sent in generic notifications, as documented here:

https://developer.hashicorp.com/terraform/cloud-docs/api-docs/notification-configurations#run-notification-payload

type Notifier

type Notifier struct {
	logr.Logger
	// contains filtered or unexported fields
}

Notifier relays run events onto interested parties

func NewNotifier

func NewNotifier(opts NotifierOptions) *Notifier

func (*Notifier) Start

func (s *Notifier) Start(ctx context.Context) error

Start the notifier daemon. Should be started in a go-routine.

type NotifierOptions

type NotifierOptions struct {
	RunClient          notifierRunClient
	WorkspaceClient    notifierWorkspaceClient
	NotificationClient notifierNotificationClient

	logr.Logger
	*internal.HostnameService
	*sql.DB
}

type Options

type Options struct {
	*sql.DB
	*sql.Listener
	*tfeapi.Responder
	logr.Logger

	Authorizer *authz.Authorizer
}

type Service

type Service struct {
	logr.Logger
	*authz.Authorizer
	// contains filtered or unexported fields
}

func NewService

func NewService(opts Options) *Service

func (*Service) AddHandlers added in v0.2.2

func (s *Service) AddHandlers(r *mux.Router)

func (*Service) Create added in v0.2.2

func (s *Service) Create(ctx context.Context, workspaceID resource.TfeID, opts CreateConfigOptions) (*Config, error)

func (*Service) Delete added in v0.2.2

func (s *Service) Delete(ctx context.Context, id resource.TfeID) error

func (*Service) Get added in v0.2.2

func (s *Service) Get(ctx context.Context, id resource.TfeID) (*Config, error)

func (*Service) List added in v0.2.2

func (s *Service) List(ctx context.Context, workspaceID resource.TfeID) ([]*Config, error)

func (*Service) Update added in v0.2.2

func (s *Service) Update(ctx context.Context, id resource.TfeID, opts UpdateConfigOptions) (*Config, error)

func (*Service) Watch added in v0.2.2

func (s *Service) Watch(ctx context.Context) (<-chan pubsub.Event[*Config], func())

type TFEDeliveryResponse added in v0.3.17

type TFEDeliveryResponse struct {
	Body       string              `jsonapi:"attribute" json:"body"`
	Code       string              `jsonapi:"attribute" json:"code"`
	Headers    map[string][]string `jsonapi:"attribute" json:"headers"`
	SentAt     time.Time           `jsonapi:"attribute" json:"sent-at"`
	Successful string              `jsonapi:"attribute" json:"successful"`
	URL        string              `jsonapi:"attribute" json:"url"`
}

TFEDeliveryResponse represents a notification configuration delivery response.

type TFENotificationConfiguration added in v0.3.17

type TFENotificationConfiguration struct {
	ID                resource.TfeID                 `jsonapi:"primary,notification-configurations"`
	CreatedAt         time.Time                      `jsonapi:"attribute" json:"created-at"`
	DeliveryResponses []*TFEDeliveryResponse         `jsonapi:"attribute" json:"delivery-responses"`
	DestinationType   TFENotificationDestinationType `jsonapi:"attribute" json:"destination-type"`
	Enabled           bool                           `jsonapi:"attribute" json:"enabled"`
	Name              string                         `jsonapi:"attribute" json:"name"`
	Token             string                         `jsonapi:"attribute" json:"token"`
	Triggers          []string                       `jsonapi:"attribute" json:"triggers"`
	UpdatedAt         time.Time                      `jsonapi:"attribute" json:"updated-at"`
	URL               string                         `jsonapi:"attribute" json:"url"`

	// EmailAddresses is only available for TFE users. It is not available in TFC.
	EmailAddresses []string `jsonapi:"attribute" json:"email-addresses"`
	// relationships
	Subscribable *workspace.TFEWorkspace `jsonapi:"relationship" json:"subscribable"`
	EmailUsers   []*user.TFEUser         `jsonapi:"relationship" json:"users"`
}

TFENotificationConfiguration represents a Notification Configuration.

type TFENotificationConfigurationCreateOptions added in v0.3.17

type TFENotificationConfigurationCreateOptions struct {
	// Type is a public field utilized by JSON:API to
	// set the resource type via the field tag.
	// It is not a user-defined value and does not need to be set.
	// https://jsonapi.org/format/#crud-creating
	Type string `jsonapi:"primary,notification-configurations"`

	// Required: The destination type of the notification configuration
	DestinationType *TFENotificationDestinationType `jsonapi:"attribute" json:"destination-type"`

	// Required: Whether the notification configuration should be enabled or not
	Enabled *bool `jsonapi:"attribute" json:"enabled"`

	// Required: The name of the notification configuration
	Name *string `jsonapi:"attribute" json:"name"`

	// Optional: The token of the notification configuration
	Token *string `jsonapi:"attribute" json:"token,omitempty"`

	// Optional: The list of run events that will trigger notifications.
	Triggers []TFENotificationTriggerType `jsonapi:"attribute" json:"triggers,omitempty"`

	// Optional: The url of the notification configuration
	URL *string `jsonapi:"attribute" json:"url,omitempty"`

	// Optional: The list of email addresses that will receive notification emails.
	// EmailAddresses is only available for TFE users. It is not available in TFC.
	EmailAddresses []string `jsonapi:"attribute" json:"email-addresses,omitempty"`

	// Optional: The list of users belonging to the organization that will receive notification emails.
	EmailUsers []*user.TFEUser `jsonapi:"relationship" json:"users,omitempty"`
}

TFENotificationConfigurationCreateOptions represents the options for creating a new notification configuration.

type TFENotificationConfigurationList added in v0.3.17

type TFENotificationConfigurationList struct {
	*types.Pagination
	Items []*TFENotificationConfiguration
}

TFENotificationConfigurationList represents a list of Notification Configurations.

type TFENotificationConfigurationUpdateOptions added in v0.3.17

type TFENotificationConfigurationUpdateOptions struct {
	// Type is a public field utilized by JSON:API to
	// set the resource type via the field tag.
	// It is not a user-defined value and does not need to be set.
	// https://jsonapi.org/format/#crud-creating
	Type string `jsonapi:"primary,notification-configurations"`

	// Optional: Whether the notification configuration should be enabled or not
	Enabled *bool `jsonapi:"attribute" json:"enabled,omitempty"`

	// Optional: The name of the notification configuration
	Name *string `jsonapi:"attribute" json:"name,omitempty"`

	// Optional: The token of the notification configuration
	Token *string `jsonapi:"attribute" json:"token,omitempty"`

	// Optional: The list of run events that will trigger notifications.
	Triggers []TFENotificationTriggerType `jsonapi:"attribute" json:"triggers,omitempty"`

	// Optional: The url of the notification configuration
	URL *string `jsonapi:"attribute" json:"url,omitempty"`

	// Optional: The list of email addresses that will receive notification emails.
	// EmailAddresses is only available for TFE users. It is not available in TFC.
	EmailAddresses []string `jsonapi:"attribute" json:"email-addresses,omitempty"`

	// Optional: The list of users belonging to the organization that will receive notification emails.
	EmailUsers []*user.TFEUser `jsonapi:"relationship" json:"users,omitempty"`
}

TFENotificationConfigurationUpdateOptions represents the options for updating a existing notification configuration.

type TFENotificationDestinationType added in v0.3.17

type TFENotificationDestinationType string

TFENotificationDestinationType represents the destination type of the notification configuration.

const (
	NotificationDestinationTypeEmail          TFENotificationDestinationType = "email"
	NotificationDestinationTypeGeneric        TFENotificationDestinationType = "generic"
	NotificationDestinationTypeSlack          TFENotificationDestinationType = "slack"
	NotificationDestinationTypeMicrosoftTeams TFENotificationDestinationType = "microsoft-teams"
)

List of available notification destination types.

type TFENotificationTriggerType added in v0.3.17

type TFENotificationTriggerType string

TFENotificationTriggerType represents the different TFE notifications that can be sent as a run's progress transitions between different states

const (
	NotificationTriggerCreated               TFENotificationTriggerType = "run:created"
	NotificationTriggerPlanning              TFENotificationTriggerType = "run:planning"
	NotificationTriggerNeedsAttention        TFENotificationTriggerType = "run:needs_attention"
	NotificationTriggerApplying              TFENotificationTriggerType = "run:applying"
	NotificationTriggerCompleted             TFENotificationTriggerType = "run:completed"
	NotificationTriggerErrored               TFENotificationTriggerType = "run:errored"
	NotificationTriggerAssessmentDrifted     TFENotificationTriggerType = "assessment:drifted"
	NotificationTriggerAssessmentFailed      TFENotificationTriggerType = "assessment:failed"
	NotificationTriggerAssessmentCheckFailed TFENotificationTriggerType = "assessment:check_failure"
)

type Trigger

type Trigger string

Trigger is the event triggering a notification

type UpdateConfigOptions

type UpdateConfigOptions struct {
	// Optional: Whether the notification configuration should be enabled or not
	Enabled *bool

	// Optional: The name of the notification configuration
	Name *string

	// Optional: The token of the notification configuration
	Token *string

	// Optional: The list of run events that will trigger notifications.
	Triggers []Trigger

	// Optional: The url of the notification configuration
	URL *string
}

UpdateConfigOptions represents the options for updating a existing notification configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL