Skip to content

Commit

Permalink
Add API structure, godoc and API validation
Browse files Browse the repository at this point in the history
  • Loading branch information
arybolovlev committed Mar 8, 2023
1 parent dbb9cde commit 93f102a
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 3 deletions.
53 changes: 52 additions & 1 deletion api/v1alpha2/workspace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package v1alpha2

import (
tfc "github.com/hashicorp/go-tfe"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -271,7 +272,56 @@ type SSHKey struct {
Name string `json:"name,omitempty"`
}

type Notification struct{}
// NotificationTrigger represents the different TFC notifications that can be sent as a run's progress transitions between different states.
// This must be aligned with go-tfe type `NotificationTriggerType`.
//
// +kubebuilder:validation:Enum=applying;checkFailed;completed;created;driftDetected;errored;healthAssessmentFail;needsAttention;planning
type NotificationTrigger string

// Notifications allow you to send messages to other applications based on run and workspace events.
// More information:
// - https://developer.hashicorp.com/terraform/cloud-docs/workspaces/settings/notifications
type Notification struct {
// Notification name.
//
//+kubebuilder:validation:MinLength=1
Name string `json:"name"`
// The type of the notification.
//
//+kubebuilder:validation:Enum=email;generic;microsoft-teams;slack
Type tfc.NotificationDestinationType `json:"type"`
// Whether the notification configuration should be enabled or not.
//
//+kubebuilder:default=true
//+optional
Enabled bool `json:"enabled,omitempty"`
// The token of the notification.
//
//+kubebuilder:validation:MinLength=1
//+optional
Token string `json:"token,omitempty"`
// The list of run events that will trigger notifications.
//
//+kubebuilder:validation:MinItems=1
//+optional
Triggers []NotificationTrigger `json:"triggers,omitempty"`
// The URL of the notification.
//
//+kubebuilder:validation:MinLength=1
//+optional
URL string `json:"url,omitempty"`
// The list of email addresses that will receive notification emails.
// It is only available for TFE users. It is not available in TFC.
//
//+kubebuilder:validation:MinItems=1
//+optional
EmailAddresses []string `json:"emailAddresses,omitempty"`
// The list of users belonging to the organization that will receive notification emails.
//
//+kubebuilder:validation:MinItems=1
//+optional
EmailUsers []string `json:"emailUsers,omitempty"`
}

// WorkspaceSpec defines the desired state of Workspace.
type WorkspaceSpec struct {
Expand Down Expand Up @@ -410,6 +460,7 @@ type WorkspaceSpec struct {
// More information:
// - https://developer.hashicorp.com/terraform/cloud-docs/workspaces/settings/notifications
//
//+kubebuilder:validation:MinItems=1
//+optional
Notifications []Notification `json:"notifications,omitempty"`
}
Expand Down
19 changes: 18 additions & 1 deletion api/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions config/crd/bases/app.terraform.io_workspaces.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,75 @@ spec:
description: 'Notifications allow you to send messages to other applications
based on run and workspace events. More information: - https://developer.hashicorp.com/terraform/cloud-docs/workspaces/settings/notifications'
items:
description: 'Notifications allow you to send messages to other
applications based on run and workspace events. More information:
- https://developer.hashicorp.com/terraform/cloud-docs/workspaces/settings/notifications'
properties:
emailAddresses:
description: The list of email addresses that will receive notification
emails. It is only available for TFE users. It is not available
in TFC.
items:
type: string
minItems: 1
type: array
emailUsers:
description: The list of users belonging to the organization
that will receive notification emails.
items:
type: string
minItems: 1
type: array
enabled:
default: true
description: Whether the notification configuration should be
enabled or not.
type: boolean
name:
description: Notification name.
minLength: 1
type: string
token:
description: The token of the notification.
minLength: 1
type: string
triggers:
description: The list of run events that will trigger notifications.
items:
description: NotificationTrigger represents the different
TFC notifications that can be sent as a run's progress transitions
between different states. This must be aligned with go-tfe
type `NotificationTriggerType`.
enum:
- applying
- checkFailed
- completed
- created
- driftDetected
- errored
- healthAssessmentFail
- needsAttention
- planning
type: string
minItems: 1
type: array
type:
description: The type of the notification.
enum:
- email
- generic
- microsoft-teams
- slack
type: string
url:
description: The URL of the notification.
minLength: 1
type: string
required:
- name
- type
type: object
minItems: 1
type: array
organization:
description: 'Organization name where the Workspace will be created.
Expand Down
12 changes: 11 additions & 1 deletion docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,21 @@ _Appears in:_




Notifications allow you to send messages to other applications based on run and workspace events. More information: - https://developer.hashicorp.com/terraform/cloud-docs/workspaces/settings/notifications

_Appears in:_
- [WorkspaceSpec](#workspacespec)

| Field | Description |
| --- | --- |
| `name` _string_ | Notification name. |
| `type` _NotificationDestinationType_ | The type of the notification. |
| `enabled` _boolean_ | Whether the notification configuration should be enabled or not. |
| `token` _string_ | The token of the notification. |
| `triggers` _NotificationTrigger array_ | The list of run events that will trigger notifications. |
| `url` _string_ | The URL of the notification. |
| `emailAddresses` _string array_ | The list of email addresses that will receive notification emails. It is only available for TFE users. It is not available in TFC. |
| `emailUsers` _string array_ | The list of users belonging to the organization that will receive notification emails. |


#### OutputStatus
Expand Down

0 comments on commit 93f102a

Please sign in to comment.