> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kosli.com/llms.txt
> Use this file to discover all available pages before exploring further.

# kosli_action resource

> Manages a Kosli action. Actions define webhook notifications triggered by environment compliance events.

Manages a Kosli action. Actions define webhook notifications triggered by environment compliance events.

> [!NOTE]
>
> Actions are identified internally by a server-assigned `number`. The `name` is used during import to look up the number.

Use this resource to configure automated notifications when environments change compliance state. Actions send webhooks to external services such as Slack or Microsoft Teams.

## Example usage

```terraform theme={"theme":"dracula","languages":{"custom":["/languages/rego.json"]}}
terraform {
  required_providers {
    kosli = {
      source = "kosli-dev/kosli"
    }
  }
}

# Action that fires on non-compliant environment events
resource "kosli_action" "compliance_alerts" {
  name         = "compliance-alerts"
  environments = ["production-k8s"]
  triggers     = ["ON_NON_COMPLIANT_ENV", "ON_COMPLIANT_ENV"]
  webhook_url  = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXX"
}

# Action that fires when a running artifact becomes compliant or non-compliant,
# or gains new provenance (UI: "Artifact changed")
resource "kosli_action" "artifact_changed_alerts" {
  name         = "artifact-changed-alerts"
  environments = ["staging-ecs"]
  triggers     = ["ON_SCALED_ARTIFACT"]
  webhook_url  = "https://outlook.office.com/webhook/XXXX"
}

# Action that fires on artifact lifecycle events in the environment
resource "kosli_action" "artifact_lifecycle_alerts" {
  name         = "artifact-lifecycle-alerts"
  environments = ["staging-ecs"]
  triggers     = ["ON_STARTED_ARTIFACT", "ON_EXITED_ARTIFACT", "ON_ALLOWED_ARTIFACT"]
  webhook_url  = "https://outlook.office.com/webhook/XXXX"
}
```

## Triggers

The `triggers` attribute must contain one or more of the following event types:

| Value | Fires when |
| - | - |
| `ON_STARTED_ARTIFACT` | An artifact starts running in the environment |
| `ON_EXITED_ARTIFACT` | An artifact stops running |
| `ON_SCALED_ARTIFACT` | A running artifact becomes compliant or non-compliant, or gains new provenance (UI: "Artifact changed") |
| `ON_ALLOWED_ARTIFACT` | An artifact is added to the allow-list |
| `ON_COMPLIANT_ENV` | The environment becomes compliant |
| `ON_NON_COMPLIANT_ENV` | The environment becomes non-compliant |

> [!NOTE]
>
> `ON_SCALED_ARTIFACT` keeps its historical name for backwards compatibility. Kosli no longer records scaling events, so this trigger fires on artifact changes.

## Import

Actions can be imported using their name:

```shell theme={"theme":"dracula","languages":{"custom":["/languages/rego.json"]}}
# Import an existing action by name
terraform import kosli_action.compliance_alerts compliance-alerts
```

## Schema

### Required

* `environments` (List of String) List of environment names this action monitors.
* `name` (String) Name of the action. Must be unique within the organization. Changing this will force recreation of the resource.
* `triggers` (List of String) List of trigger event types that activate this action. One or more of `ON_STARTED_ARTIFACT`, `ON_EXITED_ARTIFACT`, `ON_SCALED_ARTIFACT`, `ON_ALLOWED_ARTIFACT`, `ON_COMPLIANT_ENV`, `ON_NON_COMPLIANT_ENV`. See [Triggers](#triggers) for what each one fires on.
* `webhook_url` (String, Sensitive) Webhook URL to send notifications to.

### Read-only

* `created_by` (String) User who created the action.
* `last_modified_at` (Number) Unix timestamp of when the action was last modified.
* `number` (Number) Server-assigned numeric identifier for the action.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.