Skip to content

Commit

Permalink
feat(dms): support kafka partition reassignment task management (#5229)
Browse files Browse the repository at this point in the history
  • Loading branch information
saf3dfsa authored Jul 22, 2024
1 parent 4c1fc5d commit 266073f
Show file tree
Hide file tree
Showing 4 changed files with 485 additions and 0 deletions.
130 changes: 130 additions & 0 deletions docs/resources/dms_kafka_partition_reassign.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
subcategory: "Distributed Message Service (DMS)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_dms_kafka_partition_reassign"
description: |-
Manages a DMS kafka partition reassign resource within HuaweiCloud.
---

# huaweicloud_dms_kafka_partition_reassign

Manages a DMS kafka partition reassign resource within HuaweiCloud.

## Example Usage

### Create a partition reassignment task by manually specified assignment plan

```hcl
variable "instance_id" {}
variable "topic_name" {}
resource "huaweicloud_dms_kafka_partition_reassign" "test" {
instance_id = var.instance_id
reassignments {
topic = var.topic_name
assignment {
partition = 0
partition_brokers = [0,1,2]
}
assignment {
partition = 1
partition_brokers = [2,0,1]
}
assignment {
partition = 2
partition_brokers = [1,2,0]
}
}
}
```

### Create a partition reassignment task by automatic assignment plan

```hcl
variable "instance_id" {}
variable "topic_name" {}
resource "huaweicloud_dms_kafka_partition_reassign" "test" {
instance_id = var.instance_id
reassignments {
topic = var.topic_name
brokers = [0,1,2]
replication_factor = 1
}
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String, ForceNew) The region in which to create the resource.
If omitted, the provider-level region will be used. Changing this creates a new resource.

* `instance_id` - (Required, String, ForceNew) Specifies the DMS kafka instance ID.
Changing this creates a new resource.

* `reassignments` - (Required, List, ForceNew) Specifies the reassignment plan.
Changing this creates a new resource.
The [reassignments](#reassignments_struct) structure is documented below.

* `throttle` - (Optional, Int, ForceNew) Specifies the reassignment threshold. Value can be specified ranges from **1**
to **300**. The unit is **MB/s**. Or specifies it to **-1**, indicating no throttling required.
Changing this creates a new resource.

* `is_schedule` - (Optional, Bool, ForceNew) Specifies whether the task is scheduled. Defaults to **false**.
Changing this creates a new resource.

* `execute_at` - (Optional, Int, ForceNew) Specifies the schedule time. The value is a UNIX timestamp, in **ms**.
It's required if `is_schedule` is **true**. Changing this creates a new resource.

* `time_estimate` - (Optional, Bool, ForceNew) Specifies whether to perform time estimation tasks. Defaults to **false**.
Changing this creates a new resource.

<a name="reassignments_struct"></a>
The `reassignments` block supports:

* `topic` - (Required, String, ForceNew) Specifies the topic name. Changing this creates a new resource.

* `brokers` - (Optional, List, ForceNew) Specifies the integer list of brokers to which partitions are reassigned.
It's **required** in **automatic** assignment. Changing this creates a new resource.

* `replication_factor` - (Optional, Int, ForceNew) Specifies the replication factor, which can be specified in
**automatic** assignment. Changing this creates a new resource.

* `assignment` - (Optional, List, ForceNew) Specifies the manually specified assignment plan.
It's **required** in **manually** specified assignment. Changing this creates a new resource.
The [assignment](#reassignments_assignment_struct) structure is documented below.

-> If manually specified assignment and automatic assignment are both specified, only **manually** specified assignment
will take effect.

<a name="reassignments_assignment_struct"></a>
The `assignment` block supports:

* `partition` - (Optional, Int, ForceNew) Specifies the partition number in manual assignment.
It's actually **required** in **manual** assignment plan. Changing this creates a new resource.

* `partition_brokers` - (Optional, List, ForceNew) Specifies the integer list of brokers to be assigned to a partition in
manual assignment. It's actually **required** in **manual** assignment plan. Changing this creates a new resource.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID in UUID format.

* `task_id` - Indicates the task ID, and it's only returned for a partition reassignment task.

* `reassignment_time` - Indicates the estimated time, in seconds, and it's only returned for a time estimation task.

## Timeouts

This resource provides the following timeout configuration options:

* `create` - Default is 20 minutes.
1 change: 1 addition & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,7 @@ func Provider() *schema.Provider {
"huaweicloud_dms_kafka_permissions": dms.ResourceDmsKafkaPermissions(),
"huaweicloud_dms_kafka_instance": dms.ResourceDmsKafkaInstance(),
"huaweicloud_dms_kafka_topic": dms.ResourceDmsKafkaTopic(),
"huaweicloud_dms_kafka_partition_reassign": dms.ResourceDmsKafkaPartitionReassign(),
"huaweicloud_dms_kafka_consumer_group": dms.ResourceDmsKafkaConsumerGroup(),
"huaweicloud_dms_kafka_smart_connect": dms.ResourceDmsKafkaSmartConnect(),
"huaweicloud_dms_kafka_smart_connect_task": dms.ResourceDmsKafkaSmartConnectTask(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package dms

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
)

func TestAccKafkaPartitionReassign_basic(t *testing.T) {
rName := acceptance.RandomAccResourceNameWithDash()
resourceName := "huaweicloud_dms_kafka_partition_reassign.test"

// Avoid CheckDestroy
// lintignore:AT001
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccKafkaPartitionReassign_basic(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "task_id"),
),
},
{
Config: testAccKafkaPartitionReassign_automatical(rName, false),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "task_id"),
),
},
{
Config: testAccKafkaPartitionReassign_automatical(rName, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "reassignment_time"),
),
},
},
})
}

func testAccKafkaPartitionReassign_basic(rName string) string {
return fmt.Sprintf(`
%[1]s
resource "huaweicloud_dms_kafka_topic" "test" {
instance_id = huaweicloud_dms_kafka_instance.test.id
name = "%s"
partitions = 2
replicas = 3
}
resource "huaweicloud_dms_kafka_partition_reassign" "test" {
depends_on = [huaweicloud_dms_kafka_topic.test]
instance_id = huaweicloud_dms_kafka_instance.test.id
reassignments {
topic = huaweicloud_dms_kafka_topic.test.name
assignment {
partition = 0
partition_brokers = [0,1,2]
}
assignment {
partition = 1
partition_brokers = [2,0,1]
}
}
}`, testAccKafkaInstance_basic(rName), rName)
}

func testAccKafkaPartitionReassign_automatical(rName string, timeEstimate bool) string {
return fmt.Sprintf(`
%[1]s
resource "huaweicloud_dms_kafka_topic" "test" {
instance_id = huaweicloud_dms_kafka_instance.test.id
name = "%s"
partitions = 2
replicas = 3
}
resource "huaweicloud_dms_kafka_partition_reassign" "test" {
depends_on = [huaweicloud_dms_kafka_topic.test]
instance_id = huaweicloud_dms_kafka_instance.test.id
throttle = -1
time_estimate = %t
reassignments {
topic = huaweicloud_dms_kafka_topic.test.name
brokers = [0,1,2]
replication_factor = 3
}
}`, testAccKafkaInstance_basic(rName), rName, timeEstimate)
}
Loading

0 comments on commit 266073f

Please sign in to comment.