Deploy Object Migration Through Task Group
Application Scenario
Object Storage Migration Service (OMS) is a one-stop data migration service provided by Huawei Cloud, helping users quickly, securely, and efficiently migrate data from other cloud service providers or local environments to Huawei Cloud Object Storage Service (OBS). OMS service supports multiple data sources, including mainstream cloud storage services such as AWS S3, Alibaba Cloud OSS, Tencent Cloud COS, as well as local file systems.
Task group migration is an important feature of the OMS service, used for batch migration of object storage data. Through task group migration, enterprises can efficiently migrate large amounts of data, supporting incremental synchronization, resumable transfer, data verification, and other functions, ensuring the integrity and consistency of data migration. Task group migration supports advanced features such as bandwidth control, time window settings, failure retry, etc., providing enterprises with reliable data migration solutions. This best practice will introduce how to use Terraform to automatically deploy OMS task group migration tasks, including KMS key creation, OBS bucket configuration, object upload, bucket policy settings, and migration task group creation.
Related Resources/Data Sources
This best practice involves the following main resources and data sources:
Resources
Resource/Data Source Dependencies
huaweicloud_kms_key.test
└── huaweicloud_obs_bucket.test
├── huaweicloud_obs_bucket_object.test
│ └── huaweicloud_oms_migration_task_group.test
└── huaweicloud_obs_bucket_policy.test
└── huaweicloud_oms_migration_task_group.testOperation 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 KMS Key
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to create a KMS key resource:
Parameter Description:
key_alias: Key alias, assigned by referencing the input variable key_alias
key_usage: Key usage, assigned by referencing the input variable key_usage
count: Conditional creation, creates when encryption is enabled and key ID is not specified
3. 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: Bucket name, assigned by referencing the input variable bucket_name
storage_class: Storage class, assigned by referencing the input variable bucket_storage_class
acl: Access control list, assigned by referencing the input variable bucket_acl
encryption: Whether encryption is enabled, assigned by referencing the input variable bucket_encryption
sse_algorithm: Server-side encryption algorithm, uses kms algorithm when encryption is enabled
kms_key_id: KMS key ID, prioritizes using input variable, uses created KMS key if empty
force_destroy: Force destroy, assigned by referencing the input variable bucket_force_destroy
tags: Tags, assigned by referencing the input variable bucket_tags
4. Create OBS Bucket Object
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to create an OBS bucket object resource:
Parameter Description:
bucket: Bucket ID, assigned by referencing the OBS bucket resource (huaweicloud_obs_bucket.test) ID
key: Object key name, generated by combining extension name and object name
content_type: Content type, set to application/xml
content: Object content, assigned by referencing the input variable object_upload_content
5. Create OBS Bucket Policy
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to create an OBS bucket policy resource:
Parameter Description:
bucket: Bucket ID, assigned by referencing the OBS bucket resource (huaweicloud_obs_bucket.test) ID
policy: Bucket policy, allows all users to read objects in the bucket
6. Create OMS Migration Task Group
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to create an OMS migration task group resource:
Parameter Description:
action: Action type, assigned by referencing the input variable group_action_type
type: Task group type, assigned by referencing the input variable group_type
enable_kms: Whether KMS is enabled, assigned by referencing the input variable group_enable_kms
migrate_since: Migration start time, assigned by referencing the input variable group_migrate_since
object_overwrite_mode: Object overwrite mode, assigned by referencing the input variable group_object_overwrite_mode
consistency_check: Consistency check, assigned by referencing the input variable group_consistency_check
enable_requester_pays: Whether requester pays is enabled, assigned by referencing the input variable group_enable_requester_pays
enable_failed_object_recording: Whether failed object recording is enabled, assigned by referencing the input variable group_enable_failed_object_recording
source_object: Source object configuration, includes data source, region, bucket, access key, and object list
destination_object: Destination object configuration, includes region, bucket, and access key
bandwidth_policy: Bandwidth policy, dynamically creates bandwidth control configuration
7. 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="object_name=my-object"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.
8. 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 migration task groupsRun
terraform showto view the created migration task groups
Reference Information
Last updated