Skip to content

Commit dba30df

Browse files
committed
feat(lts): add new resource supports kafka instance register to lts
1 parent 74da38b commit dba30df

5 files changed

+389
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
subcategory: "Log Tank Service (LTS)"
3+
layout: "huaweicloud"
4+
page_title: "HuaweiCloud: huaweicloud_lts_register_kafka_instance"
5+
description: |-
6+
Use this resource to register the Kafka instance to LTS within HuaweiCloud.
7+
---
8+
9+
10+
# huaweicloud_lts_register_kafka_instance
11+
12+
Use this resource to register the Kafka instance to LTS within HuaweiCloud.
13+
14+
-> 1. Before registering a Kafka instance, please configure the inbound rules of the security group to which the Kafka
15+
instance belongs. Please refer to the [document](https://support.huaweicloud.com/intl/en-us/usermanual-lts/lts_04_0043.html).
16+
<br>2. The same Kafka instance can only be registered once.
17+
<br>3. This resource is only a one-time action resource for registering the Kafka instance to LTS. Deleting this resource
18+
will not clear the corresponding request record, but will only remove the resource information from the tfstate file.
19+
20+
## Example Usage
21+
22+
```hcl
23+
variable "kafka_instance_id" {}
24+
variable "kafka_instance_name" {}
25+
variable "kafka_instance_access_user" {}
26+
variable "kafka_instance_access_password" {}
27+
28+
resource "huaweicloud_lts_register_kafka_instance" "test" {
29+
instance_id = var.kafka_instance_id
30+
kafka_name = var.kafka_instance_name
31+
32+
connect_info {
33+
user_name = var.kafka_instance_access_user
34+
pwd = var.kafka_instance_access_password
35+
}
36+
}
37+
```
38+
39+
## Argument Reference
40+
41+
The following arguments are supported:
42+
43+
* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
44+
If omitted, the provider-level region will be used. Changing this parameter will create a new resource.
45+
46+
* `instance_id` - (Required, String, NonUpdatable) Specifies the ID of the Kafka instance to be registered to the LTS.
47+
48+
* `kafka_name` - (Required, String, NonUpdatable) Specifies the name of the Kafka instance to be registered to the LTS.
49+
50+
* `connect_info` - (Optional, List, NonUpdatable) Specifies the connection information of the Kafka instance to be
51+
registered to the LTS.
52+
The [connect_info](#register_kafka_to_lts_connect_info) structure is documented below.
53+
This parameter is available and required only when the registered Kafka instance is encrypted access.
54+
55+
<a name="register_kafka_to_lts_connect_info"></a>
56+
The `connect_info` block supports:
57+
58+
* `user_name` - (Optional, String, NonUpdatable) Specifies the name of the SASL_SSL user of the Kafka instance.
59+
60+
* `pwd` - (Optional, String, NonUpdatable) Specifies the password of the SASL_SSL user of the Kafka instance.
61+
62+
## Attribute Reference
63+
64+
In addition to all arguments above, the following attributes are exported:
65+
66+
* `id` - The resource ID.

huaweicloud/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -2072,6 +2072,7 @@ func Provider() *schema.Provider {
20722072
"huaweicloud_lts_log_converge": lts.ResourceLogConverge(),
20732073
"huaweicloud_lts_log_converge_switch": lts.ResourceLogConvergeSwitch(),
20742074
"huaweicloud_lts_metric_rule": lts.ResourceMetricRule(),
2075+
"huaweicloud_lts_register_kafka_instance": lts.ResourceRegisterKafkaInstance(),
20752076
"huaweicloud_lts_stream": lts.ResourceLTSStream(),
20762077
"huaweicloud_lts_structing_template": lts.ResourceStructConfig(),
20772078
"huaweicloud_lts_structuring_custom_configuration": lts.ResourceStructCustomConfig(),

huaweicloud/services/acceptance/acceptance.go

+20
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ var (
200200
HW_LTS_ENABLE_FLAG = os.Getenv("HW_LTS_ENABLE_FLAG")
201201
HW_LTS_STRUCT_CONFIG_TEMPLATE_ID = os.Getenv("HW_LTS_STRUCT_CONFIG_TEMPLATE_ID")
202202
HW_LTS_STRUCT_CONFIG_TEMPLATE_NAME = os.Getenv("HW_LTS_STRUCT_CONFIG_TEMPLATE_NAME")
203+
// Two Kafka instance IDs must be set, separated by a comma (,).
204+
// It consists of the Kafka instance ID connected via encrypted and the Kafka instance ID connected via plain text
205+
HW_LTS_KAFKA_INSTANCE_IDS = os.Getenv("HW_LTS_KAFKA_INSTANCE_IDS")
206+
HW_LTS_KAFKA_INSTANCE_PASSWORD = os.Getenv("HW_LTS_KAFKA_INSTANCE_PASSWORD")
203207

204208
HW_LIVE_STREAMING_DOMAIN_NAME = os.Getenv("HW_LIVE_STREAMING_DOMAIN_NAME")
205209
HW_LIVE_INGEST_RTMP_DOMAIN_NAME = os.Getenv("HW_LIVE_INGEST_RTMP_DOMAIN_NAME")
@@ -2078,6 +2082,22 @@ func TestAccPreCheckLtsStructConfigCustom(t *testing.T) {
20782082
}
20792083
}
20802084

2085+
// lintignore:AT003
2086+
func TestAccPreCheckLtsKafkaInstanceIds(t *testing.T) {
2087+
if len(strings.Split(HW_LTS_KAFKA_INSTANCE_IDS, ",")) != 2 {
2088+
t.Skip(`The Kafka instance is registered to LTS acceptance tests must set the Kafka instance IDs, plesse config them
2089+
in the HW_LTS_KAFKA_INSTANCE_IDS environment variable, and IDs consist of encrypted instance ID and plaintext instance ID,
2090+
separated by a commas (,)`)
2091+
}
2092+
}
2093+
2094+
// lintignore:AT003
2095+
func TestAccPreCheckLtsKafkaInstancePsw(t *testing.T) {
2096+
if HW_LTS_KAFKA_INSTANCE_PASSWORD == "" {
2097+
t.Skip("HW_LTS_KAFKA_INSTANCE_PASSWORD must be set for the encrypted access Kafka instance to be registered to the LTS acceptance test")
2098+
}
2099+
}
2100+
20812101
// lintignore:AT003
20822102
func TestAccPreCheckLiveStreamingDomainName(t *testing.T) {
20832103
if HW_LIVE_STREAMING_DOMAIN_NAME == "" {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
package lts
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
9+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
10+
)
11+
12+
func TestAccRegisterKafkaInstance_basic(t *testing.T) {
13+
name := acceptance.RandomAccResourceName()
14+
15+
resource.ParallelTest(t, resource.TestCase{
16+
PreCheck: func() {
17+
acceptance.TestAccPreCheck(t)
18+
acceptance.TestAccPreCheckLtsKafkaInstanceIds(t)
19+
acceptance.TestAccPreCheckLtsKafkaInstancePsw(t)
20+
},
21+
ProviderFactories: acceptance.TestAccProviderFactories,
22+
// This resource is a one-time action resource and there is no logic in the delete method.
23+
// lintignore:AT001
24+
CheckDestroy: nil,
25+
Steps: []resource.TestStep{
26+
{
27+
Config: resourceRegisterKafkaInstance_basic(name),
28+
},
29+
},
30+
})
31+
}
32+
33+
func resourceRegisterKafkaInstance_base(name string) string {
34+
return fmt.Sprintf(`
35+
resource "huaweicloud_lts_group" "test" {
36+
group_name = "%[1]s"
37+
ttl_in_days = 30
38+
}
39+
40+
resource "huaweicloud_lts_stream" "test" {
41+
group_id = huaweicloud_lts_group.test.id
42+
stream_name = "%[1]s"
43+
}
44+
`, name)
45+
}
46+
47+
func resourceRegisterKafkaInstance_verity(name string) string {
48+
return fmt.Sprintf(`
49+
resource "huaweicloud_dms_kafka_topic" "test" {
50+
instance_id = local.kafka_instance.id
51+
name = "%[1]s"
52+
partitions = 3
53+
}
54+
55+
resource "huaweicloud_lts_transfer" "test" {
56+
log_group_id = huaweicloud_lts_group.test.id
57+
58+
log_streams {
59+
log_stream_id = huaweicloud_lts_stream.test.id
60+
}
61+
62+
log_transfer_info {
63+
log_transfer_type = "DMS"
64+
log_transfer_mode = "realTime"
65+
log_storage_format = "RAW"
66+
log_transfer_status = "ENABLE"
67+
68+
log_transfer_detail {
69+
kafka_id = local.kafka_instance.id
70+
kafka_topic = huaweicloud_dms_kafka_topic.test.id
71+
}
72+
}
73+
74+
depends_on = [huaweicloud_lts_register_kafka_instance.test]
75+
}
76+
`, name)
77+
}
78+
79+
func resourceRegisterKafkaInstance_basic(name string) string {
80+
return fmt.Sprintf(`
81+
%[1]s
82+
83+
data "huaweicloud_dms_kafka_instances" test {
84+
instance_id = element(split(",", "%[2]s"), 0)
85+
}
86+
87+
locals {
88+
kafka_instance = data.huaweicloud_dms_kafka_instances.test.instances[0]
89+
}
90+
91+
resource "huaweicloud_lts_register_kafka_instance" "test" {
92+
instance_id = local.kafka_instance.id
93+
kafka_name = local.kafka_instance.name
94+
95+
connect_info {
96+
user_name = local.kafka_instance.access_user
97+
pwd = "%[3]s"
98+
}
99+
}
100+
101+
# Verify that the Kafka instance accessed by the encrypted data has been successfully registered to LTS.
102+
%[4]s
103+
`, resourceRegisterKafkaInstance_base(name),
104+
acceptance.HW_LTS_KAFKA_INSTANCE_IDS,
105+
acceptance.HW_LTS_KAFKA_INSTANCE_PASSWORD,
106+
resourceRegisterKafkaInstance_verity(name))
107+
}
108+
109+
func TestAccRegisterKafkaInstance_notSSL(t *testing.T) {
110+
name := acceptance.RandomAccResourceName()
111+
112+
resource.ParallelTest(t, resource.TestCase{
113+
PreCheck: func() {
114+
acceptance.TestAccPreCheck(t)
115+
acceptance.TestAccPreCheckLtsKafkaInstanceIds(t)
116+
},
117+
ProviderFactories: acceptance.TestAccProviderFactories,
118+
// lintignore:AT001
119+
CheckDestroy: nil,
120+
Steps: []resource.TestStep{
121+
{
122+
Config: resourceRegisterKafkaInstance_notSSL(name),
123+
},
124+
},
125+
})
126+
}
127+
128+
func resourceRegisterKafkaInstance_notSSL(name string) string {
129+
return fmt.Sprintf(`
130+
%[1]s
131+
132+
data "huaweicloud_dms_kafka_instances" test {
133+
instance_id = element(split(",", "%[2]s"), 1)
134+
}
135+
136+
locals {
137+
kafka_instance = data.huaweicloud_dms_kafka_instances.test.instances[0]
138+
}
139+
140+
resource "huaweicloud_lts_register_kafka_instance" "test" {
141+
instance_id = local.kafka_instance.id
142+
kafka_name = local.kafka_instance.name
143+
}
144+
145+
# Verify that the Kafka instance by plaintext access has been successfully registered to LTS.
146+
%[3]s
147+
`, resourceRegisterKafkaInstance_base(name),
148+
acceptance.HW_LTS_KAFKA_INSTANCE_IDS,
149+
resourceRegisterKafkaInstance_verity(name))
150+
}

0 commit comments

Comments
 (0)