Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat.] DMS: Add new resource opentelekomcloud_dms_consumer_group_v2 #2733

Merged
merged 7 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions docs/resources/dms_consumer_group_v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
subcategory: "Distributed Message Service (DMS)"
layout: "opentelekomcloud"
page_title: "OpenTelekomCloud: opentelekomcloud_dms_consumer_group_v2"
sidebar_current: "docs-opentelekomcloud-resource-dms-consumer-group-v2"
description: |-
Manages an up-to-date DMS Consumer Group v2 resource within OpenTelekomCloud.
---

Up-to-date reference of API arguments for DMS instance management you can get at
[documentation portal](https://docs.otc.t-systems.com/distributed-message-service/api-ref/apis_v2_recommended/instance_management/index.html)

# opentelekomcloud_dms_consumer_group_v2

Manage DMS consumer group v2 resource within OpenTelekomCloud.

## Example Usage

```hcl
variable "instance_id" {}

resource "opentelekomcloud_dms_consumer_group_v2" "group_1" {
instance_id = var.instance_id
group_name = "dms_consumer_group"
description = "Sample consumer group"
}
```

## Argument Reference

The following arguments are supported:

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

Changing this parameter will create a new resource.

* `group_name` - (Required, String, ForceNew) Specifies the name of the DMS consumer group.

Changing this parameter will create a new resource.

* `description` - (Optional, String, ForceNew) Specifies any description for the DMS consumer group.

Changing this parameter will create a new resource.

## Attribute Reference

In addition to all arguments above, the following attribute is exported:

* `state` - Indicates the Consumer group status. The value can be:
* Dead: The consumer group has no members and no metadata.
* Empty: The consumer group has metadata but has no members.
* PreparingRebalance: The consumer group is to be rebalanced.
* CompletingRebalance: All members have jointed the group.
* Stable: Members in the consumer group can consume messages normally.

* `assignment_strategy` - Indicates the partition assignment policy.
* `coordinator_id` - Indicates the coordinator ID.
* `members` - Indicates the consumer list. The structure is documented below.
* `group_message_offsets` - Indicates the consumer offset. The structure is documented below.

The `members` block contains:

* `host` - Indicates the consumer address.
* `member_id` - Indicates the consumer ID.
* `client_id` - Indicates the client ID.
* `assignments` - Indicates the details about the partition assigned to the consumer. The structure is as follows:
+ `topic` - Indicates the topic name.
+ `partitions` - Indicates the partition list.

The `group_message_offsets` block contains:

* `partition` - Indicates the partition number.
* `lag` - Indicates the number of remaining messages that can be retrieved, that is, the number of accumulated messages.
* `topic` - Indicates the topic name.
* `message_current_offset` - Indicates the consumer offset.
* `message_log_end_offset` - Indicates the log end offset (LEO).

## Import

DMS consumer groups can be imported using their `group_name` and related `instance_id`, separated by a slash, e.g.

```bash
$ terraform import opentelekomcloud_dms_consumer_group_v2.test_group <instance_id>/<group_name>
```
## Notes

But due to some attributes missing from the API response, it's required to ignore changes as below:

```hcl
resource "opentelekomcloud_dms_consumer_group_v2" "group_1" {
# ...

lifecycle {
ignore_changes = [
description,
]
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package acceptance

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/dms/v2/instances/management"

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

"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/common"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/env"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/cfg"
)

const resourceGroupV2Name = "opentelekomcloud_dms_consumer_group_v2.group_1"

func getDmsConsumerGroupResourceFunc(cfg *cfg.Config, state *terraform.ResourceState) (interface{}, error) {
client, err := cfg.DmsV2Client(env.OS_REGION_NAME)
if err != nil {
return nil, fmt.Errorf("error creating DMS V2 Client: %s", err)
}
getResp, err := management.GetConsumerGroup(client, state.Primary.Attributes["instance_id"], state.Primary.Attributes["group_name"])
if err != nil {
return nil, fmt.Errorf("error fetching dms group: %s", err)
}
return getResp.Group, nil
}

func TestAccDmsConsumerGroupV2_basic(t *testing.T) {
var dmsConsumerGroup management.Group
rc := common.InitResourceCheck(
resourceGroupV2Name,
&dmsConsumerGroup,
getDmsConsumerGroupResourceFunc,
)

var groupName = fmt.Sprintf("dms_consumer_group_%s", acctest.RandString(5))

resource.Test(t, resource.TestCase{
PreCheck: func() { common.TestAccPreCheck(t) },
ProviderFactories: common.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccDmsV2ConsumerGroupBasic(groupName),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceGroupV2Name, "group_name", groupName),
),
},
{
ResourceName: resourceGroupV2Name,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"description",
},
},
},
})
}

func testAccDmsV2ConsumerGroupBasic(groupName string) string {
return fmt.Sprintf(`
%s

%s

data "opentelekomcloud_dms_az_v1" "az_1" {}

data "opentelekomcloud_dms_product_v1" "product_1" {
engine = "kafka"
instance_type = "cluster"
version = "2.3.0"
}

resource "opentelekomcloud_dms_instance_v2" "instance_1" {
name = "dms_test_cg_instance"
engine = "kafka"
storage_space = data.opentelekomcloud_dms_product_v1.product_1.storage
access_user = "user"
password = "Dmstest@123"
vpc_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.vpc_id
security_group_id = data.opentelekomcloud_networking_secgroup_v2.default_secgroup.id
subnet_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.network_id
available_zones = [data.opentelekomcloud_dms_az_v1.az_1.id]
product_id = data.opentelekomcloud_dms_product_v1.product_1.id
engine_version = data.opentelekomcloud_dms_product_v1.product_1.version
storage_spec_code = data.opentelekomcloud_dms_product_v1.product_1.storage_spec_code
}

resource "opentelekomcloud_dms_consumer_group_v2" "group_1" {
instance_id = opentelekomcloud_dms_instance_v2.instance_1.id
group_name = "%s"
description = "Test consumer group"
}


`, common.DataSourceSecGroupDefault, common.DataSourceSubnet, groupName)
}
1 change: 1 addition & 0 deletions opentelekomcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ func Provider() *schema.Provider {
"opentelekomcloud_dns_ptrrecord_v2": dns.ResourceDNSPtrRecordV2(),
"opentelekomcloud_dns_recordset_v2": dns.ResourceDNSRecordSetV2(),
"opentelekomcloud_dns_zone_v2": dns.ResourceDNSZoneV2(),
"opentelekomcloud_dms_consumer_group_v2": dms.ResourceDmsConsumerGroupV2(),
"opentelekomcloud_dms_instance_v1": dms.ResourceDmsInstancesV1(),
"opentelekomcloud_dms_instance_v2": dms.ResourceDmsInstancesV2(),
"opentelekomcloud_dms_dedicated_instance_v2": dms.ResourceDmsDedicatedInstanceV2(),
Expand Down
Loading