Deploy LTS Configuration
Application Scenario
Anti-DDoS (Anti-Distributed Denial of Service) is a distributed denial-of-service attack protection service provided by Huawei Cloud, which can effectively protect public IPs from DDoS attacks and ensure stable business operations. By configuring the integration between Anti-DDoS and Log Tank Service (LTS), Anti-DDoS attack logs can be transmitted to LTS in real-time, facilitating log analysis, auditing, and monitoring. LTS configuration helps users centrally manage and analyze Anti-DDoS protection logs, enabling timely detection and response to security threats.
This best practice will introduce how to use Terraform to automatically deploy Anti-DDoS LTS configuration, including creating LTS log groups, log streams, and configuring the integration between Anti-DDoS and LTS.
Related Resources/Data Sources
This best practice involves the following main resources:
Resources
Resource/Data Source Dependencies
huaweicloud_lts_group
└── huaweicloud_lts_stream
└── huaweicloud_antiddos_lts_configOperation Steps
1. Script Preparation
Prepare the TF file (e.g., main.tf) in the specified workspace for writing the current best practice script, 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. Refer to the "Preparation Before Deploying Huawei Cloud Resources" document for configuration introduction.
2. Create Log Tank Service Log Group Resource
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to create a Log Tank Service log group resource:
Parameter Description:
group_name: The log group name, assigned by referencing the input variable lts_group_name
ttl_in_days: The log retention time (unit: days), assigned by referencing the input variable lts_ttl_in_days
enterprise_project_id: The enterprise project ID, assigned by referencing the input variable enterprise_project_id, default value is null
3. Create Log Tank Service Log Stream Resource
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to create a Log Tank Service log stream resource:
Parameter Description:
group_id: The log group ID, referencing the ID of the previously created Log Tank Service log group resource (huaweicloud_lts_group.test)
stream_name: The log stream name, assigned by referencing the input variable lts_stream_name
is_favorite: Whether to favorite the log stream, assigned by referencing the input variable lts_is_favorite, default value is false
enterprise_project_id: The enterprise project ID, assigned by referencing the input variable enterprise_project_id, default value is null
4. Create Anti-DDoS LTS Configuration Resource
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to create an Anti-DDoS LTS configuration resource:
Parameter Description:
lts_group_id: The LTS log group ID, referencing the ID of the previously created Log Tank Service log group resource (huaweicloud_lts_group.test)
lts_attack_stream_id: The LTS attack log stream ID, referencing the ID of the previously created Log Tank Service log stream resource (huaweicloud_lts_stream.test)
enterprise_project_id: The enterprise project ID, assigned by referencing the input variable enterprise_project_id, default value is null
5. Preset Input Parameters Required for Resource Deployment (Optional)
In this practice, some resources use input variables to assign configuration content. These input parameters need to be manually entered during subsequent deployment. At the same time, Terraform provides a method to preset these configurations through tfvars files, which can avoid repeated input during each execution.
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 users to automatically import the content of thistfvarsfile when executing terraform commands. For other naming, 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 in the following ways:
Command line parameters:
terraform apply -var="lts_group_name=test-group" -var="lts_stream_name=test-stream"Environment variables:
export TF_VAR_lts_group_name=test-groupCustom named variable file:
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 file > environment variables > default values.
6. 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 the Anti-DDoS LTS configurationRun
terraform showto view the details of the created Anti-DDoS LTS configuration
Reference Information
Last updated