@@ -26,35 +26,35 @@ func ResourceTencentCloudTrocketRocketmqTopic() *schema.Resource {
26
26
},
27
27
Schema : map [string ]* schema.Schema {
28
28
"instance_id" : {
29
- Required : true ,
30
29
Type : schema .TypeString ,
30
+ Required : true ,
31
31
ForceNew : true ,
32
32
Description : "Instance Id." ,
33
33
},
34
34
35
35
"topic" : {
36
- Required : true ,
37
36
Type : schema .TypeString ,
37
+ Required : true ,
38
38
ForceNew : true ,
39
39
Description : "topic." ,
40
40
},
41
41
42
42
"topic_type" : {
43
+ Type : schema .TypeString ,
43
44
Required : true ,
44
45
ForceNew : true ,
45
- Type : schema .TypeString ,
46
46
Description : "Topic type. `UNSPECIFIED`: not specified, `NORMAL`: normal message, `FIFO`: sequential message, `DELAY`: delayed message." ,
47
47
},
48
48
49
49
"queue_num" : {
50
- Required : true ,
51
50
Type : schema .TypeInt ,
51
+ Required : true ,
52
52
Description : "Number of queue. Must be greater than or equal to 3." ,
53
53
},
54
54
55
55
"remark" : {
56
- Optional : true ,
57
56
Type : schema .TypeString ,
57
+ Optional : true ,
58
58
Description : "remark." ,
59
59
},
60
60
},
@@ -65,14 +65,14 @@ func resourceTencentCloudTrocketRocketmqTopicCreate(d *schema.ResourceData, meta
65
65
defer tccommon .LogElapsed ("resource.tencentcloud_trocket_rocketmq_topic.create" )()
66
66
defer tccommon .InconsistentCheck (d , meta )()
67
67
68
- logId := tccommon .GetLogId (tccommon .ContextNil )
69
-
70
68
var (
69
+ logId = tccommon .GetLogId (tccommon .ContextNil )
71
70
request = trocket .NewCreateTopicRequest ()
72
71
response = trocket .NewCreateTopicResponse ()
73
72
instanceId string
74
73
topic string
75
74
)
75
+
76
76
if v , ok := d .GetOk ("instance_id" ); ok {
77
77
request .InstanceId = helper .String (v .(string ))
78
78
}
@@ -100,35 +100,45 @@ func resourceTencentCloudTrocketRocketmqTopicCreate(d *schema.ResourceData, meta
100
100
} else {
101
101
log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
102
102
}
103
+
104
+ if result == nil || result .Response == nil {
105
+ return resource .NonRetryableError (fmt .Errorf ("Create trocket rocketmqTopic failed, Response is nil." ))
106
+ }
107
+
103
108
response = result
104
109
return nil
105
110
})
111
+
106
112
if err != nil {
107
113
log .Printf ("[CRITAL]%s create trocket rocketmqTopic failed, reason:%+v" , logId , err )
108
114
return err
109
115
}
110
116
117
+ if response .Response .InstanceId == nil || response .Response .Topic == nil {
118
+ return fmt .Errorf ("InstanceId or Topic is nil." )
119
+ }
120
+
111
121
instanceId = * response .Response .InstanceId
112
122
topic = * response .Response .Topic
113
- d .SetId (instanceId + tccommon .FILED_SP + topic )
114
-
123
+ d .SetId (strings .Join ([]string {instanceId , topic }, tccommon .FILED_SP ))
115
124
return resourceTencentCloudTrocketRocketmqTopicRead (d , meta )
116
125
}
117
126
118
127
func resourceTencentCloudTrocketRocketmqTopicRead (d * schema.ResourceData , meta interface {}) error {
119
128
defer tccommon .LogElapsed ("resource.tencentcloud_trocket_rocketmq_topic.read" )()
120
129
defer tccommon .InconsistentCheck (d , meta )()
121
130
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
+ )
127
136
128
137
idSplit := strings .Split (d .Id (), tccommon .FILED_SP )
129
138
if len (idSplit ) != 2 {
130
139
return fmt .Errorf ("id is broken,%s" , d .Id ())
131
140
}
141
+
132
142
instanceId := idSplit [0 ]
133
143
topic := idSplit [1 ]
134
144
@@ -138,8 +148,8 @@ func resourceTencentCloudTrocketRocketmqTopicRead(d *schema.ResourceData, meta i
138
148
}
139
149
140
150
if rocketmqTopic == nil {
141
- d .SetId ("" )
142
151
log .Printf ("[WARN]%s resource `TrocketRocketmqTopic` [%s] not found, please check if it has been deleted.\n " , logId , d .Id ())
152
+ d .SetId ("" )
143
153
return nil
144
154
}
145
155
@@ -170,44 +180,46 @@ func resourceTencentCloudTrocketRocketmqTopicUpdate(d *schema.ResourceData, meta
170
180
defer tccommon .LogElapsed ("resource.tencentcloud_trocket_rocketmq_topic.update" )()
171
181
defer tccommon .InconsistentCheck (d , meta )()
172
182
173
- logId := tccommon .GetLogId (tccommon .ContextNil )
174
-
175
- request := trocket .NewModifyTopicRequest ()
183
+ var (
184
+ logId = tccommon .GetLogId (tccommon .ContextNil )
185
+ request = trocket .NewModifyTopicRequest ()
186
+ )
176
187
177
188
idSplit := strings .Split (d .Id (), tccommon .FILED_SP )
178
189
if len (idSplit ) != 2 {
179
190
return fmt .Errorf ("id is broken,%s" , d .Id ())
180
191
}
192
+
181
193
instanceId := idSplit [0 ]
182
194
topic := idSplit [1 ]
183
195
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
186
199
187
- if d .HasChange ("queue_num" ) {
188
200
if v , ok := d .GetOkExists ("queue_num" ); ok {
189
201
request .QueueNum = helper .IntInt64 (v .(int ))
190
202
}
191
- }
192
203
193
- if d .HasChange ("remark" ) {
194
204
if v , ok := d .GetOk ("remark" ); ok {
195
205
request .Remark = helper .String (v .(string ))
196
206
}
197
- }
198
207
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
205
222
}
206
- return nil
207
- })
208
- if err != nil {
209
- log .Printf ("[CRITAL]%s update trocket rocketmqTopic failed, reason:%+v" , logId , err )
210
- return err
211
223
}
212
224
213
225
return resourceTencentCloudTrocketRocketmqTopicRead (d , meta )
@@ -217,14 +229,17 @@ func resourceTencentCloudTrocketRocketmqTopicDelete(d *schema.ResourceData, meta
217
229
defer tccommon .LogElapsed ("resource.tencentcloud_trocket_rocketmq_topic.delete" )()
218
230
defer tccommon .InconsistentCheck (d , meta )()
219
231
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
+ )
222
237
223
- service := TrocketService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
224
238
idSplit := strings .Split (d .Id (), tccommon .FILED_SP )
225
239
if len (idSplit ) != 2 {
226
240
return fmt .Errorf ("id is broken,%s" , d .Id ())
227
241
}
242
+
228
243
instanceId := idSplit [0 ]
229
244
topic := idSplit [1 ]
230
245
0 commit comments