获取Terraform google_monitoring_notification_channel资源的Slack auth_token

Coo*_*ter 7 google-cloud-platform terraform slack stackdriver

我希望从gcloud-> slack设置一些警报,到目前为止,已经按照以下说明进行了测试并正在运行:

https://cloud.google.com/monitoring/support/notification-options?_ga=2.190773474.-879257953.1550134526#slack

但是,理想情况下,我会将这些通知的配置存储在terraform脚本中,这样,如果需要再次设置,则无需遵循手动步骤。看起来这应该可行:https//www.terraform.io/docs/providers/google/r/monitoring_notification_channel.html

我已经运行了gcloud alpha monitoring channel-descriptors describe projects/<My Project>/notificationChannelDescriptors/slack,它会为labels + type产生以下输出:

labels:
- description: A permanent authentication token provided by Slack. This field is obfuscated
    by returning only a few characters of the key when fetched.
  key: auth_token
- description: The Slack channel to which to post notifications.
  key: channel_name
type: slack
Run Code Online (Sandbox Code Playgroud)

因此,我认为通知渠道的Terraform配置希望是:

resource "google_monitoring_notification_channel" "basic" {
  display_name = "My slack notifications"
  type = "slack"
  labels = {
    auth_token = "????????"
    channel_name = "#notification-channel"
  }
}
Run Code Online (Sandbox Code Playgroud)

但是,我不知道如何获取此脚本的身份验证令牌?我似乎无法从Slack gcloud中提取已经设置的代码,也找不到从头开始创建代码的任何说明...

注意:这不是特定于Terraform的问题,因为脚本只是与Google REST API挂钩。因此,任何直接使用API​​的人也必须从某个地方获取此auth_token。必须有一种预期的方式来获取它,或者为什么在API中根本没有它...?

Mat*_*man 12

  1. 访问https://app.google.stackdriver.com/settings/accounts/notifications/slack?project=YOUR_PROJECT_NAME
  2. 选择“添加松弛通道”
  3. 选择“授权 Stackdriver”
  4. 选择“安装”
  5. 您将被重定向回以下表单的 URL:https : //app.google.stackdriver.com/settings/accounts/notifications/slack/add?project=YOUR_PROJECT_NAME&auth_token=AUTH_TOKEN_HERE
  6. 保存通知通道(这似乎是完成 oauth 流程所必需的)
  7. &auth_token=查询字符串中的参数复制/粘贴身份验证令牌

您最终将获得一个额外的通知渠道,即您在控制台中创建的那个,但之后您将能够在 terraform 管理的通知渠道中重用身份验证令牌。

  • 自从 stackdriver 合并到监控中后,这不再起作用。:( (2认同)
  • @Mar0ux 这对我有用。记录 oauth 流的网络活动,然后找到 GET 到“https://slack.com/api/auth.test?token=auth_token” (2认同)