Skip to content

Commit 71e3353

Browse files
tongyimingmikatong
andauthored
fix rocketmq enable_public (#2134)
* fix rocketmq enable_public * add changelog * update * update --------- Co-authored-by: mikatong <mikatong@tencent.com>
1 parent e67e3bc commit 71e3353

8 files changed

+204
-48
lines changed

.changelog/2134.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/tencentcloud_trocket_rocketmq_instance: fix `enable_public` read problem
3+
```

tencentcloud/extension_trocket.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package tencentcloud
2+
3+
const (
4+
ENDPOINT_TYPE_PUBLIC = "PUBLIC"
5+
ENDPOINT_TYPE_VPC = "VPC"
6+
)

tencentcloud/resource_tc_ckafka_instance.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/*
22
Use this resource to create ckafka instance.
33
4-
~> **NOTE:** It only support create prepaid ckafka instance.
5-
64
Example Usage
75
86
Basic Instance

tencentcloud/resource_tc_trocket_rocketmq_instance.go

Lines changed: 78 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
11
/*
22
Provides a resource to create a rocketmq 5.x instance
33
4+
~> **NOTE:** It only support create postpaid rocketmq 5.x instance.
5+
46
Example Usage
57
8+
Basic Instance
69
```hcl
710
resource "tencentcloud_trocket_rocketmq_instance" "rocketmq_instance" {
811
instance_type = "EXPERIMENT"
9-
name = "test"
12+
name = "rocketmq-instance"
13+
sku_code = "experiment_500"
14+
remark = "remark"
15+
vpc_id = "vpc-xxxxxx"
16+
subnet_id = "subnet-xxxxxx"
17+
tags = {
18+
tag_key = "rocketmq"
19+
tag_value = "5.x"
20+
}
21+
}
22+
```
23+
24+
Enable Public Instance
25+
```hcl
26+
resource "tencentcloud_trocket_rocketmq_instance" "rocketmq_instance_public" {
27+
instance_type = "EXPERIMENT"
28+
name = "rocketmq-enable-public-instance"
1029
sku_code = "experiment_500"
11-
remark = "test"
30+
remark = "remark"
1231
vpc_id = "vpc-xxxxxx"
1332
subnet_id = "subnet-xxxxxx"
1433
tags = {
1534
tag_key = "rocketmq"
1635
tag_value = "5.x"
1736
}
37+
enable_public = true
38+
bandwidth = 1
1839
}
1940
```
2041
@@ -97,14 +118,14 @@ func resourceTencentCloudTrocketRocketmqInstance() *schema.Resource {
97118
Optional: true,
98119
Computed: true,
99120
Type: schema.TypeBool,
100-
Description: "Whether to enable the public network.",
121+
Description: "Whether to enable the public network. Must set `bandwidth` when `enable_public` equal true.",
101122
},
102123

103124
"bandwidth": {
104125
Optional: true,
105126
Computed: true,
106127
Type: schema.TypeInt,
107-
Description: "Public network bandwidth.",
128+
Description: "Public network bandwidth. `bandwidth` must be greater than zero when `enable_public` equal true.",
108129
},
109130

110131
"ip_rules": {
@@ -139,6 +160,18 @@ func resourceTencentCloudTrocketRocketmqInstance() *schema.Resource {
139160
Type: schema.TypeInt,
140161
Description: "Message retention time in hours.",
141162
},
163+
164+
"public_end_point": {
165+
Type: schema.TypeString,
166+
Computed: true,
167+
Description: "Public network access address.",
168+
},
169+
170+
"vpc_end_point": {
171+
Type: schema.TypeString,
172+
Computed: true,
173+
Description: "VPC access address.",
174+
},
142175
},
143176
}
144177
}
@@ -150,9 +183,11 @@ func resourceTencentCloudTrocketRocketmqInstanceCreate(d *schema.ResourceData, m
150183
logId := getLogId(contextNil)
151184
ctx := context.WithValue(context.TODO(), logIdKey, logId)
152185
var (
153-
request = trocket.NewCreateInstanceRequest()
154-
response = trocket.NewCreateInstanceResponse()
155-
instanceId string
186+
request = trocket.NewCreateInstanceRequest()
187+
response = trocket.NewCreateInstanceResponse()
188+
instanceId string
189+
enablePublic bool
190+
bandwidth int
156191
)
157192
if v, ok := d.GetOk("instance_type"); ok {
158193
request.InstanceType = helper.String(v.(string))
@@ -178,13 +213,18 @@ func resourceTencentCloudTrocketRocketmqInstanceCreate(d *schema.ResourceData, m
178213
request.VpcList = []*trocket.VpcInfo{&vpcInfo}
179214

180215
if v, ok := d.GetOkExists("enable_public"); ok {
181-
request.EnablePublic = helper.Bool(v.(bool))
216+
enablePublic = v.(bool)
217+
request.EnablePublic = helper.Bool(enablePublic)
182218
}
183219

184220
if v, ok := d.GetOkExists("bandwidth"); ok {
185-
request.Bandwidth = helper.IntInt64(v.(int))
221+
bandwidth = v.(int)
222+
request.Bandwidth = helper.IntInt64(bandwidth)
186223
}
187224

225+
if enablePublic && bandwidth <= 0 {
226+
return fmt.Errorf("`bandwidth` must be greater than zero when `enable_public` equal true.")
227+
}
188228
if v, ok := d.GetOk("ip_rules"); ok {
189229
for _, item := range v.([]interface{}) {
190230
dMap := item.(map[string]interface{})
@@ -281,40 +321,43 @@ func resourceTencentCloudTrocketRocketmqInstanceRead(d *schema.ResourceData, met
281321
_ = d.Set("remark", rocketmqInstance.Remark)
282322
}
283323

284-
if len(rocketmqInstance.EndpointList) != 0 {
285-
endpoint := rocketmqInstance.EndpointList[0]
286-
if endpoint.VpcId != nil {
287-
_ = d.Set("vpc_id", endpoint.VpcId)
288-
}
289-
290-
if endpoint.SubnetId != nil {
291-
_ = d.Set("subnet_id", endpoint.SubnetId)
324+
var enablePublic bool
325+
for _, endpoint := range rocketmqInstance.EndpointList {
326+
endpointType := endpoint.Type
327+
if endpointType == nil {
328+
continue
292329
}
293-
294-
if len(endpoint.IpRules) != 0 {
295-
ipRuleList := make([]interface{}, 0)
296-
for _, ipRule := range endpoint.IpRules {
297-
ipRuleMap := make(map[string]interface{})
298-
ipRuleMap["ip"] = ipRule.Ip
299-
ipRuleMap["allow"] = ipRule.Allow
300-
ipRuleMap["remark"] = ipRule.Remark
301-
ipRuleList = append(ipRuleList, ipRuleMap)
330+
if *endpointType == ENDPOINT_TYPE_PUBLIC {
331+
enablePublic = true
332+
if len(endpoint.IpRules) != 0 {
333+
ipRuleList := make([]interface{}, 0)
334+
for _, ipRule := range endpoint.IpRules {
335+
ipRuleMap := make(map[string]interface{})
336+
ipRuleMap["ip"] = ipRule.Ip
337+
ipRuleMap["allow"] = ipRule.Allow
338+
ipRuleMap["remark"] = ipRule.Remark
339+
ipRuleList = append(ipRuleList, ipRuleMap)
340+
}
341+
_ = d.Set("ip_rules", ipRuleList)
302342
}
303-
_ = d.Set("ip_rules", ipRuleList)
304-
}
305-
if endpoint.Bandwidth != nil {
306-
_ = d.Set("bandwidth", endpoint.Bandwidth)
343+
if endpoint.Bandwidth != nil {
344+
_ = d.Set("bandwidth", endpoint.Bandwidth)
345+
}
346+
_ = d.Set("public_end_point", endpoint.EndpointUrl)
307347
}
348+
if *endpointType == ENDPOINT_TYPE_VPC {
349+
if endpoint.VpcId != nil {
350+
_ = d.Set("vpc_id", endpoint.VpcId)
351+
}
308352

309-
if endpoint.Type != nil {
310-
if *endpoint.Type == "PUBLIC" {
311-
_ = d.Set("enable_public", true)
312-
} else {
313-
_ = d.Set("enable_public", true)
353+
if endpoint.SubnetId != nil {
354+
_ = d.Set("subnet_id", endpoint.SubnetId)
314355
}
356+
_ = d.Set("vpc_end_point", endpoint.EndpointUrl)
315357
}
316358

317359
}
360+
_ = d.Set("enable_public", enablePublic)
318361

319362
if rocketmqInstance.MessageRetention != nil {
320363
_ = d.Set("message_retention", rocketmqInstance.MessageRetention)

tencentcloud/resource_tc_trocket_rocketmq_instance_test.go

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,27 @@ func TestAccTencentCloudTrocketRocketmqInstanceResource_basic(t *testing.T) {
1414
Steps: []resource.TestStep{
1515
{
1616
Config: testAccTrocketRocketmqInstance,
17-
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_trocket_rocketmq_instance.rocketmq_instance", "id")),
17+
Check: resource.ComposeTestCheckFunc(
18+
resource.TestCheckResourceAttrSet("tencentcloud_trocket_rocketmq_instance.rocketmq_instance", "id"),
19+
resource.TestCheckResourceAttr("tencentcloud_trocket_rocketmq_instance.rocketmq_instance", "name", "rocketmq-instance"),
20+
resource.TestCheckResourceAttr("tencentcloud_trocket_rocketmq_instance.rocketmq_instance", "sku_code", "experiment_500"),
21+
resource.TestCheckResourceAttr("tencentcloud_trocket_rocketmq_instance.rocketmq_instance", "remark", "remark"),
22+
resource.TestCheckResourceAttrSet("tencentcloud_trocket_rocketmq_instance.rocketmq_instance", "vpc_end_point"),
23+
resource.TestCheckResourceAttr("tencentcloud_trocket_rocketmq_instance.rocketmq_instance", "tags.tag_key", "rocketmq"),
24+
resource.TestCheckResourceAttr("tencentcloud_trocket_rocketmq_instance.rocketmq_instance", "tags.tag_value", "5.x"),
25+
),
26+
},
27+
{
28+
Config: testAccTrocketRocketmqInstanceUpdate,
29+
Check: resource.ComposeTestCheckFunc(
30+
resource.TestCheckResourceAttrSet("tencentcloud_trocket_rocketmq_instance.rocketmq_instance", "id"),
31+
resource.TestCheckResourceAttr("tencentcloud_trocket_rocketmq_instance.rocketmq_instance", "name", "rocketmq-instance-update"),
32+
resource.TestCheckResourceAttr("tencentcloud_trocket_rocketmq_instance.rocketmq_instance", "sku_code", "experiment_500"),
33+
resource.TestCheckResourceAttr("tencentcloud_trocket_rocketmq_instance.rocketmq_instance", "remark", "remark update"),
34+
resource.TestCheckResourceAttrSet("tencentcloud_trocket_rocketmq_instance.rocketmq_instance", "vpc_end_point"),
35+
resource.TestCheckResourceAttr("tencentcloud_trocket_rocketmq_instance.rocketmq_instance", "tags.tag_key", "rocketmq"),
36+
resource.TestCheckResourceAttr("tencentcloud_trocket_rocketmq_instance.rocketmq_instance", "tags.tag_value", "5.x.x"),
37+
),
1838
},
1939
{
2040
ResourceName: "tencentcloud_trocket_rocketmq_instance.rocketmq_instance",
@@ -25,17 +45,75 @@ func TestAccTencentCloudTrocketRocketmqInstanceResource_basic(t *testing.T) {
2545
})
2646
}
2747

48+
func TestAccTencentCloudTrocketRocketmqInstanceResource_enablePublic(t *testing.T) {
49+
t.Parallel()
50+
resource.Test(t, resource.TestCase{
51+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
52+
Providers: testAccProviders,
53+
Steps: []resource.TestStep{
54+
{
55+
Config: testAccTrocketRocketmqInstancePublic,
56+
Check: resource.ComposeTestCheckFunc(
57+
resource.TestCheckResourceAttrSet("tencentcloud_trocket_rocketmq_instance.rocketmq_instance_public", "id"),
58+
resource.TestCheckResourceAttr("tencentcloud_trocket_rocketmq_instance.rocketmq_instance_public", "name", "rocketmq-enable-public-instance"),
59+
resource.TestCheckResourceAttr("tencentcloud_trocket_rocketmq_instance.rocketmq_instance_public", "enable_public", "true"),
60+
resource.TestCheckResourceAttr("tencentcloud_trocket_rocketmq_instance.rocketmq_instance_public", "bandwidth", "1"),
61+
resource.TestCheckResourceAttrSet("tencentcloud_trocket_rocketmq_instance.rocketmq_instance_public", "public_end_point"),
62+
resource.TestCheckResourceAttrSet("tencentcloud_trocket_rocketmq_instance.rocketmq_instance_public", "vpc_end_point"),
63+
),
64+
},
65+
{
66+
ResourceName: "tencentcloud_trocket_rocketmq_instance.rocketmq_instance_public",
67+
ImportState: true,
68+
ImportStateVerify: true,
69+
},
70+
},
71+
})
72+
}
73+
2874
const testAccTrocketRocketmqInstance = `
2975
resource "tencentcloud_trocket_rocketmq_instance" "rocketmq_instance" {
3076
instance_type = "EXPERIMENT"
31-
name = "test"
77+
name = "rocketmq-instance"
78+
sku_code = "experiment_500"
79+
remark = "remark"
80+
vpc_id = "vpc-3a9fo1k9"
81+
subnet_id = "subnet-8nby1yxg"
82+
tags = {
83+
tag_key = "rocketmq"
84+
tag_value = "5.x"
85+
}
86+
}
87+
`
88+
89+
const testAccTrocketRocketmqInstanceUpdate = `
90+
resource "tencentcloud_trocket_rocketmq_instance" "rocketmq_instance" {
91+
instance_type = "EXPERIMENT"
92+
name = "rocketmq-instance-update"
93+
sku_code = "experiment_500"
94+
remark = "remark update"
95+
vpc_id = "vpc-3a9fo1k9"
96+
subnet_id = "subnet-8nby1yxg"
97+
tags = {
98+
tag_key = "rocketmq"
99+
tag_value = "5.x.x"
100+
}
101+
}
102+
`
103+
104+
const testAccTrocketRocketmqInstancePublic = `
105+
resource "tencentcloud_trocket_rocketmq_instance" "rocketmq_instance_public" {
106+
instance_type = "EXPERIMENT"
107+
name = "rocketmq-enable-public-instance"
32108
sku_code = "experiment_500"
33-
remark = "test"
109+
remark = "remark"
34110
vpc_id = "vpc-3a9fo1k9"
35111
subnet_id = "subnet-8nby1yxg"
36112
tags = {
37113
tag_key = "rocketmq"
38114
tag_value = "5.x"
39115
}
116+
enable_public = true
117+
bandwidth = 1
40118
}
41119
`

tencentcloud/service_tencentcloud_trocket.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ func (me *TrocketService) TrocketRocketmqInstanceStateRefreshFunc(instanceId str
7373
if err != nil {
7474
return nil, "", err
7575
}
76-
76+
if *object.InstanceStatus == "RUNNING" {
77+
for _, endpoint := range object.EndpointList {
78+
if *endpoint.Status != "OPEN" {
79+
return object, "PROCESSING", nil
80+
}
81+
}
82+
}
7783
return object, helper.PString(object.InstanceStatus), nil
7884
}
7985
}

website/docs/r/ckafka_instance.html.markdown

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ description: |-
1111

1212
Use this resource to create ckafka instance.
1313

14-
~> **NOTE:** It only support create prepaid ckafka instance.
15-
1614
## Example Usage
1715

1816
### Basic Instance

0 commit comments

Comments
 (0)