@@ -26,35 +26,35 @@ func ResourceTencentCloudTrocketRocketmqTopic() *schema.Resource {
2626 },
2727 Schema : map [string ]* schema.Schema {
2828 "instance_id" : {
29- Required : true ,
3029 Type : schema .TypeString ,
30+ Required : true ,
3131 ForceNew : true ,
3232 Description : "Instance Id." ,
3333 },
3434
3535 "topic" : {
36- Required : true ,
3736 Type : schema .TypeString ,
37+ Required : true ,
3838 ForceNew : true ,
3939 Description : "topic." ,
4040 },
4141
4242 "topic_type" : {
43+ Type : schema .TypeString ,
4344 Required : true ,
4445 ForceNew : true ,
45- Type : schema .TypeString ,
4646 Description : "Topic type. `UNSPECIFIED`: not specified, `NORMAL`: normal message, `FIFO`: sequential message, `DELAY`: delayed message." ,
4747 },
4848
4949 "queue_num" : {
50- Required : true ,
5150 Type : schema .TypeInt ,
51+ Required : true ,
5252 Description : "Number of queue. Must be greater than or equal to 3." ,
5353 },
5454
5555 "remark" : {
56- Optional : true ,
5756 Type : schema .TypeString ,
57+ Optional : true ,
5858 Description : "remark." ,
5959 },
6060 },
@@ -65,14 +65,14 @@ func resourceTencentCloudTrocketRocketmqTopicCreate(d *schema.ResourceData, meta
6565 defer tccommon .LogElapsed ("resource.tencentcloud_trocket_rocketmq_topic.create" )()
6666 defer tccommon .InconsistentCheck (d , meta )()
6767
68- logId := tccommon .GetLogId (tccommon .ContextNil )
69-
7068 var (
69+ logId = tccommon .GetLogId (tccommon .ContextNil )
7170 request = trocket .NewCreateTopicRequest ()
7271 response = trocket .NewCreateTopicResponse ()
7372 instanceId string
7473 topic string
7574 )
75+
7676 if v , ok := d .GetOk ("instance_id" ); ok {
7777 request .InstanceId = helper .String (v .(string ))
7878 }
@@ -100,35 +100,45 @@ func resourceTencentCloudTrocketRocketmqTopicCreate(d *schema.ResourceData, meta
100100 } else {
101101 log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
102102 }
103+
104+ if result == nil || result .Response == nil {
105+ return resource .NonRetryableError (fmt .Errorf ("Create trocket rocketmqTopic failed, Response is nil." ))
106+ }
107+
103108 response = result
104109 return nil
105110 })
111+
106112 if err != nil {
107113 log .Printf ("[CRITAL]%s create trocket rocketmqTopic failed, reason:%+v" , logId , err )
108114 return err
109115 }
110116
117+ if response .Response .InstanceId == nil || response .Response .Topic == nil {
118+ return fmt .Errorf ("InstanceId or Topic is nil." )
119+ }
120+
111121 instanceId = * response .Response .InstanceId
112122 topic = * response .Response .Topic
113- d .SetId (instanceId + tccommon .FILED_SP + topic )
114-
123+ d .SetId (strings .Join ([]string {instanceId , topic }, tccommon .FILED_SP ))
115124 return resourceTencentCloudTrocketRocketmqTopicRead (d , meta )
116125}
117126
118127func resourceTencentCloudTrocketRocketmqTopicRead (d * schema.ResourceData , meta interface {}) error {
119128 defer tccommon .LogElapsed ("resource.tencentcloud_trocket_rocketmq_topic.read" )()
120129 defer tccommon .InconsistentCheck (d , meta )()
121130
122- logId := tccommon . GetLogId ( tccommon . ContextNil )
123-
124- ctx : = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
125-
126- service := TrocketService { client : meta .(tccommon. ProviderMeta ). GetAPIV3Conn ()}
131+ var (
132+ logId = tccommon . GetLogId ( tccommon . ContextNil )
133+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
134+ service = TrocketService { client : meta .(tccommon. ProviderMeta ). GetAPIV3Conn ()}
135+ )
127136
128137 idSplit := strings .Split (d .Id (), tccommon .FILED_SP )
129138 if len (idSplit ) != 2 {
130139 return fmt .Errorf ("id is broken,%s" , d .Id ())
131140 }
141+
132142 instanceId := idSplit [0 ]
133143 topic := idSplit [1 ]
134144
@@ -138,8 +148,8 @@ func resourceTencentCloudTrocketRocketmqTopicRead(d *schema.ResourceData, meta i
138148 }
139149
140150 if rocketmqTopic == nil {
141- d .SetId ("" )
142151 log .Printf ("[WARN]%s resource `TrocketRocketmqTopic` [%s] not found, please check if it has been deleted.\n " , logId , d .Id ())
152+ d .SetId ("" )
143153 return nil
144154 }
145155
@@ -170,44 +180,46 @@ func resourceTencentCloudTrocketRocketmqTopicUpdate(d *schema.ResourceData, meta
170180 defer tccommon .LogElapsed ("resource.tencentcloud_trocket_rocketmq_topic.update" )()
171181 defer tccommon .InconsistentCheck (d , meta )()
172182
173- logId := tccommon .GetLogId (tccommon .ContextNil )
174-
175- request := trocket .NewModifyTopicRequest ()
183+ var (
184+ logId = tccommon .GetLogId (tccommon .ContextNil )
185+ request = trocket .NewModifyTopicRequest ()
186+ )
176187
177188 idSplit := strings .Split (d .Id (), tccommon .FILED_SP )
178189 if len (idSplit ) != 2 {
179190 return fmt .Errorf ("id is broken,%s" , d .Id ())
180191 }
192+
181193 instanceId := idSplit [0 ]
182194 topic := idSplit [1 ]
183195
184- request .InstanceId = & instanceId
185- request .Topic = & topic
196+ if d .HasChange ("queue_num" ) || d .HasChange ("remark" ) {
197+ request .InstanceId = & instanceId
198+ request .Topic = & topic
186199
187- if d .HasChange ("queue_num" ) {
188200 if v , ok := d .GetOkExists ("queue_num" ); ok {
189201 request .QueueNum = helper .IntInt64 (v .(int ))
190202 }
191- }
192203
193- if d .HasChange ("remark" ) {
194204 if v , ok := d .GetOk ("remark" ); ok {
195205 request .Remark = helper .String (v .(string ))
196206 }
197- }
198207
199- err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
200- result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseTrocketClient ().ModifyTopic (request )
201- if e != nil {
202- return tccommon .RetryError (e )
203- } else {
204- log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
208+ err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
209+ result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseTrocketClient ().ModifyTopic (request )
210+ if e != nil {
211+ return tccommon .RetryError (e )
212+ } else {
213+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
214+ }
215+
216+ return nil
217+ })
218+
219+ if err != nil {
220+ log .Printf ("[CRITAL]%s update trocket rocketmqTopic failed, reason:%+v" , logId , err )
221+ return err
205222 }
206- return nil
207- })
208- if err != nil {
209- log .Printf ("[CRITAL]%s update trocket rocketmqTopic failed, reason:%+v" , logId , err )
210- return err
211223 }
212224
213225 return resourceTencentCloudTrocketRocketmqTopicRead (d , meta )
@@ -217,14 +229,17 @@ func resourceTencentCloudTrocketRocketmqTopicDelete(d *schema.ResourceData, meta
217229 defer tccommon .LogElapsed ("resource.tencentcloud_trocket_rocketmq_topic.delete" )()
218230 defer tccommon .InconsistentCheck (d , meta )()
219231
220- logId := tccommon .GetLogId (tccommon .ContextNil )
221- ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
232+ var (
233+ logId = tccommon .GetLogId (tccommon .ContextNil )
234+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
235+ service = TrocketService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
236+ )
222237
223- service := TrocketService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
224238 idSplit := strings .Split (d .Id (), tccommon .FILED_SP )
225239 if len (idSplit ) != 2 {
226240 return fmt .Errorf ("id is broken,%s" , d .Id ())
227241 }
242+
228243 instanceId := idSplit [0 ]
229244 topic := idSplit [1 ]
230245
0 commit comments