Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into port-7361
Browse files Browse the repository at this point in the history
  • Loading branch information
lord-sarcastic committed Jun 20, 2024
2 parents c50dfa4 + 1bafe10 commit c4e309d
Show file tree
Hide file tree
Showing 233 changed files with 62,267 additions and 10,937 deletions.
1 change: 0 additions & 1 deletion archive/self-service-actions/self-service-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ In Port, you can make your Software Catalog active by defining Self-Service Acti
Port enables developer Self-Service in 2 distinct ways:

- [Self-Service Actions](./self-service-actions-deep-dive/self-service-actions-deep-dive.md) - configure **Create** and **Delete** actions to provision and control the resource usage in your organization. Configure **Day-2 Operations** to keep your infrastructure up-to-date.
- [Real-time Changelog](./kafka/examples/changelog-basic-change-listener-using-aws-lambda.md) - every change that occurs in Port generates a new audit log entry.

## Getting started

Expand Down
2 changes: 1 addition & 1 deletion docs/__quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -1281,4 +1281,4 @@ If you want to learn more about Port's capabilities in a specific area, you can
If you want to continue utilizing Port's REST API, take a look at these resources:

- [API guide](./build-your-software-catalog/custom-integration/api/api.md)
- [API Reference](./api-reference/api-reference.mdx)
- [API Reference](./api-reference/port-api)
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Self-service actions are created and managed in the [Self-service](https://app.g
To begin, click on the `+ New Action` button in the top right corner, then follow the steps below.

:::tip Other supported methods
Besides Port's UI, you can also create and manage self-service actions using [Port's API](https://api.getport.io/static/index.html#/Actions), or [Terraform](https://registry.terraform.io/providers/port-labs/port-labs/latest/docs/resources/port_action).
Besides Port's UI, you can also create and manage self-service actions using [Port's API](/api-reference/port-api), or [Terraform](https://registry.terraform.io/providers/port-labs/port-labs/latest/docs/resources/port_action).
:::

### Step 1 - setup the action's frontend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import TabItem from "@theme/TabItem"

# Entity

Entity is an input type used to reference existing [entities](/build-your-software-catalog/sync-data-to-catalog/sync-data-to-catalog.md#creating-entities) from the software catalog when triggering actions.
Entity is an input type used to reference existing [entities](/build-your-software-catalog/sync-data-to-catalog/sync-data-to-catalog.md#entities) from the software catalog when triggering actions.

## 💡 Common entity usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Automations are defined in JSON format. The JSON structure looks like this:
"type": "automation",
"event": {
"type": "event_type",
"blueprintIdentifier": "blueprint_id",
"blueprintIdentifier": "blueprint_id"
},
"condition": {
"type": "JQ",
Expand Down Expand Up @@ -79,4 +79,8 @@ Automations are defined in the [Automations page](https://app.getport.io/setting
* Setup the [trigger](/actions-and-automations/define-automations/setup-trigger).
* Define the [action](/actions-and-automations/define-automations/setup-action) that will be executed when the trigger event occurs.

3. Make sure to set the `publish` field to `true` if you want to enable the automation. When finished, click `Save`.
3. Make sure to set the `publish` field to `true` if you want to enable the automation. When finished, click `Save`.

## Examples

See some examples of automation definitions [here](/actions-and-automations/define-automations/examples).
205 changes: 205 additions & 0 deletions docs/actions-and-automations/define-automations/examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
---
sidebar_position: 3
title: Examples
---

import SlackTeamsMessagingWebhook from "/docs/actions-and-automations/define-automations/templates/_slack_teams_webhook_setup_instructions.mdx"

# Examples

This section provides examples of automation definitions in Port.

## Send a Slack/Teams message when a service becomes unhealthy

### Automation definition

By using the `ENTITY_UPDATED` trigger type, we can run custom logic whenever an entity of a specific type is updated.

For example, the following definition will cause a message to be sent whenever a `service` entity's `status` property becomes `Unhealthy`:

```json showLineNumbers
{
"identifier": "serviceUnHealthy",
"title": "Service Health Changed",
"trigger": {
"type": "automation",
"event": {
"type": "ENTITY_UPDATED",
"blueprintIdentifier": "service"
},
// The condition below checks the service's status property after the update
// The automation will only run for services whose status becomes "Unhealthy"
"condition": {
"type": "JQ",
"expressions": [
".diff.after.properties.status == \"Unhealthy\""
],
"combinator": "and"
}
},
"invocationMethod": {
"type": "GITHUB",
"org": "github-org-name",
"repo": "github-repo-name",
"workflow": "slack-teams-notify-unhealthy-service.yaml",
// workflowInputs is the payload to be passed to the GitHub workflow upon every execution
// In this example, we pass the updated service's identifier
"workflowInputs": {
"service_name": "{{ .event.context.entityIdentifier }}"
},
"reportWorkflowStatus": true
},
"publish": true
}
```

### Backend - GitHub workflow

The `slack-teams-notify-unhealthy-service.yaml` workflow will contain the logic to send a Slack/Teams message.

<SlackTeamsMessagingWebhook/>

```yaml showLineNumbers title="slack-teams-notify-unhealthy-service.yaml"
name: Notify when service becomes unhealthy

on:
workflow_dispatch:
inputs:
# Note that the input is the same as the payload (workflowInputs) defined in the automation
service_name:
description: "The unhealthy service's name"
required: true
type: string

jobs:
send_message:
runs-on: ubuntu-latest
steps:
- name: Send message to Slack
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":"The service ${{ inputs.service_name }} has become unhealthy."}' $SLACK_WEBHOOK_URL
- name: Send message to Microsoft Teams
env:
TEAMS_WEBHOOK_URL: ${{ secrets.TEAMS_WEBHOOK_URL }}
run: |
curl -H 'Content-Type: application/json' -d '{"text": "The service ${{ inputs.service_name }} has become unhealthy."}' $TEAMS_WEBHOOK_URL
```
---
## Terminate an ephemeral environment when its TTL is expired
### Automation definition
By using the `TIMER_PROPERTY_EXPIRED` trigger type, we can run custom logic whenever a [timer property](/build-your-software-catalog/customize-integrations/configure-data-model/setup-blueprint/properties/timer) expires.

The following definition will cause a webhook to be triggered whenever the `ttl` property expires on an `environment` entity:

```json showLineNumbers
{
"identifier": "ttlEphemeralEnvironment",
"title": "Terminate ephemeral environment",
"trigger": {
"type": "automation",
"event": {
"type": "TIMER_PROPERTY_EXPIRED",
"blueprintIdentifier": "environment",
"propertyIdentifier": "ttl"
}
},
"invocationMethod": {
"type": "WEBHOOK",
"url": "https://myWebhookUrl.com",
// Under "body" we specify the payload to be passed to the webhook upon every execution
// In this example, we pass the id of the entity whose TTL has expired and the run id
"body": {
"entityId": "{{ .event.context.entityIdentifier }}",
"runId": "{{ .run.id }}"
},
},
"publish": true
}
```

### Backend - Webhook

Since the webhook implementation is entirely up to you, it can be used to terminate the environment, clean up resources, send a notification to the relevant team, and anything else that you want to happen as part of the termination process.
The run id can be used to [interact with the execution in Port](/actions-and-automations/reflect-action-progress/) - send log messages and/or update the execution's status.

---

## Send a Slack/Teams message when a TTL expires

### Automation definition

By using the `TIMER_PROPERTY_EXPIRED` trigger type, we can run custom logic whenever a [timer property](/build-your-software-catalog/customize-integrations/configure-data-model/setup-blueprint/properties/timer) expires.

The following definition will cause a GitHub workflow to be triggered whenever the `ttl` property expires on a `service` entity:

```json showLineNumbers
{
"identifier": "ttlExpiresSendMessage",
"title": "Send a message when TTL expires",
"trigger": {
"type": "automation",
"event": {
"type": "TIMER_PROPERTY_EXPIRED",
"blueprintIdentifier": "Service",
"propertyIdentifier": "ttl"
}
},
"invocationMethod": {
"type": "GITHUB",
"org": "github-org-name",
"repo": "github-repo-name",
"workflow": "slack-teams-notify-ttl-expired.yaml",
// workflowInputs is the payload to be passed to the GitHub workflow upon every execution
// In this example, we pass the identifier of the service whose ttl expired
"workflowInputs": {
"service_name": "{{ .event.context.entityIdentifier }}"
},
"reportWorkflowStatus": true
},
"publish": true
}
```

### Backend - GitHub workflow

The `slack-teams-notify-ttl-expired.yaml` workflow will contain the logic to send a Slack/Teams message.

<SlackTeamsMessagingWebhook/>

```yaml showLineNumbers title="slack-teams-notify-ttl-expired.yaml"
name: Notify when a service's TTL expires
on:
workflow_dispatch:
inputs:
# Note that the input is the same as the payload (workflowInputs) defined in the automation
service_name:
description: "The service's name"
required: true
type: string
jobs:
send_message:
runs-on: ubuntu-latest
steps:
- name: Send message to Slack
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":"The TTL property of service ${{ inputs.service_name }} has expired."}' $SLACK_WEBHOOK_URL
- name: Send message to Microsoft Teams
env:
TEAMS_WEBHOOK_URL: ${{ secrets.TEAMS_WEBHOOK_URL }}
run: |
curl -H 'Content-Type: application/json' -d '{"text": "The TTL property of service ${{ inputs.service_name }} has expired."}' $TEAMS_WEBHOOK_URL
```

---
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The action is defined under the `invocationMethod` key in the automation's JSON
"type": "automation",
"event": {
"type": "event_type",
"blueprintIdentifier": "blueprint_id",
"blueprintIdentifier": "blueprint_id"
},
"condition": {
"type": "JQ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ An automation's trigger is defined under the `trigger` key:
"type": "automation",
"event": {
"type": "event_type",
"blueprintIdentifier": "blueprint_id",
"blueprintIdentifier": "blueprint_id"
},
"condition": {
"type": "JQ",
Expand All @@ -61,7 +61,7 @@ The table below describes the fields in the JSON structure under the `trigger` k
| **`event`** | An object containing data about the event that triggers the automation. |
| **`event.type`** | The [trigger event type](/actions-and-automations/define-automations/setup-trigger#available-triggers). |
| **`event.blueprintIdentifier`** | The identifier of the blueprint whose entities will trigger the automation. |
| `condition` | An optional object containing `jq` expressions used to determine which entities the automation will be triggered for. See [Conditions](/actions-and-automations/create-self-service-experiences/setup-ui-for-action/#conditions) for more information. |
| `condition` | An optional object containing `jq` expressions used to determine which entities the automation will be triggered for. |
| `condition.type` | The type of condition. Should be set to `JQ`. |
| `condition.expressions` | An array of expressions used to filter the entities for which the automation will be triggered. |
| `condition.combinator` | The combinator used to combine the expressions. Should be set to `and` or `or`. |
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
:::info Prerequisite - set up messaging webhooks
The workflow requires a Slack webhook URL and/or a Microsoft Teams webhook URL to send the message.

**Slack**:
1. To set up a Slack webhook, follow the instructions [here](https://api.slack.com/messaging/webhooks).
2. Once you have the webhook URL, add it as a secret in your GitHub repository named `SLACK_WEBHOOK_URL`.

**Microsoft Teams**:
1. To set up a Microsoft Teams webhook, follow the instructions [here](https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook).
2. Once you have the webhook URL, add it as a secret in your GitHub repository named `TEAMS_WEBHOOK_URL`.
:::
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ sidebar_position: 3
---

import PortTooltip from "/src/components/tooltip/tooltip.jsx";
import PortApiRegionTip from "/docs/generalTemplates/_port_region_parameter_explanation_template.md"

# Create Azure Resource with Terraform

Expand Down Expand Up @@ -181,6 +182,7 @@ provider "azurerm" {
provider "port" {
client_id = var.port_client_id
secret = var.port_client_secret
base_url = var.base_url
}
resource "azurerm_storage_account" "storage_account" {
Expand Down Expand Up @@ -253,8 +255,15 @@ variable "port_client_secret" {
type = string
description = "The Port client secret"
}
variable "base_url" {
type = string
description = "The Port API URL"
}
```

<PortApiRegionTip/>

</details>

<details>
Expand All @@ -268,7 +277,7 @@ output "endpoint_url" {

</details>

5. Create an Azure pipeline:
1. Create an Azure pipeline:

<details>

Expand Down Expand Up @@ -313,6 +322,7 @@ jobs:
sudo apt-get install -y jq
displayName: Install jq
# The API call below uses the EU region. To use the US region, replace `api.getport.io` with `api.us.getport.io`
- script: |
accessToken=$(curl -X POST \
-H 'Content-Type: application/json' \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ jobs:
provision-ec2:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '14'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Create a log message (apply)
if: ${{ github.event.inputs.action == 'apply' }}
Expand Down
Loading

0 comments on commit c4e309d

Please sign in to comment.