terraform-provider-google: Slack Notification Channel creation via terraform no longer works
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
- Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
- If you are interested in working on this issue or have submitted a pull request, please leave a comment.
- If an issue is assigned to the
modular-magicianuser, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned tohashibot, a community member has claimed the issue already.
Terraform Version
I’m using v1.1.5
Affected Resource(s)
- google_monitoring_notification_channel
Terraform Configuration Files
resource "google_monitoring_notification_channel" "alert_notification_channel" {
enabled = true
display_name = "test slack alerts"
type = "slack"
labels = {
"channel_name": "#my-channel-name"
}
sensitive_labels {
"auth_token": "xoxb-0000000000-1111111111111-Abbc1defg2HIjkL3MNoPQRs4"
}
Debug Output
google_monitoring_notification_channel.alert_notification_channel["test slack alerts"]: Refreshing state... [id=projects/my-gcp-project/notificationChannels/1231231231231231231]
# google_monitoring_notification_channel.alert_notification_channel["test slack alerts"] has changed
~ resource "google_monitoring_notification_channel" "alert_notification_channel" {
id = "projects/my-gcp-project/notificationChannels/1231231231231231231"
name = "projects/my-gcp-project/notificationChannels/1231231231231231231"
+ user_labels = {}
# (7 unchanged attributes hidden)
# (1 unchanged block hidden)
}
Panic Output
Expected Behavior
When we attach this notification channel to a GCP Monitoring Alert, and the Alert is triggered, an alert message should be sent to the provided slack channel.
Actual Behavior
When an incident arises and the alert happens, no Slack messages are sent.
However, if we create Notification Channels for Pubsub/Pagerduty/etc via Terraform, these all work as expected.
My guess is that this is related to GCP’s update for the creation of Slack notification channels… now, when you create a Slack notification channel in the GCP console, it pulls up a new screen/UI that asks for the slack channel you want to connect to, and auto-generates a connection to the slack channel. If I create a Slack notification channel in the GCP console using this method and attach it to an alarm, the slack messages are sent as-expected when an incident is raised. But, when I send alerts through the Slack notification channel created by terraform, no slack messages are sent when an incident is raised.
Steps to Reproduce
terraform apply- Attach notification channel to a GCP monitoring alert
- Trigger the alert to raise an incident, which should cause a message to be sent to the provided slack channel
Important Factoids
I created a Slack App via https://api.slack.com/apps and installed the app in my Slack workspace. I invited the Slack App bot into the channel we are trying to notify via the Notification Channel. I retrieved the auth_token from Settings -> Install App -> Bot User OAuth Token, and am passing that value to my terraform resource.
I’ve tried creating notification channels linked to various different slack apps and different Slack channels, but none of them will work when spun up with Terraform.
References
Similar to https://github.com/hashicorp/terraform-provider-google/issues/9564 . Seems like Slack notification channels simply don’t work when they are created via terraform.
- b/275101438
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 78
- Comments: 21
I think I found a workaround for this if you want to define it all in terraform:
On the slack side, I created the app, and added the channel.join and chat.write permissions. I also manually installed it in the channel I was targeting after installing it to the workspace. The token is the Bot User OAuth Token from the OAuth and Permissions section.
I’m using version 4.46.0 of the provider.
Hope this helps!
Running into the same problem. As described by @johan-torres-data, the
teamfield seems to be missing. When inspecting requests sent by gcp’s to Slack’s API I see that it tries to send, next to theauth_tokenandchannel_name; theteamname. These are valid API labels, but for some reason Terraform doesn’t acceptteamduring configuration.Hi everyone, same issue here, I tried to create the channel using terraform but it didn’t work, so I created another one from the UI and that one works, the only difference that I noticed is one field called
teamthat in my case is the Slack-workspace name, that label is not available within the “google_monitoring_notification_channel” resource. Each time that I want to set up a new channel Slack asks me to allow Monitoring to have some permissions, not pretty sure if could be related with that. In the next picture, you can see that the first has a team label, that was created by the UI the second one uses terraform.We actually got in touch with responsible team and this is what I heard back
The long term goal is to have full TF parity with console/cli. Lots of working being done at the moment. I have +1 the ticket and will be booking a follow up meeting with the PM to discuss progressSo I hope sometime in near future we would get this done.
Any update regarding this issue? As mentionned above the only solution in order to use the slack channel for me was to copy past in my alert resource the channel name that can be found with the following command:
Can concur here around the Team not being included. Current workaround is super ugly but essentially create the slack alert manually and copy down the notification channel ID which is something like:
"projects/<gcp_project_id>/notificationChannel/<NotificationchannelID>"Also frustrating that you can’t just pass the notification channel name. This “workaround” at the very least gives your created Alerts a working channel to reference in environments that will be stable for a while.Yeah, the issue is resolved after it’s reported internally as well! We should be good at using the following:
Have migrated my workaround to the above in May this year which is working perfectly fine
Another possible (albeit terrifying workaround) is to use slacks feature to send emails to a channel:
It’s not pretty but it works.