Skip to content

Commit b4ec81a

Browse files
authored
Fix/tdmq (#2033)
* fix/tdmq * fix/tdmq * fix/tdmq * fix/tdmq * fix/tdmq * fix/tdmq * fix/tdmq * fix/tdmq * fix/tdmq * fix/tdmq
1 parent b628786 commit b4ec81a

19 files changed

+427
-292
lines changed

.changelog/2033.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_tdmq_rocketmq_vip_instance: Cancel import
3+
```
4+
5+
```release-note:enhancement
6+
resource/tencentcloud_tdmq_namespace: Update `retention_policy` Parameters
7+
```

tencentcloud/data_source_tc_tdmq_environment_attributes.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,24 @@ Use this data source to query detailed information of tdmq environment_attribute
44
Example Usage
55
66
```hcl
7-
data "tencentcloud_tdmq_environment_attributes" "environment_attributes" {
8-
environment_id = "keep-ns"
9-
cluster_id = "pulsar-9n95ax58b9vn"
7+
data "tencentcloud_tdmq_environment_attributes" "example" {
8+
environment_id = tencentcloud_tdmq_namespace.example.environ_name
9+
cluster_id = tencentcloud_tdmq_instance.example.id
10+
}
11+
12+
resource "tencentcloud_tdmq_instance" "example" {
13+
cluster_name = "tf_example"
14+
remark = "remark."
15+
tags = {
16+
"createdBy" = "terraform"
17+
}
18+
}
19+
20+
resource "tencentcloud_tdmq_namespace" "example" {
21+
environ_name = "tf_example"
22+
msg_ttl = 300
23+
cluster_id = tencentcloud_tdmq_instance.example.id
24+
remark = "remark."
1025
}
1126
```
1227
*/

tencentcloud/data_source_tc_tdmq_environment_attributes_test.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,31 @@ func TestAccTencentCloudTdmqEnvironmentAttributesDataSource_basic(t *testing.T)
1818
{
1919
Config: testAccTdmqEnvironmentAttributesDataSource,
2020
Check: resource.ComposeTestCheckFunc(
21-
testAccCheckTencentCloudDataSourceID("data.tencentcloud_tdmq_environment_attributes.environment_attributes"),
21+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_tdmq_environment_attributes.example"),
2222
),
2323
},
2424
},
2525
})
2626
}
2727

2828
const testAccTdmqEnvironmentAttributesDataSource = `
29-
data "tencentcloud_tdmq_environment_attributes" "environment_attributes" {
30-
environment_id = "keep-ns"
31-
cluster_id = "pulsar-9n95ax58b9vn"
29+
data "tencentcloud_tdmq_environment_attributes" "example" {
30+
environment_id = tencentcloud_tdmq_namespace.example.environ_name
31+
cluster_id = tencentcloud_tdmq_instance.example.id
32+
}
33+
34+
resource "tencentcloud_tdmq_instance" "example" {
35+
cluster_name = "tf_example"
36+
remark = "remark."
37+
tags = {
38+
"createdBy" = "terraform"
39+
}
40+
}
41+
42+
resource "tencentcloud_tdmq_namespace" "example" {
43+
environ_name = "tf_example"
44+
msg_ttl = 300
45+
cluster_id = tencentcloud_tdmq_instance.example.id
46+
remark = "remark."
3247
}
3348
`

tencentcloud/resource_tc_tdmq_namespace.go

Lines changed: 78 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@ Provide a resource to create a tdmq namespace.
44
Example Usage
55
66
```hcl
7-
resource "tencentcloud_tdmq_instance" "foo" {
8-
cluster_name = "example"
9-
remark = "this is description."
7+
resource "tencentcloud_tdmq_instance" "example" {
8+
cluster_name = "tf_example"
9+
remark = "remark."
10+
tags = {
11+
"createdBy" = "terraform"
12+
}
1013
}
1114
12-
resource "tencentcloud_tdmq_namespace" "bar" {
13-
environ_name = "example"
14-
msg_ttl = 300
15-
cluster_id = "${tencentcloud_tdmq_instance.foo.id}"
16-
remark = "this is description."
15+
resource "tencentcloud_tdmq_namespace" "example" {
16+
environ_name = "tf_example"
17+
msg_ttl = 300
18+
cluster_id = tencentcloud_tdmq_instance.example.id
19+
retention_policy {
20+
time_in_minutes = 60
21+
size_in_mb = 10
22+
}
23+
remark = "remark."
1724
}
1825
```
1926
@@ -30,28 +37,14 @@ package tencentcloud
3037
import (
3138
"context"
3239
"fmt"
40+
"strings"
3341

3442
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
3543
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
3644
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
3745
tdmq "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq/v20200217"
3846
)
3947

40-
func RetentionPolicy() map[string]*schema.Schema {
41-
return map[string]*schema.Schema{
42-
"time_in_minutes": {
43-
Type: schema.TypeInt,
44-
Optional: true,
45-
Description: "the time of message to retain.",
46-
},
47-
"size_in_mb": {
48-
Type: schema.TypeInt,
49-
Optional: true,
50-
Description: "the size of message to retain.",
51-
},
52-
}
53-
}
54-
5548
func resourceTencentCloudTdmqNamespace() *schema.Resource {
5649
return &schema.Resource{
5750
Create: resourceTencentCloudTdmqNamespaceCreate,
@@ -84,9 +77,27 @@ func resourceTencentCloudTdmqNamespace() *schema.Resource {
8477
Description: "Description of the namespace.",
8578
},
8679
"retention_policy": {
87-
Type: schema.TypeMap,
80+
Type: schema.TypeList,
8881
Optional: true,
82+
Computed: true,
83+
MaxItems: 1,
8984
Description: "The Policy of message to retain. Format like: `{time_in_minutes: Int, size_in_mb: Int}`. `time_in_minutes`: the time of message to retain; `size_in_mb`: the size of message to retain.",
85+
Elem: &schema.Resource{
86+
Schema: map[string]*schema.Schema{
87+
"time_in_minutes": {
88+
Type: schema.TypeInt,
89+
Optional: true,
90+
Computed: true,
91+
Description: "the time of message to retain.",
92+
},
93+
"size_in_mb": {
94+
Type: schema.TypeInt,
95+
Optional: true,
96+
Computed: true,
97+
Description: "the size of message to retain.",
98+
},
99+
},
100+
},
90101
},
91102
},
92103
}
@@ -125,20 +136,21 @@ func resourceTencentCloudTdmqNamespaceCreate(d *schema.ResourceData, meta interf
125136
}
126137

127138
if temp, ok := d.GetOk("retention_policy"); ok {
128-
v := temp.(map[string]interface{})
129-
timeInMinutes := int64(v["time_in_minutes"].(int))
130-
sizeInMb := int64(v["size_in_mb"].(int))
131-
132-
retentionPolicy.TimeInMinutes = &timeInMinutes
133-
retentionPolicy.SizeInMB = &sizeInMb
139+
policy := temp.([]interface{})
140+
for _, item := range policy {
141+
value := item.(map[string]interface{})
142+
timeInMinutes := int64(value["time_in_minutes"].(int))
143+
sizeInMB := int64(value["size_in_mb"].(int))
144+
retentionPolicy.TimeInMinutes = &timeInMinutes
145+
retentionPolicy.SizeInMB = &sizeInMB
146+
}
134147
}
135148
environId, err := tdmqService.CreateTdmqNamespace(ctx, environ_name, msg_ttl, clusterId, remark, retentionPolicy)
136149
if err != nil {
137150
return err
138151
}
139152

140-
d.SetId(environId)
141-
153+
d.SetId(strings.Join([]string{environId, clusterId}, FILED_SP))
142154
return resourceTencentCloudTdmqNamespaceRead(d, meta)
143155
}
144156

@@ -149,8 +161,12 @@ func resourceTencentCloudTdmqNamespaceRead(d *schema.ResourceData, meta interfac
149161
logId := getLogId(contextNil)
150162
ctx := context.WithValue(context.TODO(), logIdKey, logId)
151163

152-
environId := d.Id()
153-
clusterId := d.Get("cluster_id").(string)
164+
idSplit := strings.Split(d.Id(), FILED_SP)
165+
if len(idSplit) != 2 {
166+
return fmt.Errorf("id is broken,%s", idSplit)
167+
}
168+
environId := idSplit[0]
169+
clusterId := idSplit[1]
154170

155171
tdmqService := TdmqService{client: meta.(*TencentCloudClient).apiV3Conn}
156172

@@ -165,13 +181,16 @@ func resourceTencentCloudTdmqNamespaceRead(d *schema.ResourceData, meta interfac
165181
}
166182

167183
_ = d.Set("environ_name", info.EnvironmentId)
184+
_ = d.Set("cluster_id", clusterId)
168185
_ = d.Set("msg_ttl", info.MsgTTL)
169186
_ = d.Set("remark", info.Remark)
170187

188+
tmpList := make([]map[string]interface{}, 0)
171189
retentionPolicy := make(map[string]interface{}, 2)
172190
retentionPolicy["time_in_minutes"] = info.RetentionPolicy.TimeInMinutes
173191
retentionPolicy["size_in_mb"] = info.RetentionPolicy.SizeInMB
174-
_ = d.Set("retention_policy", retentionPolicy)
192+
tmpList = append(tmpList, retentionPolicy)
193+
_ = d.Set("retention_policy", tmpList)
175194
return nil
176195
})
177196
if err != nil {
@@ -186,15 +205,19 @@ func resourceTencentCloudTdmqNamespaceUpdate(d *schema.ResourceData, meta interf
186205
logId := getLogId(contextNil)
187206
ctx := context.WithValue(context.TODO(), logIdKey, logId)
188207

189-
environId := d.Id()
190-
clusterId := d.Get("cluster_id").(string)
208+
idSplit := strings.Split(d.Id(), FILED_SP)
209+
if len(idSplit) != 2 {
210+
return fmt.Errorf("id is broken,%s", idSplit)
211+
}
212+
environId := idSplit[0]
213+
clusterId := idSplit[1]
191214

192215
service := TdmqService{client: meta.(*TencentCloudClient).apiV3Conn}
193216

194217
var (
195-
msgTtl uint64
196-
remark string
197-
retentPolicy *tdmq.RetentionPolicy
218+
msgTtl uint64
219+
remark string
220+
retentionPolicy = new(tdmq.RetentionPolicy)
198221
)
199222

200223
old, now := d.GetChange("msg_ttl")
@@ -213,17 +236,19 @@ func resourceTencentCloudTdmqNamespaceUpdate(d *schema.ResourceData, meta interf
213236

214237
_, now = d.GetChange("retention_policy")
215238
if d.HasChange("retention_policy") {
216-
temp := now.(map[string]interface{})
217-
time := temp["time_in_minutes"].(int64)
218-
size := temp["size_in_mb"].(int64)
219-
retentPolicy = &tdmq.RetentionPolicy{
220-
TimeInMinutes: &time,
221-
SizeInMB: &size,
239+
policy := now.([]interface{})
240+
241+
for _, item := range policy {
242+
value := item.(map[string]interface{})
243+
timeInMinutes := int64(value["time_in_minutes"].(int))
244+
sizeInMB := int64(value["size_in_mb"].(int))
245+
retentionPolicy.TimeInMinutes = &timeInMinutes
246+
retentionPolicy.SizeInMB = &sizeInMB
222247
}
223248
}
224249

225250
d.Partial(true)
226-
if err := service.ModifyTdmqNamespaceAttribute(ctx, environId, msgTtl, remark, clusterId, retentPolicy); err != nil {
251+
if err := service.ModifyTdmqNamespaceAttribute(ctx, environId, msgTtl, remark, clusterId, retentionPolicy); err != nil {
227252
return err
228253
}
229254

@@ -237,8 +262,12 @@ func resourceTencentCloudTdmqNamespaceDelete(d *schema.ResourceData, meta interf
237262
logId := getLogId(contextNil)
238263
ctx := context.WithValue(context.TODO(), logIdKey, logId)
239264

240-
environId := d.Id()
241-
clusterId := d.Get("cluster_id").(string)
265+
idSplit := strings.Split(d.Id(), FILED_SP)
266+
if len(idSplit) != 2 {
267+
return fmt.Errorf("id is broken,%s", idSplit)
268+
}
269+
environId := idSplit[0]
270+
clusterId := idSplit[1]
242271

243272
service := TdmqService{client: meta.(*TencentCloudClient).apiV3Conn}
244273

tencentcloud/resource_tc_tdmq_namespace_role_attachment.go

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,36 @@ Provide a resource to create a TDMQ role.
44
Example Usage
55
66
```hcl
7-
resource "tencentcloud_tdmq_instance" "foo" {
8-
cluster_name = "example"
9-
remark = "this is description."
7+
resource "tencentcloud_tdmq_instance" "example" {
8+
cluster_name = "tf_example"
9+
remark = "remark."
10+
tags = {
11+
"createdBy" = "terraform"
12+
}
1013
}
1114
12-
resource "tencentcloud_tdmq_namespace" "bar" {
13-
environ_name = "example"
14-
msg_ttl = 300
15-
cluster_id = "${tencentcloud_tdmq_instance.foo.id}"
16-
remark = "this is description."
15+
resource "tencentcloud_tdmq_namespace" "example" {
16+
environ_name = "tf_example"
17+
msg_ttl = 300
18+
cluster_id = tencentcloud_tdmq_instance.example.id
19+
retention_policy {
20+
time_in_minutes = 60
21+
size_in_mb = 10
22+
}
23+
remark = "remark."
1724
}
1825
19-
resource "tencentcloud_tdmq_topic" "bar" {
20-
environ_id = "${tencentcloud_tdmq_namespace.bar.id}"
21-
topic_name = "example"
22-
partitions = 6
23-
topic_type = 0
24-
cluster_id = "${tencentcloud_tdmq_instance.foo.id}"
25-
remark = "this is description."
26+
resource "tencentcloud_tdmq_role" "example" {
27+
role_name = "tf_example"
28+
cluster_id = tencentcloud_tdmq_instance.example.id
29+
remark = "remark."
2630
}
2731
28-
resource "tencentcloud_tdmq_role" "bar" {
29-
role_name = "example"
30-
cluster_id = "${tencentcloud_tdmq_instance.foo.id}"
31-
remark = "this is description world"
32-
}
33-
34-
resource "tencentcloud_tdmq_namespace_role_attachment" "bar" {
35-
environ_id = "${tencentcloud_tdmq_namespace.bar.id}"
36-
role_name = "${tencentcloud_tdmq_role.bar.role_name}"
32+
resource "tencentcloud_tdmq_namespace_role_attachment" "example" {
33+
environ_id = tencentcloud_tdmq_namespace.example.environ_name
34+
role_name = tencentcloud_tdmq_role.example.role_name
3735
permissions = ["produce", "consume"]
38-
cluster_id = "${tencentcloud_tdmq_instance.foo.id}"
36+
cluster_id = tencentcloud_tdmq_instance.example.id
3937
}
4038
```
4139
*/

0 commit comments

Comments
 (0)