0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GCP Error ReportingをSlack連携する

Last updated at Posted at 2024-12-02

やりたいこと

GCP Error Reportingが便利なのでSlackに連携する

Slack App作成

https://api.slack.com/apps/ からSlack Appを作成

OAuth & Permissions からScopeは以下のように設定

Screenshot 2024-12-02 at 9.21.22.png

Install App からインストールする

Bot User OAuth Token が取得できる。(例. xoxb-11111111-xxxxxxxx)

GCP Secret Managerの設定

上で取得したBot User OAuth TokenをSecret Managerに設定する

resource "google_secret_manager_secret" "slack_bot_token_gcp" {
  secret_id = "slack-bot-token-gcp"
  replication {
    auto {}
  }
}

secret manager versionに値を追加 (Console 上 or gcloud)

echo -n "xoxb-xxxxxxx" | gcloud secrets versions add slack-bot-token-gcp --data-file=- --project <project>

notification channelの設定

data "google_secret_manager_secret_version" "slack_bot_token_gcp" {
  secret = "slack-bot-token-gcp"
}

resource "google_monitoring_notification_channel" "slack_proj_internal_system" {
  display_name = "slack-proj-internal-system"
  type         = "slack"
  labels = {
    "channel_name" = "#proj-internal-system" # you can set your own slack channel name
  }

  sensitive_labels {
    auth_token = data.google_secret_manager_secret_version.slack_bot_token_gcp.secret_data
  }
}

GCPのError Reporting を連携

terraform でのError Reportingとの連携はサポートされてないようなので、手動で設定。

Screenshot 2024-12-02 at 9.47.44.png

Slack通知

Screenshot 2024-12-03 at 10.31.23.png

通知が来るようになる!

Ref

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?