如何使用Terraform在Google Cloud平台上创建Slack通知频道

4

我正在尝试使用Terraform在GCP中创建Slack通知频道。 我能够使用以下代码创建一个频道,但是它缺少“团队”和“所有者”属性。

resource "google_monitoring_notification_channel" "default" {
  display_name = "Test Slack Channel"
  type         = "slack"
  enabled      = "true"
  labels = {
    "channel_name" = "#testing"
    "auth_token"   = "<my_slack_app_token>"
  }
}


下图中的第一个频道是通过 GUI 创建的,工作正常。第二个频道是通过 terraform 创建的,无法发送通知: Slack channels Terraform仓库未提及这些属性,我尝试在channel_name之后的labels中定义它们。
labels = {
  "channel_name" = "#testing"
  "team"         = "<my_team>"
  "owner"        = "google_cloud_monitoring"
  "auth_token"   = "<my_slack_app_token>"
}

我遇到了以下错误:

Error creating NotificationChannel: googleapi: Error 400: Field "notification_channel.labels['owner']" is not allowed; labels must conform to the channel type's descriptor; permissible label keys for "slack" are: {"auth_token", "channel_name"}

显然,只有 channel_nameauth_token 是有效的标签。

我错过了什么吗?


嗨,@Miro K,我想更好地了解您想要如何使用“Team”和“Owner”属性。您能否分享一下您正在使用这些属性的代码?哪个错误显示? - Marlen Monroy
嗨@MarlenMonroy,我已经添加了一个“team”和“owner”标签的示例代码,因为我尝试使用它们,下面是我得到的错误。 - Miro K
嗨@MiroK,随意使用GUI的截图来丰富问题,显示teamowner字段应该对于google_monitoring_notification_channel资源类型有效。 - Bernard Halas
1
嗨,我复制了你的场景并注意到与你提到的一样的性能问题,但不幸的是,ownerteam的值不在Google API中,因此在这种情况下最好的渠道是直接在terraform中开启一个案例。 - Marlen Monroy
1
@Meuko,GCP API中缺少团队和所有者选项,我已经提出了一个问题(https://issuetracker.google.com/issues/184556867?pli=1),但它仍未解决。 - Miro K
显示剩余2条评论
1个回答

0

Slack需要为令牌添加sensitive_lables选项。在文档中有一个示例。

resource "google_monitoring_notification_channel" "default" {
  display_name = "Test Slack Channel"
  type         = "slack"
  labels = {
    "channel_name" = "#foobar"
  }
  sensitive_labels {
    auth_token = "...."
  }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接