11/*
22Provides a resource to create a rocketmq 5.x instance
33
4+ ~> **NOTE:** It only support create postpaid rocketmq 5.x instance.
5+
46Example Usage
57
8+ Basic Instance
69```hcl
710resource "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 )
0 commit comments