-
Notifications
You must be signed in to change notification settings - Fork 163
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 rabbitmq queue management (#5494)
- Loading branch information
Showing
7 changed files
with
908 additions
and
0 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,66 @@ | ||
--- | ||
subcategory: "Distributed Message Service (DMS)" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_dms_rabbitmq_queues" | ||
description: |- | ||
Use this data source to get the list of DMS RabbitMQ queues. | ||
--- | ||
|
||
# huaweicloud_dms_rabbitmq_queues | ||
|
||
Use this data source to get the list of DMS RabbitMQ queues. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "instance_id" {} | ||
variable "vhost" {} | ||
data "huaweicloud_dms_rabbitmq_queues" "test" { | ||
instance_id = var.instance_id | ||
vhost = var.vhost | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `region` - (Optional, String) Specifies the region in which to query the data source. | ||
If omitted, the provider-level region will be used. | ||
|
||
* `instance_id` - (Required, String) Specifies the DMS RabbitMQ instance ID. | ||
|
||
* `vhost` - (Required, String) Specifies the vhost name. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The data source ID. | ||
|
||
* `queues` - Indicates the list of queues. | ||
The [queues](#attrblock--queues) structure is documented below. | ||
|
||
<a name="attrblock--queues"></a> | ||
The `queues` block supports: | ||
|
||
* `name` - Indicates the queue name. | ||
|
||
* `auto_delete` - Indicates whether the auto delete is enabled. | ||
|
||
* `durable` - Indicates whether the durable is enabled. | ||
|
||
* `dead_letter_exchange` - Indicates the name of the dead letter exchange. | ||
|
||
* `dead_letter_routing_key` - Indicates the routing key of the dead letter exchange. | ||
|
||
* `lazy_mode` - Indicates the lazy mode. | ||
|
||
* `message_ttl` - Indicates how long a message in this queue can be retained. | ||
|
||
* `consumers` - Indicates the connected consumers. | ||
|
||
* `messages` - Indicates the accumulated messages. | ||
|
||
* `policy` - Indicates the policy. |
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,136 @@ | ||
--- | ||
subcategory: "Distributed Message Service (DMS)" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_dms_rabbitmq_queue" | ||
description: |- | ||
Manages a DMS RabbitMQ queue resource within HuaweiCloud. | ||
--- | ||
|
||
# huaweicloud_dms_rabbitmq_queue | ||
|
||
Manages a DMS RabbitMQ queue resource within HuaweiCloud. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "instance_id" {} | ||
variable "vhost" {} | ||
variable "name" {} | ||
variable "exchange" {} | ||
variable "routing_key" {} | ||
resource "huaweicloud_dms_rabbitmq_queue" "test" { | ||
instance_id = var.instance_id | ||
vhost = var.vhost | ||
name = var.name | ||
auto_delete = false | ||
durable = true | ||
dead_letter_exchange = var.exchange | ||
dead_letter_routing_key = var.routing_key | ||
message_ttl = 4 | ||
lazy_mode = "lazy" | ||
} | ||
``` | ||
|
||
## 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 DMS RabbitMQ instance ID. | ||
Changing this creates a new resource. | ||
|
||
* `vhost` - (Required, String, ForceNew) Specifies the vhost name. | ||
Changing this creates a new resource. | ||
|
||
* `name` - (Required, String, ForceNew) Specifies the queue name. | ||
Changing this creates a new resource. | ||
|
||
* `auto_delete` - (Required, Bool, ForceNew) Specifies whether to enable auto delete. | ||
Changing this creates a new resource. | ||
|
||
* `durable` - (Optional, Bool, ForceNew) Specifies whether to enable durable. Defaults to **false**. | ||
Changing this creates a new resource. | ||
|
||
* `dead_letter_exchange` - (Optional, String, ForceNew) Specifies the name of the dead letter exchange. | ||
It's required when `dead_letter_routing_key` is specified. | ||
Changing this creates a new resource. | ||
|
||
* `dead_letter_routing_key` - (Optional, String, ForceNew) Specifies the routing key of the dead letter exchange. | ||
Changing this creates a new resource. | ||
|
||
* `message_ttl` - (Optional, Int, ForceNew) Specifies how long a message in this queue can be retained. | ||
Changing this creates a new resource. | ||
|
||
* `lazy_mode` - (Optional, String, ForceNew) Specifies the lazy mode. Valid value is **lazy**. | ||
Changing this creates a new resource. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The resource ID. | ||
|
||
* `consumers` - Indicates the connected consumers. | ||
|
||
* `messages` - Indicates the accumulated messages. | ||
|
||
* `policy` - Indicates the policy. | ||
|
||
* `consumer_details` - Indicates the details of subscribed consumers. | ||
The [consumer_details](#attrblock--consumer_details) structure is documented below. | ||
|
||
* `queue_bindings` - Indicates the bindings to this queue. | ||
The [queue_bindings](#attrblock--queue_bindings) structure is documented below. | ||
|
||
<a name="attrblock--consumer_details"></a> | ||
The `consumer_details` block supports: | ||
|
||
* `ack_required` - Indicates whether manual acknowledgement is enabled on the consumer client. | ||
|
||
* `channel_details` - Indicates the consumer connections. | ||
The [channel_details](#attrblock--consumer_details--channel_details) structure is documented below. | ||
|
||
* `consumer_tag` - Indicates the consumer tag. | ||
|
||
* `prefetch_count` - Indicates the consumer client preset value. | ||
|
||
<a name="attrblock--consumer_details--channel_details"></a> | ||
The `channel_details` block supports: | ||
|
||
* `connection_name` - Indicates the connection details. | ||
|
||
* `name` - Indicates the channel details | ||
|
||
* `number` - Indicates the channel quantity. | ||
|
||
* `peer_host` - Indicates the IP address of the connected consumer. | ||
|
||
* `peer_port` - Indicates the port of the process of the connected consumer. | ||
|
||
* `user` - Indicates the consumer username. If ACL is enabled, the real username will be returned, otherwise null will | ||
be returned. | ||
|
||
<a name="attrblock--queue_bindings"></a> | ||
The `queue_bindings` block supports: | ||
|
||
* `destination` - Indicates the binding target name. | ||
|
||
* `destination_type` - Indicates the binding target type. | ||
|
||
* `properties_key` - Indicates the URL-translated routing key. | ||
|
||
* `routing_key` - Indicates the binding key-value. | ||
|
||
* `source` - Indicates the exchange name. | ||
|
||
## Import | ||
|
||
The queue can be imported using `instance_id`, `vhost` and `name` separated by slashes, e.g. | ||
|
||
```bash | ||
$ terraform import huaweicloud_dms_rabbitmq_queue.test <instance_id>/<vhost>/<name> | ||
``` |
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
52 changes: 52 additions & 0 deletions
52
huaweicloud/services/acceptance/dms/data_source_huaweicloud_dms_rabbitmq_queues_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,52 @@ | ||
package dms | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" | ||
) | ||
|
||
func TestAccDataSourceDmsRabbitmqQueues_basic(t *testing.T) { | ||
dataSource := "data.huaweicloud_dms_rabbitmq_queues.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: testDataSourceDataSourceDmsRabbitmqQueues_basic(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
dc.CheckResourceExists(), | ||
resource.TestCheckResourceAttrSet(dataSource, "queues.#"), | ||
resource.TestCheckResourceAttrSet(dataSource, "queues.0.name"), | ||
resource.TestCheckResourceAttrSet(dataSource, "queues.0.auto_delete"), | ||
resource.TestCheckResourceAttrSet(dataSource, "queues.0.durable"), | ||
resource.TestCheckResourceAttrSet(dataSource, "queues.0.dead_letter_exchange"), | ||
resource.TestCheckResourceAttrSet(dataSource, "queues.0.dead_letter_routing_key"), | ||
resource.TestCheckResourceAttrSet(dataSource, "queues.0.message_ttl"), | ||
resource.TestCheckResourceAttrSet(dataSource, "queues.0.lazy_mode"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testDataSourceDataSourceDmsRabbitmqQueues_basic(name string) string { | ||
return fmt.Sprintf(` | ||
%s | ||
data "huaweicloud_dms_rabbitmq_queues" "test" { | ||
depends_on = [huaweicloud_dms_rabbitmq_queue.test] | ||
instance_id = huaweicloud_dms_rabbitmq_instance.test.id | ||
vhost = huaweicloud_dms_rabbitmq_vhost.test.name | ||
} | ||
`, testRabbitmqQueue_basic(name)) | ||
} |
99 changes: 99 additions & 0 deletions
99
huaweicloud/services/acceptance/dms/resource_huaweicloud_dms_rabbitmq_queue_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,99 @@ | ||
package dms | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
|
||
"github.com/chnsz/golangsdk" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils" | ||
) | ||
|
||
func getRabbitmqQueueResourceFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) { | ||
client, err := cfg.NewServiceClient("dmsv2", acceptance.HW_REGION_NAME) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating DMS client: %s", err) | ||
} | ||
|
||
getHttpUrl := "v2/rabbitmq/{project_id}/instances/{instance_id}/vhosts/{vhost}/queues/{queue}" | ||
getPath := client.Endpoint + getHttpUrl | ||
getPath = strings.ReplaceAll(getPath, "{project_id}", client.ProjectID) | ||
getPath = strings.ReplaceAll(getPath, "{instance_id}", state.Primary.Attributes["instance_id"]) | ||
getPath = strings.ReplaceAll(getPath, "{vhost}", state.Primary.Attributes["vhost"]) | ||
getPath = strings.ReplaceAll(getPath, "{queue}", state.Primary.Attributes["name"]) | ||
getOpt := golangsdk.RequestOpts{ | ||
KeepResponseBody: true, | ||
} | ||
|
||
getResp, err := client.Request("GET", getPath, &getOpt) | ||
if err != nil { | ||
return nil, fmt.Errorf("error retrieving queue: %s", err) | ||
} | ||
|
||
return utils.FlattenResponse(getResp) | ||
} | ||
|
||
func TestAccRabbitmqQueue_basic(t *testing.T) { | ||
var obj interface{} | ||
rName := acceptance.RandomAccResourceNameWithDash() | ||
resourceName := "huaweicloud_dms_rabbitmq_queue.test" | ||
rc := acceptance.InitResourceCheck( | ||
resourceName, | ||
&obj, | ||
getRabbitmqQueueResourceFunc, | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acceptance.TestAccPreCheck(t) }, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
CheckDestroy: rc.CheckResourceDestroy(), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testRabbitmqQueue_basic(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(resourceName, "name", rName), | ||
resource.TestCheckResourceAttr(resourceName, "auto_delete", "false"), | ||
resource.TestCheckResourceAttr(resourceName, "durable", "true"), | ||
resource.TestCheckResourceAttrPair(resourceName, "vhost", "huaweicloud_dms_rabbitmq_vhost.test", "name"), | ||
resource.TestCheckResourceAttrPair(resourceName, "instance_id", "huaweicloud_dms_rabbitmq_instance.test", "id"), | ||
resource.TestCheckResourceAttr(resourceName, "dead_letter_exchange", "amq.direct"), | ||
resource.TestCheckResourceAttr(resourceName, "dead_letter_routing_key", "binding"), | ||
resource.TestCheckResourceAttr(resourceName, "message_ttl", "4"), | ||
resource.TestCheckResourceAttr(resourceName, "lazy_mode", "lazy"), | ||
), | ||
}, | ||
{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testRabbitmqQueue_basic(rName string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
resource "huaweicloud_dms_rabbitmq_queue" "test" { | ||
depends_on = [huaweicloud_dms_rabbitmq_vhost.test] | ||
instance_id = huaweicloud_dms_rabbitmq_instance.test.id | ||
vhost = huaweicloud_dms_rabbitmq_vhost.test.name | ||
name = "%[2]s" | ||
auto_delete = false | ||
durable = true | ||
dead_letter_exchange = "amq.direct" | ||
dead_letter_routing_key = "binding" | ||
message_ttl = 4 | ||
lazy_mode = "lazy" | ||
} | ||
`, testRabbitmqVhost_basic(rName), rName) | ||
} |
Oops, something went wrong.