# Configure Slack notifications for backup events

## Step 1: Create a Slack app

Go to [Slack API apps](https://api.slack.com/apps) and create a new Slack app connected to the Oslo kommune workspace. You can choose any name you prefer.

<figure markdown="span">
![Create a Slack app](../images/backup/app-name.png)
</figure>

## Step 2: Create an incoming Slack webhook

Under **Features** > **Incoming Webhooks** activate the toggle incoming webhooks.

<figure markdown="span">
![Activate incoming webhooks](../images/backup/inc-webhook.png){ width="900" }
</figure>

Create a new webhook attached to a channel of your choice. Select **Add New Webhook to Workspace** and select a channel to receive backup notifications in.

<figure markdown="span">
![Create an incoming webhook](../images/backup/inc-webhook-act.png){ width="900" }
</figure>

Copy the webhook URL to the clipboard.

<!-- ![Chose a channel](../images/backup/create-webhook.png) -->

## Step 3: Set webhook URL in AWS console

In the AWS console, **Systems manager** > **Parameter Store** find the SSM Parameter `/${local.environment}/slack/webhook/backup`. Add the webhook URL from the previous step to this parameter.

## Step 4: Configure Slack app name and channel

In your Terraform IaC configuration, locate the file `config_override.tf`.

Create two new locals as follows:

```tf title="repo-iac/environments/dev/backup/config_override.tf"
locals{
    ...
    ################################################################################
    # Slack notifications
    ################################################################################
    slack_username = "reporter"
    slack_channel  = "temp-aws-root-alerts" # (1)!
    ...
}
```

1. Use the same Slack channel you selected in Step #2.

Adjust Slack username and Slack channel to suit your needs.

## Step 5: Enable Slack notifications

Edit `package-config.yml` and enable `NotifySlack`:

```yaml title="repo-iac/environments/dev/backup/package-config.yml"
NotifySlack:
  Enable: true
```

## Step 6: Update the `backup` stack and apply

Update the `backup` stack using the new configuration:

```bash title="repo-iac/environments/dev/backup/"
ok pkg install
```

Initialize Terraform and apply the configuration:

```bash title="repo-iac/environments/dev/backup/"
terraform init
terraform apply
```

## Step 7: Verify Slack notifications

Next time a backup runs a message should be posted to your channel.

```markdown
✅ An AWS Backup job was completed successfully
Resource ARN
`arn:aws:rds:eu-west-1:1234567890:cluster:pirates-dev-main`
Recovery point ARN
`arn:aws:rds:eu-west-1:1234567890:cluster-snapshot:awsbackup:job-e09f3a12-9239-7e82-041b-db378838f32e`
```

<!-- prettier-ignore-start -->
!!! Tip
    By default you are notified of successful and failed jobs. You can further filter notifications by overriding the `backup_vault_events` input for the `aws_backup` module.
<!-- prettier-ignore-end -->

## Next steps

After 24 hours, follow the guide for [enabling immutable backups](enable-immutable-backups.md) to verify that the backup is working as expected, and
enable immutable backups.
