Deploy Topic with AOM Alarm Notification
Application Scenario
Simple Message Notification (SMN) is a reliable and scalable message notification service provided by Huawei Cloud, supporting multiple message notification methods including email, SMS, HTTP/HTTPS, etc. Application Operations Management (AOM) is a one-stop application operations management platform provided by Huawei Cloud, supporting application monitoring, log management, alarm management, and other functions. By configuring AOM alarm notifications to SMN topics, automatic push of alarm messages can be achieved. At the same time, by configuring SMN log tanks, operation logs of SMN topics can be stored in Log Tank Service (LTS), achieving unified log management and analysis. This best practice introduces how to use Terraform to automatically deploy topics with AOM alarm notifications, including creating SMN topics, LTS log groups and streams, SMN log tank configuration, and AOM alarm action rule configuration.
Related Resources/Data Sources
This best practice involves the following main resources and data sources:
Resources
Resource/Data Source Dependencies
huaweicloud_smn_topic
├── huaweicloud_smn_logtank
└── huaweicloud_aom_alarm_action_rule
huaweicloud_lts_group
└── huaweicloud_lts_stream
└── huaweicloud_smn_logtankNote: SMN log tanks depend on SMN topics and LTS log streams, used to store operation logs of SMN topics to LTS. AOM alarm action rules depend on SMN topics, used to configure the sending target of alarm notifications.
Operation Steps
1. Script Preparation
Prepare the TF file (such as main.tf) for writing the current best practice script in the specified workspace, ensuring that it (or other TF files in the same directory) contains the provider version declaration and Huawei Cloud authentication information required for deploying resources. For configuration details, refer to the introduction in Preparation Before Deploying Huawei Cloud Resources.
2. Create SMN Topic
Add the following script to the TF file (such as main.tf) to create an SMN topic:
Parameter Description:
name: Topic name, assigned by referencing the input variable
smn_topic_nameenterprise_project_id: Enterprise project ID, assigned by referencing the input variable
enterprise_project_id, optional parameter
3. Create LTS Log Group and Log Stream
Add the following script to the TF file (such as main.tf) to create LTS log group and log stream:
Parameter Description:
group_name: Log group name, assigned by referencing the input variable
lts_group_namettl_in_days: Log group TTL (days), assigned by referencing the input variable
lts_group_ttl_in_days, default is 30 daysstream_name: Log stream name, assigned by referencing the input variable
lts_stream_namegroup_id: Log group ID, assigned by referencing the LTS log group resource ID
Note: Log streams must belong to a log group, so the log group needs to be created first. The log group TTL is used to set the log retention time.
4. Configure SMN Log Tank
Add the following script to the TF file (such as main.tf) to configure SMN log tank:
Parameter Description:
topic_urn: Topic URN, assigned by referencing the SMN topic resource
topic_urnlog_group_id: Log group ID, assigned by referencing the LTS log group resource ID
log_stream_id: Log stream ID, assigned by referencing the LTS log stream resource ID
Note: SMN log tanks are used to store operation logs of SMN topics to LTS, achieving unified log management and analysis.
5. Configure AOM Alarm Action Rule
Add the following script to the TF file (such as main.tf) to configure AOM alarm action rule:
Parameter Description:
name: Alarm action rule name, assigned by referencing the input variable
alarm_action_rule_nameuser_name: User name, assigned by referencing the input variable
alarm_action_rule_user_nametype: Rule type, assigned by referencing the input variable
alarm_action_rule_type, default is1(notification type)notification_template: Notification template, set to
aom.built-in.template.zhindicates using AOM built-in Chinese templatedescription: Rule description, assigned by referencing the input variable
alarm_action_rule_description, optional parametersmn_topics: SMN topic configuration, assigned by referencing the SMN topic resource
topic_urn, used to specify the sending target of alarm notifications
Note: AOM alarm action rules are used to configure the sending method of alarm notifications. By configuring SMN topics, automatic push of alarm messages can be achieved. Notification templates can choose built-in templates or custom templates.
6. Preset Input Parameters Required for Resource Deployment (Optional)
In this practice, some resources and data sources use input variables to assign configuration content. These input parameters need to be manually entered during subsequent deployment. Terraform also provides a method to preset these configurations through tfvars files, which can avoid repeated input each time.
Create a terraform.tfvars file in the working directory with the following example content:
Usage:
Save the above content as a
terraform.tfvarsfile in the working directory (this filename allows Terraform to automatically import the variable values in thistfvarsfile when executing terraform commands. For other names, you need to add.autobefore tfvars, such asvariables.auto.tfvars)Modify parameter values according to actual needs
When executing
terraform planorterraform apply, Terraform will automatically read the variable values in this file
In addition to using the terraform.tfvars file, you can also set variable values through the following methods:
Command-line parameters:
terraform apply -var="smn_topic_name=tf_test_topic" -var="lts_group_name=tf_test_group"Environment variables:
export TF_VAR_smn_topic_name=tf_test_topicCustom-named variable files:
terraform apply -var-file="custom.tfvars"
Note: If the same variable is set through multiple methods, Terraform will use variable values according to the following priority: command-line parameters > variable files > environment variables > default values.
7. Initialize and Apply Terraform Configuration
After completing the above script configuration, execute the following steps to create resources:
Run
terraform initto initialize the environmentRun
terraform planto view the resource creation planAfter confirming that the resource plan is correct, run
terraform applyto start creating SMN topic, LTS log group and stream, SMN log tank, and AOM alarm action ruleRun
terraform showto view the created resources
Reference Information
Last updated