Google cloud platform 获取Terraform google\u monitoring\u notification\u通道资源的Slack auth\u令牌
我希望从gcloud->slack设置一些警报,到目前为止,我已经按照以下说明启动并运行了一个测试: 然而,理想情况下,我会将这些通知的配置存储在一个terraform脚本中,这样,如果需要再次设置,我就不需要手动执行步骤。看起来这应该是可能的: 我已经运行了Google cloud platform 获取Terraform google\u monitoring\u notification\u通道资源的Slack auth\u令牌,google-cloud-platform,terraform,slack,stackdriver,Google Cloud Platform,Terraform,Slack,Stackdriver,我希望从gcloud->slack设置一些警报,到目前为止,我已经按照以下说明启动并运行了一个测试: 然而,理想情况下,我会将这些通知的配置存储在一个terraform脚本中,这样,如果需要再次设置,我就不需要手动执行步骤。看起来这应该是可能的: 我已经运行了gcloud alpha monitoring channel descriptor descriptor projects//notificationchanneldescriptor/slack,它为labels+类型生成以下输出:
gcloud alpha monitoring channel descriptor descriptor projects//notificationchanneldescriptor/slack
,它为labels+类型生成以下输出:
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
因此,我认为通知通道的地形配置应该是:
resource "google_monitoring_notification_channel" "basic" {
display_name = "My slack notifications"
type = "slack"
labels = {
auth_token = "????????"
channel_name = "#notification-channel"
}
}
但是,我不知道如何获取此脚本的身份验证令牌?我似乎无法从Slack或gcloud中提取我已经设置的,也找不到任何从头创建的说明
注意:这是而不是特定于地形的问题,因为脚本只是挂接到google REST API。因此,任何直接使用API的人也必须从某个地方获得这个auth_令牌。必须有一个预定的方法来获得它,或者为什么它会出现在API中
&auth\u token=
参数复制/粘贴auth令牌您将得到一个额外的通知通道,即您在控制台中创建的通知通道,但在此之后,您将能够在terraform管理的通知通道中重用auth令牌。包含auth令牌的URL不再是我们重定向到的最终URL。要查找身份验证令牌,请打开浏览器的网络监视器并按照上述步骤操作。在整个过程中发出的请求列表中,您会发现其中一个请求包含身份验证令牌。您可以在之后删除额外的通知通道,该令牌将继续工作。自从stackdriver被合并到监视中以来,这不再起作用(@Rose)您希望将令牌放入GCP机密中,并在此处引用它。与terraform中的其他敏感值一样,它不应出现在源代码中,但可能会出现在您的状态文件中。相应地,请确保状态安全。@Mar0ux它对我有效。记录oauth流的网络活动,然后找到“获取”路径