Deploy Migration Project
Application Scenario
Server Migration Service (SMS) is a server migration service provided by Huawei Cloud, supporting migration of physical servers, virtual machines, or servers from other cloud platforms to Huawei Cloud, achieving seamless business migration. Migration projects are fundamental resources of SMS service, used to manage and organize migration tasks. By creating migration projects, parameters such as migration region, network type, server type, and synchronization policy can be configured, providing basic configuration for subsequent migration tasks. This best practice introduces how to use Terraform to automatically deploy migration projects, including project basic information, region configuration, network configuration, and synchronization policy configuration.
Related Resources/Data Sources
This best practice involves the following main resources and data sources:
Resources
Resource/Data Source Dependencies
huaweicloud_sms_migration_projectOperation 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 Migration Project
Add the following script to the TF file (such as main.tf) to create a migration project:
Parameter Description:
name: Migration project name, assigned by referencing the input variable
migration_project_nameregion: Region name, assigned by referencing the input variable
migration_project_region, used to specify the migration target regionuse_public_ip: Whether to use public IP for migration, assigned by referencing the input variable
migration_project_use_public_ipexist_server: Whether the server already exists, assigned by referencing the input variable
migration_project_exist_servertype: Migration project type, assigned by referencing the input variable
migration_project_typesyncing: Whether to continue syncing after the first copy or sync, assigned by referencing the input variable
migration_project_syncing
Note: Migration projects are used to manage and organize migration tasks, and need to configure corresponding parameters according to actual migration scenarios. If using public IP for migration, ensure that the source server can access the public network.
3. 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="migration_project_name=tf_test_sms_migration_project" -var="migration_project_region=cn-north-4"Environment variables:
export TF_VAR_migration_project_name=tf_test_sms_migration_projectCustom-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.
4. 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 migration projectRun
terraform showto view the created migration project
Reference Information
Last updated