[アップデート] User Notifications が Terraform AWS Provider v5.99.0 でサポートされ、デプロイできるようになりました

[アップデート] User Notifications が Terraform AWS Provider v5.99.0 でサポートされ、デプロイできるようになりました

Clock Icon2025.06.07

こんにちは!クラウド事業本部コンサルティング部のたかくに(@takakuni_)です。

AWS Provider v5.99.0 で User Notifications がデプロイできるようになりました。

https://github.com/hashicorp/terraform-provider-aws/blob/main/CHANGELOG.md

CloudFormation では 2025年 1 月 17 日にリリースされていましたが、ついに AWS Provider でもサポートされて嬉しいですね。

https://dev.classmethod.jp/articles/user-notifications-ga-cloudformation/

というわけで今回は、AWS Provider で User Notifications をデプロイしてみたいと思います。

アップデート内容

今回、サポートしたリソースは以下の 5 つです。結構多いですね。

  • aws_notifications_channel_association
  • aws_notifications_event_rule
  • aws_notifications_notification_configuration
  • aws_notifications_notification_hub
  • aws_notificationscontacts_email_contact

Mermaid で表すと次の依存関係になります。

aws_notifications_notification_configuration

まず初めに aws_notifications_notification_configuration です。これはマネジメントコンソールで言う、通知設定にあたります。

通知設定は User Notifications で一番大きい構成要素の 1 つです。

通知設定の中にイベント設定やチャンネル設定を組み立てていきます。aggregation_duration で集約期間を設定でき、重複した通知を排除できます。

resource "aws_notifications_notification_configuration" "this" {
  name                 = "takakuni"
  description          = "Example notification configuration"
  aggregation_duration = "SHORT"

  tags = {
    Environment = "production"
    Project     = "takakuni"
  }
}

Resource: aws_notifications_notification_configuration

aws_notifications_notification_hub

続いて aws_notifications_notification_hub です。これは User Notifications に送信された通知を別リージョンに複製する仕組みです。

https://docs.aws.amazon.com/ja_jp/notifications/latest/userguide/nhr-add-remove.html

デフォルトでは、バージニアリージョンに複製されるようです。

Notification hubs only set the Regional boundaries of notifications. User Notifications stores the notification configuration's data in the default Region, US East (N. Virginia). This data is also stored in individual Regions that you have configured rules for. For example, say that you create a configuration that receives Amazon CloudWatch Alarm notifications about events in Europe (Milan) and Europe (Frankfurt). User Notifications creates the notification configuration in US East (N. Virginia). It then replicates the configuration to Europe (Milan) and Europe (Frankfurt).

https://docs.aws.amazon.com/ja_jp/notifications/latest/userguide/notification-hubs.html

私の場合は東京リージョンに設定してみました。

resource "aws_notifications_notification_hub" "this" {
  notification_hub_region = "ap-northeast-1"
}

Resource: aws_notifications_notification_hub

aws_notifications_event_rule

aws_notifications_event_rule は通知設定に組み込む、EventBridge の Rule を指定します。私の場合は AWS Health のイベントを取得したかったため、バックアップリージョンを意識しながら、以下で設定しました。

resource "aws_notifications_event_rule" "this" {
  event_pattern = jsonencode({
    detail = {
      "eventRegion" = ["ap-northeast-1", "us-east-1", "global"]
    }
  })
  event_type                     = "AWS Health Event"
  notification_configuration_arn = aws_notifications_notification_configuration.this.arn
  regions                        = ["ap-northeast-1", "us-east-1", "us-west-2"]
  source                         = "aws.health"
}

Resource: aws_notifications_event_rule

aws_notificationscontacts_email_contact

aws_notificationscontacts_email_contact は配信チャネルで設定する、メールアドレスのリソースです。配信チャネルではメール、モバイルデバイス、チャットチャネルの 3 つのエンドポイントをサポートしますが、現状はメールのみ AWS Provider で設定できるようでした。

email_address は設定したいメールアドレスを指定しましょう。

resource "aws_notificationscontacts_email_contact" "this" {
  name          = "Shinnosuke Takakuni"
  email_address = ""
}

aws_notificationscontacts_email_contact

aws_notifications_channel_association

最後に aws_notifications_channel_association です。通知設定と配信チャネルの紐付けです。とくに意識するものはなくシンプルですね。

resource "aws_notifications_channel_association" "this" {
  arn                            = aws_notificationscontacts_email_contact.this.arn
  notification_configuration_arn = aws_notifications_notification_configuration.this.arn
}

aws_notifications_channel_association

リソースを確認してみる

terraform apply で作成したリソースを確認してみます。まずはメールボックスに届いている認証メールを承諾します。

配信設定です。イベントルールおよび、配信チャネルもうまく作成できているようですね。

2025-06-07 at 20.31.10-takakuni  AWS User Notifications  Global.png

まとめ

以上、「AWS Provider v5.99.0 で User Notifications がサポートされました。」でした。

メールアドレス向けに通知内容を整形しなくて良いので、私はよく使っていますが、AWS Providerサポートしてなかったため、コンソールで構築していた民です。嬉しいですね。

参考になれば幸いです!クラウド事業本部コンサルティング部のたかくに(@takakuni_)でした!

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.