Slack

You spend your day in Slack, responding to DM's, talking about production, and now: getting access to resources with Sym.

Overview

It is easy to request access and use your organization's workflow and approval logic via Sym's Slack Integration.

Implementing Slack

Adding Slack to your Sym configuration has two key pieces:

  • Adding the Slack integration to your Terraform config
  • Using Slack in your Python implementation

πŸ‘

SDK Docs

The Slack Integration is defined at sym.sdk.integrations.slack.

Adding Slack to Terraform

To add Slack to your Sym configuration, create a sym_integration and include it in your sym_environment.

resource "sym_environment" "prod" {
  name = "prod"

  integrations = {
    slack_id     = sym_integration.slack.id
    # other integrations
  }
}

resource "sym_integration" "slack" {
  type = "slack"
  name = "prod"

  # your slack workspace id
  external_id = "T012345678"
}

Using Slack in Python

Route a request to a channel

This example returns a Slack channel in the get_approvers reducer of a sym:approval template, which results in a request being sent to a channel.

from sym.sdk.annotations import hook, reducer
from sym.sdk.integrations import slack

@reducer
def get_approvers(evt):
    if evt.payload.fields["urgency"] == "High":
        # This is a self-approval in a channel
        return slack.channel("#break-glass", allow_self=True)
    return slack.channel("#ops")

Route a request to a DM

This example uses the PagerDuty Integration to selectively DM a Slack user.

from sym.sdk.annotations import hook, reducer
from sym.sdk.integrations import pagerduty, slack

@reducer
def get_approvers(evt):
    # The `pagerduty` import uses the creds from the TF integration.
    # It knows how to take in a sym.User & check if that User is 
    # on call for a given schedule.
    if pagerduty.is_on_call(evt.user, escalation_policy_name="sre"):
        # This is a self-approval in a DM
        return slack.user(evt.user)

Route a request to a group DM

This example returns a group of users to DM with an access request.

🚧

Slack's conversations.open endpoint for direct messages accepts up to 8 users.

from sym.sdk.annotations import hook, reducer
from sym.sdk.integrations import pagerduty, slack

@reducer
def get_approvers(evt):
    on_call_mgrs = pagerduty.users_on_call(schedule_id="PXUGCWM")
    return slack.group([u for u in on_call_mgrs][:7])

Did this page help you?