Skip to content

Commit 114bb87

Browse files
authored
feat(lts/transfer): the resource supports new fields (#6915)
1 parent e0d1dd2 commit 114bb87

File tree

5 files changed

+369
-104
lines changed

5 files changed

+369
-104
lines changed

docs/resources/lts_transfer.md

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,38 @@ resource "huaweicloud_lts_transfer" "obs_agency" {
147147
}
148148
```
149149

150+
### Create a DMS transfer in JSON format
151+
152+
```hcl
153+
variable "lts_group_id" {}
154+
variable "lts_stream_id" {}
155+
variable "registered_kafka_instance_id" {}
156+
variable "kafka_topic" {}
157+
158+
resource "huaweicloud_lts_transfer" "test" {
159+
log_group_id = var.lts_group_id
160+
161+
log_streams {
162+
log_stream_id = lts_stream_id
163+
}
164+
165+
log_transfer_info {
166+
log_transfer_type = "DMS"
167+
log_transfer_mode = "realTime"
168+
log_storage_format = "JSON"
169+
log_transfer_status = "ENABLE"
170+
171+
log_transfer_detail {
172+
kafka_id = var.registered_kafka_instance_id
173+
kafka_topic = var.kafka_topic
174+
lts_tags = ["hostName", "collectTime"]
175+
stream_tags = ["all"]
176+
struct_fields = ["all"]
177+
}
178+
}
179+
}
180+
```
181+
150182
## Argument Reference
151183

152184
The following arguments are supported:
@@ -293,10 +325,25 @@ The `log_transfer_detail` block supports:
293325

294326
-> Before creating a DMS transfer task, register your Kafka instance with Kafka ID and Kafka topic first.
295327

328+
* `lts_tags` - (Optional, List) Specifies the list of built-in fields and custom tags to be transferred.
329+
If you want to transfer all built-in and specified fields in the log, you need to set it to **all**.
330+
331+
* `stream_tags` - (Optional, List) Specifies the list of stream tag fields to be transferred.
332+
If you want to transfer all stream tag fields in the log, you need to set it to **all**.
333+
334+
* `struct_fields` - (Optional, List) Specifies the list of structured fields to be transferred.
335+
If you want to transfer all fields in a log in the log, you need to set it to **all**.
336+
337+
-> 1. The `lts_tags`, `stream_tags` and `struct_fields` parameters are valid only for DMS transfer in JSON format.
338+
At least one of them must be set.
339+
340+
* `invalid_field_value` - (Optional, String) Specifies the value of the invalid field fill.
341+
296342
* `delivery_tags` - (Optional, List) The list of tag fields will be delivered when transferring.
297343
This field must contain the following host information: **hostIP**, **hostId**, **hostName**, **pathFile**, and **collectTime**.
298344
The common fields include **logStreamName**, **regionName**, **logGroupName**, and **projectId**, which are optional.
299-
The transfer tag: **streamTag**, which is optional.
345+
The transfer tag: **streamTag**, which is optional.
346+
This parameter is valid only for OBS or DIS transfer in JSON format.
300347

301348
## Attribute Reference
302349

@@ -306,10 +353,31 @@ In addition to all arguments above, the following attributes are exported:
306353

307354
* `log_group_name` - Log group name.
308355

356+
* `created_at` - The creation time of the log transfer, in RFC3339 format.
357+
309358
## Import
310359

311360
The LTS transfer task can be imported using the `id`, e.g.
312361

313362
```bash
314363
$ terraform import huaweicloud_lts_transfer.test <id>
315364
```
365+
366+
Note that the imported state may not be identical to your resource definition, due to some attributes missing from the
367+
API response.
368+
The missing attributes include: `log_transfer_info.0.log_transfer_detail.0.invalid_field_value`.
369+
It is generally recommended running `terraform plan` after importing the resource.
370+
You can then decide if changes should be applied to the resource, or the resource definition should be updated to
371+
align with the resource. Also you can ignore changes as below.
372+
373+
```hcl
374+
resource "huaweicloud_lts_transfer" "test" {
375+
...
376+
377+
lifecycle {
378+
ignore_changes = [
379+
log_transfer_info.0.log_transfer_detail.0.invalid_field_value
380+
]
381+
}
382+
}
383+
```

huaweicloud/services/acceptance/acceptance.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,9 @@ var (
599599
HW_LTS_CLUSTER_ID_ANOTHER = os.Getenv("HW_LTS_CLUSTER_ID_ANOTHER")
600600
HW_LTS_CLUSTER_NAME_ANOTHER = os.Getenv("HW_LTS_CLUSTER_NAME_ANOTHER")
601601
HW_LTS_ALARM_ACTION_RULE_NAME = os.Getenv("HW_LTS_ALARM_ACTION_RULE_NAME")
602+
// When registering Kafka using the huaweicloud_lts_register_kafka_instance resource, the interface may time out.
603+
// Therefore, use HW_LTS_REGISTERED_KAFKA_INSTANCE_ID instead.
604+
HW_LTS_REGISTERED_KAFKA_INSTANCE_ID = os.Getenv("HW_LTS_REGISTERED_KAFKA_INSTANCE_ID")
602605

603606
HW_VPCEP_SERVICE_ID = os.Getenv("HW_VPCEP_SERVICE_ID")
604607

@@ -2404,6 +2407,13 @@ func TestAccPreCheckLtsAlarmActionRuleName(t *testing.T) {
24042407
}
24052408
}
24062409

2410+
// lintignore:AT003
2411+
func TestAccPreCheckLtsDmsTransfer(t *testing.T) {
2412+
if HW_LTS_REGISTERED_KAFKA_INSTANCE_ID == "" {
2413+
t.Skip("HW_LTS_REGISTERED_KAFKA_INSTANCE_ID must be set for the acceptance test")
2414+
}
2415+
}
2416+
24072417
// lintignore:AT003
24082418
func TestAccPreCheckLtsKafkaInstanceIds(t *testing.T) {
24092419
if len(strings.Split(HW_LTS_KAFKA_INSTANCE_IDS, ",")) != 2 {

0 commit comments

Comments
 (0)