-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dms): support to get and delete rabbitmq background tasks
- Loading branch information
Showing
7 changed files
with
399 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...oud/services/acceptance/dms/data_source_huaweicloud_dms_rabbitmq_background_tasks_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
43 changes: 43 additions & 0 deletions
43
.../services/acceptance/dms/resource_huaweicloud_dms_rabbitmq_background_task_delete_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
92 changes: 92 additions & 0 deletions
92
huaweicloud/services/dms/data_source_huaweicloud_dms_rabbitmq_background_tasks.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.