Skip to content

Commit 0021054

Browse files
authored
chore(example/sms): refactor the task best practice (#7341)
1 parent 871b216 commit 0021054

File tree

8 files changed

+157
-29
lines changed

8 files changed

+157
-29
lines changed

examples/sms/migration-task/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Create a migration task
2+
3+
This example provides best practice code for using Terraform to create a migration task in HuaweiCloud SMS service.
4+
5+
## Prerequisites
6+
7+
* A HuaweiCloud account
8+
* Terraform installed
9+
* HuaweiCloud access key and secret key (AK/SK)
10+
* SMS source server already exists and is registered
11+
12+
## Required Variables
13+
14+
The following variables need to be configured:
15+
16+
### Authentication Variables
17+
18+
* `region_name` - The region where the SMS task is located
19+
* `access_key` - The access key of the IAM user
20+
* `secret_key` - The secret key of the IAM user
21+
22+
### Resource Variables
23+
24+
#### Required Variables
25+
26+
* `source_server_name` - The name of the SMS source server
27+
* `server_template_name` - The name of the SMS server template
28+
* `migrate_task_type` - The type of the SMS task (e.g., "MIGRATE_FILE" or "MIGRATE_BLOCK")
29+
* `server_os_type` - The OS type of the server (e.g., "LINUX" or "WINDOWS")
30+
31+
## Usage
32+
33+
* Copy this example script to your `main.tf`.
34+
35+
* Create a `terraform.tfvars` file and fill in the required variables:
36+
37+
```hcl
38+
region_name = "cn-north-4"
39+
access_key = "your-access-key"
40+
secret_key = "your-secret-key"
41+
42+
source_server_name = "your_source_server_name"
43+
server_template_name = "your_server_template_name"
44+
migrate_task_type = "MIGRATE_BLOCK"
45+
server_os_type = "WINDOWS"
46+
```
47+
48+
* Initialize Terraform:
49+
50+
```bash
51+
$ terraform init
52+
```
53+
54+
* Review the Terraform plan:
55+
56+
```bash
57+
$ terraform plan
58+
```
59+
60+
* Apply the configuration:
61+
62+
```bash
63+
$ terraform apply
64+
```
65+
66+
* To clean up the resources:
67+
68+
```bash
69+
$ terraform destroy
70+
```
71+
72+
## Note
73+
74+
* Make sure to keep your credentials secure and never commit them to version control
75+
* This example creates an SMS server template and migration task
76+
* The SMS source server must already exist and be registered in the SMS service
77+
* The migration task type and OS type are configurable via variables
78+
* All resources will be created in the specified region
79+
80+
## Requirements
81+
82+
| Name | Version |
83+
| ---- | ---- |
84+
| terraform | >= 0.12.0 |
85+
| huaweicloud | >= 1.37.0 |

examples/sms/migration-task/main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
data "huaweicloud_availability_zones" "test" {}
2+
3+
data "huaweicloud_sms_source_servers" "test" {
4+
name = var.source_server_name
5+
}
6+
7+
resource "huaweicloud_sms_server_template" "test" {
8+
name = var.server_template_name
9+
availability_zone = try(data.huaweicloud_availability_zones.test.names[0], null)
10+
}
11+
12+
resource "huaweicloud_sms_task" "test" {
13+
type = var.migrate_task_type
14+
os_type = var.server_os_type
15+
source_server_id = try(data.huaweicloud_sms_source_servers.test.servers[0].id, null)
16+
vm_template_id = huaweicloud_sms_server_template.test.id
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_providers {
3+
huaweicloud = {
4+
source = "huaweicloud/huaweicloud"
5+
version = ">= 1.37.0"
6+
}
7+
}
8+
}
9+
10+
provider "huaweicloud" {
11+
region = var.region_name
12+
access_key = var.access_key
13+
secret_key = var.secret_key
14+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source_server_name = "tf_source_server_name"
2+
server_template_name = "tf_server_template_name"
3+
migrate_task_type = "MIGRATE_BLOCK"
4+
server_os_type = "WINDOWS"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Variable definitions for authentication
2+
variable "region_name" {
3+
description = "The region where the SMS task is located"
4+
type = string
5+
}
6+
7+
variable "access_key" {
8+
description = "The access key of the IAM user"
9+
type = string
10+
}
11+
12+
variable "secret_key" {
13+
description = "The secret key of the IAM user"
14+
type = string
15+
}
16+
17+
# Variable definitions for resources/data sources
18+
variable "source_server_name" {
19+
description = "The name of the SMS source server"
20+
type = string
21+
default = null
22+
}
23+
24+
variable "server_template_name" {
25+
description = "The name of the SMS server template"
26+
type = string
27+
}
28+
29+
variable "migrate_task_type" {
30+
description = "The type of the SMS task"
31+
type = string
32+
}
33+
34+
variable "server_os_type" {
35+
description = "The OS type of the server"
36+
type = string
37+
}

examples/sms/task/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/sms/task/main.tf

Lines changed: 0 additions & 17 deletions
This file was deleted.

examples/sms/task/variables.tf

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)