Create a DTS synchronization instance using Terraform
Terraform is an open-source tool that allows you to safely and efficiently preview, provision, and manage cloud infrastructure and resources. You can use Terraform to manage some DTS resources. This topic describes how to use Terraform to create a DTS synchronization instance.
You can run the sample code in this tutorial with a single click. Run in one click
Prerequisites
-
To reduce security risks, we recommend that you use a RAM user with the minimum required permissions to complete this tutorial. For more information, see Create a RAM user and Manage RAM user permissions. This tutorial requires the following permission policy:
{ "Version": "1", "Statement": [ { "Effect": "Allow", "Action": [ "dts:CreateDtsInstance", "dts:DescribeGadInstances", "dts:DescribeDtsJobDetail", "dts:DescribeInstances", "dts:DeleteSynchronizationJob" ], "Resource": "*" } ] } -
Prepare a Terraform runtime environment. You can use Terraform in one of the following ways:
-
Explorer: Alibaba Cloud provides an online runtime environment for Terraform. After logging on, you can use and experience Terraform online without needing to install it. This method is ideal for quickly and easily trying or debugging Terraform at no cost.
-
Quickly create resources by using Terraform: Alibaba Cloud Cloud Shell comes pre-installed with Terraform components and configured with identity credentials. You can run Terraform commands directly in Cloud Shell. This method is ideal for fast, convenient, and low-cost access to Terraform.
-
Install and configure Terraform on your on-premises machine: This option is ideal for scenarios with poor network connectivity or when you need a customized development environment.
-
Resources used
-
alicloud_dts_synchronization_instance: a DTS synchronization instance.
Procedure
-
Create a working directory, and in that directory, create a configuration file named main.tf and copy the following code into main.tf.
variable "region" { default = "cn-beijing" } provider "alicloud" { region = var.region } # DTS synchronization instance resource "alicloud_dts_synchronization_instance" "default" { payment_type = "PayAsYouGo" source_endpoint_engine_name = "MySQL" source_endpoint_region = var.region destination_endpoint_engine_name = "MySQL" destination_endpoint_region = var.region instance_class = "small" sync_architecture = "oneway" } -
Run the following command to initialize the Terraform runtime environment.
terraform initThe following output indicates a successful initialization.
Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary. -
Run the following command to apply the configuration.
terraform applyWhen prompted, enter
yesand press the Enter key. Wait for the command to complete. The following output indicates that the configuration was applied successfully.You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes Apply complete! Resources: 1 added, 0 changed, 0 destroyed. -
Verify the result.
Terraform show
In your working directory, run the following command to view the details of the resources created by Terraform:
terraform showshell@Alicloud:~/dts$ terraform show # alicloud_dts_synchronization_instance.default: resource "alicloud_dts_synchronization_instance" "default" { destination_endpoint_engine_name = "MySQL" destination_endpoint_region = "cn-beijing" id = "dtsxxx" instance_class = "small" payment_type = "PayAsYouGo" source_endpoint_engine_name = "MySQL" source_endpoint_region = "cn-beijing" sync_architecture = "oneway" }Console
Log on to the Data Transmission Service (DTS) console, navigate to the page, and view the new DTS synchronization instance.
In the task list, you can view information such as the task status (for example, Not Configured), link specification, and payment type. In the Actions column, click Configure Task to proceed with the next configuration step.
Clean up resources
When you no longer need the resources managed by Terraform, run the following command to release them. For more information about terraform destroy, see Common commands.
terraform destroy
Complete example
You can run the sample code in this tutorial with a single click. Run in one click
Sample code
For more complete examples, see More complete examples.
References
-
For an introduction to Terraform, see What is Alibaba Cloud Terraform?.
-
If network latency causes the 'terraform init' command to time out and fail to download the provider, see Configure a Terraform Init acceleration solution.