为 Terraform google_monitoring_notification_channel 资源获取 Slack auth_token
Obtain Slack auth_token for Terraform google_monitoring_notification_channel resource
我正在寻找从 gcloud -> slack 设置一些警报,到目前为止已经进行了测试并且 运行ning 已遵循以下说明:
但是,理想情况下,我会将这些通知的配置存储在 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:
- 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
所以,我想我的通知通道的 terraform 配置应该是:
resource "google_monitoring_notification_channel" "basic" {
display_name = "My slack notifications"
type = "slack"
labels = {
auth_token = "????????"
channel_name = "#notification-channel"
}
}
但是,我不知道如何获取此脚本的授权令牌?我似乎无法从 Slack 或 gcloud 中提取我已经设置的那个,也找不到从头开始创建一个的任何说明...
N.B。这 不是 特定于 Terraform 的问题,因为脚本只是挂接到 google REST API。因此,任何直接使用 API 的人都必须从某个地方获得此 auth_token。必须有一种预期的方式来获得它,或者为什么它在 API 中...?
- 访问https://app.google.stackdriver.com/settings/accounts/notifications/slack?project=YOUR_PROJECT_NAME
- Select "Add Slack Channel"
- Select "Authorize Stackdriver"
- Select "Install"
- 您将被重定向回以下形式的 URL:https://app.google.stackdriver.com/settings/accounts/notifications/slack/add?project=YOUR_PROJECT_NAME&auth_token=AUTH_TOKEN_HERE
- 保存 通知渠道(这似乎是完成 oauth 流程所必需的)
- Copy/paste 来自查询字符串中
&auth_token=
参数的身份验证令牌
您最终会得到一个额外的通知渠道,即您在控制台中创建的渠道,但之后您将能够在 terraform-managed 个通知渠道中重复使用授权令牌。
一个技巧是创建您自己的 Slack 应用程序并使用其 oauth-token。如果你知道怎么做的话,相当简单。在我自己研究这个问题时,我发现这个很棒的博客 post 解释了它 https://bradtho.github.io/technology/gcp-alerting/
或者,您可以设置默认的 Google 云监控集成并在单击“发送测试通知”时检查网络调用。 POST 负载包含令牌。
我正在寻找从 gcloud -> slack 设置一些警报,到目前为止已经进行了测试并且 运行ning 已遵循以下说明:
但是,理想情况下,我会将这些通知的配置存储在 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:
- 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
所以,我想我的通知通道的 terraform 配置应该是:
resource "google_monitoring_notification_channel" "basic" {
display_name = "My slack notifications"
type = "slack"
labels = {
auth_token = "????????"
channel_name = "#notification-channel"
}
}
但是,我不知道如何获取此脚本的授权令牌?我似乎无法从 Slack 或 gcloud 中提取我已经设置的那个,也找不到从头开始创建一个的任何说明...
N.B。这 不是 特定于 Terraform 的问题,因为脚本只是挂接到 google REST API。因此,任何直接使用 API 的人都必须从某个地方获得此 auth_token。必须有一种预期的方式来获得它,或者为什么它在 API 中...?
- 访问https://app.google.stackdriver.com/settings/accounts/notifications/slack?project=YOUR_PROJECT_NAME
- Select "Add Slack Channel"
- Select "Authorize Stackdriver"
- Select "Install"
- 您将被重定向回以下形式的 URL:https://app.google.stackdriver.com/settings/accounts/notifications/slack/add?project=YOUR_PROJECT_NAME&auth_token=AUTH_TOKEN_HERE
- 保存 通知渠道(这似乎是完成 oauth 流程所必需的)
- Copy/paste 来自查询字符串中
&auth_token=
参数的身份验证令牌
您最终会得到一个额外的通知渠道,即您在控制台中创建的渠道,但之后您将能够在 terraform-managed 个通知渠道中重复使用授权令牌。
一个技巧是创建您自己的 Slack 应用程序并使用其 oauth-token。如果你知道怎么做的话,相当简单。在我自己研究这个问题时,我发现这个很棒的博客 post 解释了它 https://bradtho.github.io/technology/gcp-alerting/
或者,您可以设置默认的 Google 云监控集成并在单击“发送测试通知”时检查网络调用。 POST 负载包含令牌。