Skip to content

Commit

Permalink
Adding environment webhook support, webhook groups (#406)
Browse files Browse the repository at this point in the history
### Summary 
- Adding webhook group support
- Adding environment webhook support
- I have to build this on top on environment project support PR, so this
will need to go in only after
[this](#398)

### Testing
- Manual test
- Updating example/integ test

---------

Co-authored-by: Sean Yeh <[email protected]>
Co-authored-by: Derek <[email protected]>
  • Loading branch information
3 people authored Sep 13, 2024
1 parent a56db10 commit cde69c6
Show file tree
Hide file tree
Showing 20 changed files with 1,091 additions and 95 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
### Improvements

- Added support for ESC Webhooks and Webhook Groups [#401](https://github.com/pulumi/pulumi-pulumiservice/issues/409)

### Bug Fixes

### Miscellaneous
4 changes: 4 additions & 0 deletions examples/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ func TestTeamsExample(t *testing.T) {

func TestNodejsWebhookExample(t *testing.T) {
cwd := getCwd(t)
digits := generateRandomFiveDigits()
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: path.Join(cwd, ".", "ts-webhooks"),
Config: map[string]string{
"digits": digits,
},
Dependencies: []string{
"@pulumi/pulumiservice",
},
Expand Down
46 changes: 38 additions & 8 deletions examples/ts-webhooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,57 @@
import * as pulumi from "@pulumi/pulumi";
import { Webhook, WebhookFormat, WebhookFilters } from "@pulumi/pulumiservice";
import * as service from "@pulumi/pulumiservice";
import { WebhookGroup, WebhookFormat, WebhookFilters } from "@pulumi/pulumiservice";

const serviceOrg = "service-provider-test-org";
let config = new pulumi.Config();

const webhook = new Webhook("wh", {
var environment = new service.Environment("environment-to-use", {
organization: serviceOrg,
project: "test-project",
name: "testing-environment-ts-"+config.require("digits"),
yaml: new pulumi.asset.StringAsset(
`values:
myNumber: 1`
)
})

// Organization webhook subscribed to all events
const webhookAllEvents = new service.Webhook("org-webhook-all", {
active: true,
displayName: "webhook-from-provider",
organizationName: serviceOrg,
payloadUrl: "https://google.com",
filters: [WebhookFilters.DeploymentStarted, WebhookFilters.DeploymentSucceeded],
});

const stackWebhook = new Webhook("stack-webhook", {
// Organization webhook only subscribed to environments and stacks groups
const webhook = new service.Webhook("org-webhook-groups", {
active: true,
displayName: "webhook-from-provider",
organizationName: serviceOrg,
payloadUrl: "https://google.com",
groups: [ WebhookGroup.Environments, WebhookGroup.Stacks ]
});

// Stack webhook subscribed to a group and specific filters
const stackWebhook = new service.Webhook("stack-webhook", {
active: true,
displayName: "stack-webhook",
organizationName: serviceOrg,
projectName: pulumi.getProject(),
stackName: pulumi.getStack(),
payloadUrl: "https://example.com",
format: WebhookFormat.Slack,
groups: [ WebhookGroup.Stacks ],
filters: [WebhookFilters.DeploymentStarted, WebhookFilters.DeploymentSucceeded],
})

export const orgName = webhook.organizationName;
export const name = webhook.name;
export const stackWebhookName = stackWebhook.name;
export const stackWebhookProjectName = stackWebhook.projectName;
// Environment webhook subscribed to specific filters only
const environmentWebhook = new service.Webhook("env-webhook", {
active: true,
displayName: "env-webhook",
organizationName: serviceOrg,
projectName: environment.project,
environmentName: environment.name,
payloadUrl: "https://example.com",
filters: [WebhookFilters.EnvironmentRevisionCreated, WebhookFilters.ImportedEnvironmentChanged],
})
101 changes: 99 additions & 2 deletions provider/cmd/pulumi-resource-pulumiservice/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@
}
]
},
"pulumiservice:index:WebhookGroup": {
"type": "string",
"enum": [
{
"value": "stacks",
"description": "A group of webhooks containing all stack events.",
"name": "Stacks"
},
{
"value": "deployments",
"description": "A group of webhooks containing all deployment events.",
"name": "Deployments"
},
{
"value": "environments",
"description": "A group of webhooks containing all environment events.",
"name": "Environments"
}
]
},
"pulumiservice:index:WebhookFilters": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -170,6 +190,61 @@
"value": "drift_remediation_failed",
"description": "Trigger a webhook when a drift remediation run fails.",
"name": "DriftRemediationFailed"
},
{
"value": "environment_created",
"description": "Trigger a webhook when a new environment is created.",
"name": "EnvironmentCreated"
},
{
"value": "environment_deleted",
"description": "Trigger a webhook when an environment is deleted.",
"name": "EnvironmentDeleted"
},
{
"value": "environment_revision_created",
"description": "Trigger a webhook when a new revision is created on an environment.",
"name": "EnvironmentRevisionCreated"
},
{
"value": "environment_revision_retracted",
"description": "Trigger a webhook when a revision is retracted on an environment.",
"name": "EnvironmentRevisionRetracted"
},
{
"value": "environment_revision_tag_created",
"description": "Trigger a webhook when a revision tag is created on an environment.",
"name": "EnvironmentRevisionTagCreated"
},
{
"value": "environment_revision_tag_deleted",
"description": "Trigger a webhook when a revision tag is deleted on an environment.",
"name": "EnvironmentRevisionTagDeleted"
},
{
"value": "environment_revision_tag_updated",
"description": "Trigger a webhook when a revision tag is updated on an environment.",
"name": "EnvironmentRevisionTagUpdated"
},
{
"value": "environment_tag_created",
"description": "Trigger a webhook when an environment tag is created.",
"name": "EnvironmentTagCreated"
},
{
"value": "environment_tag_deleted",
"description": "Trigger a webhook when an environment tag is deleted.",
"name": "EnvironmentTagDeleted"
},
{
"value": "environment_tag_updated",
"description": "Trigger a webhook when an environment tag is updated.",
"name": "EnvironmentTagUpdated"
},
{
"value": "imported_environment_changed",
"description": "Trigger a webhook when an imported environment has changed.",
"name": "ImportedEnvironmentChanged"
}
]
},
Expand Down Expand Up @@ -857,13 +932,17 @@
"type": "string"
},
"projectName": {
"description": "Name of the project. Only specified if this is a stack webhook.",
"description": "Name of the project. Only specified if this is a stack or environment webhook.",
"type": "string"
},
"stackName": {
"description": "Name of the stack. Only specified if this is a stack webhook.",
"type": "string"
},
"environmentName": {
"description": "Name of the environment. Only specified if this is an environment webhook.",
"type": "string"
},
"format": {
"description": "Format of the webhook payload. Can be either `raw`, `slack`, `ms_teams` or `pulumi_deployments`. Defaults to `raw`.",
"$ref": "#/types/pulumiservice:index:WebhookFormat"
Expand All @@ -874,6 +953,13 @@
"items": {
"$ref": "#/types/pulumiservice:index:WebhookFilters"
}
},
"groups": {
"description": "Optional set of filter groups to apply to the webhook. See [webhook docs](https://www.pulumi.com/docs/intro/pulumi-service/webhooks/#groups) for more information.",
"type": "array",
"items": {
"$ref": "#/types/pulumiservice:index:WebhookGroup"
}
}
},
"required": [
Expand Down Expand Up @@ -907,13 +993,17 @@
"type": "string"
},
"projectName": {
"description": "Name of the project. Only needed if this is a stack webhook.",
"description": "Name of the project. Only specified if this is a stack or environment webhook.",
"type": "string"
},
"stackName": {
"description": "Name of the stack. Only needed if this is a stack webhook.",
"type": "string"
},
"environmentName": {
"description": "Name of the environment. Only specified if this is an environment webhook.",
"type": "string"
},
"format": {
"description": "Format of the webhook payload. Can be either `raw` or `slack`. Defaults to `raw`.",
"$ref": "#/types/pulumiservice:index:WebhookFormat",
Expand All @@ -925,6 +1015,13 @@
"items": {
"$ref": "#/types/pulumiservice:index:WebhookFilters"
}
},
"groups": {
"description": "Optional set of filter groups to apply to the webhook. See [webhook docs](https://www.pulumi.com/docs/intro/pulumi-service/webhooks/#groups) for more information.",
"type": "array",
"items": {
"$ref": "#/types/pulumiservice:index:WebhookGroup"
}
}
},
"requiredInputs": [
Expand Down
Loading

0 comments on commit cde69c6

Please sign in to comment.