I'm looking to set up some alerts from gcloud -> slack, and so far have a test up and running having followed these instructions:
However, ideally I'd store the config for these notifications in a terraform script so that I don't have manual steps to follow if things need setting up again. It looks like this should be possible: https://www.terraform.io/docs/providers/google/r/monitoring_notification_channel.html
I've run gcloud alpha monitoring channel-descriptors describe projects/<My Project>/notificationChannelDescriptors/slack
, which produces the following output for the 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
So, I think my terraform config for the notification channel wants to be:
resource "google_monitoring_notification_channel" "basic" {
display_name = "My slack notifications"
type = "slack"
labels = {
auth_token = "????????"
channel_name = "#notification-channel"
}
}
However, I can't figure out how to obtain the auth token for this script? I can't seem to extract the one I've already set up from Slack or gcloud, and can't find any instructions for creating one from scratch...
N.B. This is not a Terraform-specific issue, because the script is just hooking into the google REST API. So, anyone using the API directly would also have to obtain this auth_token from somewhere. There must be an intended way to obtain it or why is it in the API at all...?
&auth_token=
parameter in the query stringYou will end up with an extra notification channel, i.e. the one you created in the console, but after that you will be able to reuse the auth token in terraform-managed notification channels.