Skip to content

Commit

Permalink
feat(dms): support to get and delete rabbitmq background tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
saf3dfsa committed Nov 22, 2024
1 parent d9bb121 commit cb83d63
Show file tree
Hide file tree
Showing 7 changed files with 399 additions and 16 deletions.
62 changes: 62 additions & 0 deletions docs/data-sources/dms_rabbitmq_background_tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
subcategory: "Distributed Message Service (DMS)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_dms_rabbitmq_background_tasks"
description: |-
Use this data source to get the list of DMS RabbitMQ background tasks.
---

# huaweicloud_dms_rabbitmq_background_tasks

Use this data source to get the list of DMS RabbitMQ background tasks.

## Example Usage

```hcl
variable "instance_id" {}
data "huaweicloud_dms_rabbitmq_background_tasks" "test" {
instance_id = var.instance_id
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String) Specifies the region in which to query the resource.
If omitted, the provider-level region will be used.

* `instance_id` - (Required, String) Specifies the instance ID.

* `begin_time` - (Optional, String) Specifies the time of task where the query starts. The format is YYYYMMDDHHmmss.

* `end_time` - (Optional, String) Specifies the time of task where the query ends. The format is YYYYMMDDHHmmss.

## Attribute Reference

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

* `id` - The data source ID.

* `tasks` - Indicates the task list.
The [tasks](#attrblock--tasks) structure is documented below.

<a name="attrblock--tasks"></a>
The `tasks` block supports:

* `created_at` - Indicates the start time.

* `id` - Indicates the task ID.

* `name` - Indicates the task name.

* `params` - Indicates the task parameters.

* `status` - Indicates the task status.

* `updated_at` - Indicates the end time.

* `user_id` - Indicates the user ID.

* `user_name` - Indicates the username.
43 changes: 43 additions & 0 deletions docs/resources/dms_rabbitmq_background_task_delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
subcategory: "Distributed Message Service (DMS)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_dms_rabbitmq_background_task_delete"
description: |-
Manages a DMS RabbitMQ background task delete resource within HuaweiCloud.
---

# huaweicloud_dms_rabbitmq_background_task_delete

Manages a DMS RabbitMQ background task delete resource within HuaweiCloud.

## Example Usage

```hcl
variable "instance_id" {}
variable "task_id" {}
resource "huaweicloud_dms_rabbitmq_background_task_delete" "test" {
instance_id = var.instance_id
task_id = var.task_id
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String, ForceNew) Specifies 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 instance ID.
Changing this creates a new resource.

* `task_id` - (Required, String, ForceNew) Specifies the task ID.
Changing this creates a new resource.

## Attribute Reference

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

* `id` - The resource ID.
34 changes: 18 additions & 16 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,14 +702,15 @@ func Provider() *schema.Provider {
"huaweicloud_dms_kafka_message_diagnosis_tasks": dms.DataSourceDmsKafkaMessageDiagnosisTasks(),
"huaweicloud_dms_kafka_messages": dms.DataSourceDmsKafkaMessages(),

"huaweicloud_dms_rabbitmq_flavors": dms.DataSourceRabbitMQFlavors(),
"huaweicloud_dms_rabbitmq_plugins": dms.DataSourceDmsRabbitmqPlugins(),
"huaweicloud_dms_rabbitmq_instances": dms.DataSourceDmsRabbitMQInstances(),
"huaweicloud_dms_rabbitmq_extend_flavors": dms.DataSourceDmsRabbitmqExtendFlavors(),
"huaweicloud_dms_rabbitmq_vhosts": dms.DataSourceDmsRabbitmqVhosts(),
"huaweicloud_dms_rabbitmq_exchanges": dms.DataSourceDmsRabbitmqExchanges(),
"huaweicloud_dms_rabbitmq_queues": dms.DataSourceDmsRabbitmqQueues(),
"huaweicloud_dms_rabbitmq_users": dms.DataSourceDmsRabbitmqUsers(),
"huaweicloud_dms_rabbitmq_background_tasks": dms.DataSourceDmsRabbitMQBackgroundTasks(),
"huaweicloud_dms_rabbitmq_flavors": dms.DataSourceRabbitMQFlavors(),
"huaweicloud_dms_rabbitmq_plugins": dms.DataSourceDmsRabbitmqPlugins(),
"huaweicloud_dms_rabbitmq_instances": dms.DataSourceDmsRabbitMQInstances(),
"huaweicloud_dms_rabbitmq_extend_flavors": dms.DataSourceDmsRabbitmqExtendFlavors(),
"huaweicloud_dms_rabbitmq_vhosts": dms.DataSourceDmsRabbitmqVhosts(),
"huaweicloud_dms_rabbitmq_exchanges": dms.DataSourceDmsRabbitmqExchanges(),
"huaweicloud_dms_rabbitmq_queues": dms.DataSourceDmsRabbitmqQueues(),
"huaweicloud_dms_rabbitmq_users": dms.DataSourceDmsRabbitmqUsers(),

"huaweicloud_dms_rocketmq_broker": dms.DataSourceDmsRocketMQBroker(),
"huaweicloud_dms_rocketmq_instances": dms.DataSourceDmsRocketMQInstances(),
Expand Down Expand Up @@ -1554,14 +1555,15 @@ func Provider() *schema.Provider {
"huaweicloud_dms_kafka_user_client_quota": dms.ResourceDmsKafkaUserClientQuota(),
"huaweicloud_dms_kafka_message_diagnosis_task": dms.ResourceDmsKafkaMessageDiagnosisTask(),

"huaweicloud_dms_rabbitmq_instance": dms.ResourceDmsRabbitmqInstance(),
"huaweicloud_dms_rabbitmq_plugin": dms.ResourceDmsRabbitmqPlugin(),
"huaweicloud_dms_rabbitmq_vhost": dms.ResourceDmsRabbitmqVhost(),
"huaweicloud_dms_rabbitmq_exchange": dms.ResourceDmsRabbitmqExchange(),
"huaweicloud_dms_rabbitmq_queue": dms.ResourceDmsRabbitmqQueue(),
"huaweicloud_dms_rabbitmq_queue_message_clear": dms.ResourceDmsRabbitmqQueueMessageClear(),
"huaweicloud_dms_rabbitmq_exchange_associate": dms.ResourceDmsRabbitmqExchangeAssociate(),
"huaweicloud_dms_rabbitmq_user": dms.ResourceDmsRabbitmqUser(),
"huaweicloud_dms_rabbitmq_background_task_delete": dms.ResourceDmsRabbitMQBackgroundTaskDelete(),
"huaweicloud_dms_rabbitmq_instance": dms.ResourceDmsRabbitmqInstance(),
"huaweicloud_dms_rabbitmq_plugin": dms.ResourceDmsRabbitmqPlugin(),
"huaweicloud_dms_rabbitmq_vhost": dms.ResourceDmsRabbitmqVhost(),
"huaweicloud_dms_rabbitmq_exchange": dms.ResourceDmsRabbitmqExchange(),
"huaweicloud_dms_rabbitmq_queue": dms.ResourceDmsRabbitmqQueue(),
"huaweicloud_dms_rabbitmq_queue_message_clear": dms.ResourceDmsRabbitmqQueueMessageClear(),
"huaweicloud_dms_rabbitmq_exchange_associate": dms.ResourceDmsRabbitmqExchangeAssociate(),
"huaweicloud_dms_rabbitmq_user": dms.ResourceDmsRabbitmqUser(),

"huaweicloud_dms_rocketmq_instance": dms.ResourceDmsRocketMQInstance(),
"huaweicloud_dms_rocketmq_consumer_group": dms.ResourceDmsRocketMQConsumerGroup(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package dms

import (
"fmt"
"testing"
"time"

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

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

func TestAccDataSourceDmsRabbitMQBackgroundTasks_basic(t *testing.T) {
dataSource := "data.huaweicloud_dms_rabbitmq_background_tasks.test"
rName := acceptance.RandomAccResourceName()
dc := acceptance.InitDataSourceCheck(dataSource)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testDataSourceDmsRabbitMQBackgroundTasks_basic(rName),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttrSet(dataSource, "tasks.#"),
resource.TestCheckResourceAttrSet(dataSource, "tasks.0.id"),
resource.TestCheckResourceAttrSet(dataSource, "tasks.0.name"),
resource.TestCheckResourceAttrSet(dataSource, "tasks.0.params"),
resource.TestCheckResourceAttrSet(dataSource, "tasks.0.status"),
resource.TestCheckResourceAttrSet(dataSource, "tasks.0.user_id"),
resource.TestCheckResourceAttrSet(dataSource, "tasks.0.user_name"),
resource.TestCheckResourceAttrSet(dataSource, "tasks.0.created_at"),
resource.TestCheckResourceAttrSet(dataSource, "tasks.0.updated_at"),
),
},
},
})
}

func testDataSourceDmsRabbitMQBackgroundTasks_basic(name string) string {
beginTime := time.Now().UTC().Format("20060102150405")
endTime := time.Now().Add(time.Hour).UTC().Format("20060102150405")

return fmt.Sprintf(`
%[1]s
data "huaweicloud_dms_rabbitmq_background_tasks" "test" {
instance_id = huaweicloud_dms_rabbitmq_instance.test.id
begin_time = "%[2]s"
end_time = "%[3]s"
}
`, testAccDmsRabbitmqInstance_newFormat_single(name), beginTime, endTime)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package dms

import (
"fmt"
"testing"

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

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

func TestAccDmsRabbitMQBackgroundTaskDelete_basic(t *testing.T) {
rName := acceptance.RandomAccResourceNameWithDash()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: testAccDmsRabbitMQBackgroundTaskDelete_basic(rName),
},
},
})
}

func testAccDmsRabbitMQBackgroundTaskDelete_basic(rName string) string {
return fmt.Sprintf(`
%[1]s
resource "huaweicloud_dms_rabbitmq_background_task_delete" "test" {
instance_id = huaweicloud_dms_rabbitmq_instance.test.id
task_id = try(data.huaweicloud_dms_rabbitmq_background_tasks.test.tasks[0].id, "")
lifecycle {
ignore_changes = [
task_id,
]
}
}`, testDataSourceDmsRabbitMQBackgroundTasks_basic(rName))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package dms

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// @API RabbitMQ GET /v2/{project_id}/instances/{instance_id}/tasks
func DataSourceDmsRabbitMQBackgroundTasks() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceDmsRabbitMQBackgroundTasksRead,

Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: `Specifies the region in which to query the resource. If omitted, the provider-level region will be used.`,
},
"instance_id": {
Type: schema.TypeString,
Required: true,
Description: `Specifies the instance ID.`,
},
"begin_time": {
Type: schema.TypeString,
Optional: true,
Description: `Specifies the time of task where the query starts. The format is YYYYMMDDHHmmss.`,
},
"end_time": {
Type: schema.TypeString,
Optional: true,
Description: `Specifies the time of task where the query ends. The format is YYYYMMDDHHmmss.`,
},
"tasks": {
Type: schema.TypeList,
Computed: true,
Description: `Indicates the task list.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: `Indicates the task ID.`,
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: `Indicates the task name.`,
},
"params": {
Type: schema.TypeString,
Computed: true,
Description: `Indicates the task parameters.`,
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: `Indicates the task status.`,
},
"user_id": {
Type: schema.TypeString,
Computed: true,
Description: `Indicates the user ID.`,
},
"user_name": {
Type: schema.TypeString,
Computed: true,
Description: `Indicates the username.`,
},
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: `Indicates the start time.`,
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
Description: `Indicates the end time.`,
},
},
},
},
},
}
}

func dataSourceDmsRabbitMQBackgroundTasksRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
return dataSourceDmsKafkaBackgroundTasksRead(ctx, d, meta)
}
Loading

0 comments on commit cb83d63

Please sign in to comment.