Deploy System Tracker
Application Scenario
The System Tracker of Cloud Trace Service (CTS) is a core service used to record and store audit logs of cloud resource operations. Through system trackers, you can achieve security audit, compliance monitoring, operation recording, problem troubleshooting, and other functions.
System trackers are particularly suitable for scenarios that require recording cloud resource operation history, conducting security audits, meeting compliance requirements, etc., such as enterprise-level security monitoring, compliance checks, operation auditing, problem tracking, etc. This best practice will introduce how to use Terraform to automatically deploy a CTS system tracker, implementing automatic recording and storage of cloud resource operations.
Related Resources/Data Sources
This best practice involves the following main resources and data sources:
Data Sources
This best practice does not use data sources.
Resources
Resource/Data Source Dependencies
huaweicloud_obs_bucket
└── huaweicloud_cts_trackerOperation 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 OBS Bucket
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to create an OBS bucket resource:
Parameter Description:
bucket: OBS bucket name, assigned by referencing the input variable bucket_name
acl: Bucket access control list, set to "private" for private access
force_destroy: Whether to force delete the bucket, set to true to allow deletion of non-empty buckets
3. Create CTS System Tracker
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to create a CTS system tracker resource:
Parameter Description:
enabled: Whether to enable the system tracker, assigned by referencing the input variable tracker_enabled, default value true means enabled
tags: System tracker tags, assigned by referencing the input variable tracker_tags, used for resource classification and management
delete_tracker: Whether to delete the system tracker when the tracker resource is deleted, assigned by referencing the input variable is_system_tracker_delete, default value true means delete
bucket_name: OBS bucket name for storing trace data, assigned by referencing the OBS bucket's bucket attribute
file_prefix: Prefix of trace objects in the OBS bucket, assigned by referencing the input variable trace_object_prefix
compress_type: Compression type of trace files, assigned by referencing the input variable trace_file_compression_type, default value "gzip" means using gzip compression
lts_enabled: Whether to enable trace analysis for LTS service, assigned by referencing the input variable is_lts_enabled, default value true means enabled
4. Preset Input Parameters Required for Resource Deployment (Optional)
In this practice, some resources and data sources use input variables to assign values to configuration content. These input parameters need to be manually entered during subsequent deployments. 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
terraform.tfvarsfile in the working directory (this file name allows users to automatically import the content of thistfvarsfile when executing terraform commands; for other names,.autoneeds to be added before tfvars, such asvariables.auto.tfvars)Modify parameter values as needed
When executing
terraform planorterraform apply, Terraform will automatically read the variable values from this file
In addition to using terraform.tfvars file, variable values can also be set in the following ways:
Command line parameters:
terraform apply -var="bucket_name=my-bucket" -var="trace_object_prefix=my-prefix"Environment variables:
export TF_VAR_bucket_name=my-bucketCustom named variable files:
terraform apply -var-file="custom.tfvars"
Note: If the same variable is set in multiple ways, Terraform will use the variable value according to the following priority: command line parameters > variable files > environment variables > default values.
5. 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 the resource plan is correct, run
terraform applyto start creating OBS bucket and CTS system trackerRun
terraform showto view the details of the created OBS bucket and CTS system tracker
Reference Information
Last updated