@@ -175,49 +175,32 @@ func resourceTencentCloudCkafkaTopicCreate(d *schema.ResourceData, meta interfac
175
175
ckafkcService = CkafkaService {
176
176
client : meta .(* TencentCloudClient ).apiV3Conn ,
177
177
}
178
- request = ckafka .NewCreateTopicRequest ()
179
- instanceId = d .Get ("instance_id" ).(string )
180
- topicName = d .Get ("topic_name" ).(string )
181
- cleanUpPolicy , note string
182
- syncReplicaMinNum , uncleanLeaderElection int64
183
- whiteListSwitch bool
184
- ipWhiteLists = d .Get ("ip_white_list" ).([]interface {})
185
- ipWhiteList = make ([]* string , 0 , len (ipWhiteLists ))
178
+ request = ckafka .NewCreateTopicRequest ()
179
+ instanceId = d .Get ("instance_id" ).(string )
180
+ topicName = d .Get ("topic_name" ).(string )
181
+ note string
182
+ ipWhiteLists = d .Get ("ip_white_list" ).([]interface {})
183
+ ipWhiteList = make ([]* string , 0 , len (ipWhiteLists ))
184
+ syncReplicaMinNum = int64 (d .Get ("sync_replica_min_num" ).(int ))
185
+ uncleanLeaderElection = d .Get ("unclean_leader_election_enable" ).(bool )
186
+ cleanUpPolicy = d .Get ("clean_up_policy" ).(string )
187
+ whiteListSwitch = d .Get ("enable_white_list" ).(bool )
188
+ retention = d .Get ("retention" ).(int )
186
189
)
187
190
for _ , value := range ipWhiteLists {
188
191
ipWhiteList = append (ipWhiteList , helper .String (value .(string )))
189
192
}
190
- if v , ok := d .GetOk ("sync_replica_min_num" ); ok {
191
- syncReplicaMinNum = int64 (v .(int ))
192
- request .MinInsyncReplicas = & syncReplicaMinNum
193
- }
194
- if v , ok := d .GetOk ("unclean_leader_election_enable" ); ok {
195
- uncleanLeaderElection = * helper .BoolToInt64Ptr (v .(bool ))
196
- request .UncleanLeaderElectionEnable = & uncleanLeaderElection
197
- }
198
- if v , ok := d .GetOk ("enable_white_list" ); ok {
199
- whiteListSwitch = v .(bool )
200
- request .EnableWhiteList = helper .BoolToInt64Ptr (whiteListSwitch )
201
- if whiteListSwitch {
202
- if len (ipWhiteList ) == 0 {
203
- return fmt .Errorf ("this Topic %s Create Failed, reason: ip whitelist switch is on, ip whitelist cannot be empty" , topicName )
204
- }
205
- request .IpWhiteList = ipWhiteList
193
+ request .EnableWhiteList = helper .BoolToInt64Ptr (whiteListSwitch )
194
+ if whiteListSwitch {
195
+ if len (ipWhiteList ) == 0 {
196
+ return fmt .Errorf ("this Topic %s Create Failed, reason: ip whitelist switch is on, ip whitelist cannot be empty" , topicName )
206
197
}
207
- }
208
- if v , ok := d .GetOk ("clean_up_policy" ); ok {
209
- cleanUpPolicy = v .(string )
210
- request .CleanUpPolicy = & cleanUpPolicy
198
+ request .IpWhiteList = ipWhiteList
211
199
}
212
200
if v , ok := d .GetOk ("note" ); ok {
213
201
note = v .(string )
214
202
request .Note = & note
215
203
}
216
- if v , ok := d .GetOk ("retention" ); ok {
217
- if v .(int ) != 0 {
218
- request .RetentionMs = helper .IntInt64 (v .(int ))
219
- }
220
- }
221
204
if v , ok := d .GetOk ("segment" ); ok {
222
205
if v .(int ) != 0 {
223
206
request .SegmentMs = helper .IntInt64 (v .(int ))
@@ -227,6 +210,10 @@ func resourceTencentCloudCkafkaTopicCreate(d *schema.ResourceData, meta interfac
227
210
request .TopicName = & topicName
228
211
request .PartitionNum = helper .IntInt64 (d .Get ("partition_num" ).(int ))
229
212
request .ReplicaNum = helper .IntInt64 (d .Get ("replica_num" ).(int ))
213
+ request .MinInsyncReplicas = & syncReplicaMinNum
214
+ request .UncleanLeaderElectionEnable = helper .BoolToInt64Ptr (uncleanLeaderElection )
215
+ request .CleanUpPolicy = & cleanUpPolicy
216
+ request .RetentionMs = helper .IntInt64 (retention )
230
217
//Before create topic,Check if kafka exists
231
218
_ , has , error := ckafkcService .DescribeInstanceById (ctx , instanceId )
232
219
if error != nil {
@@ -332,20 +319,13 @@ func resourceTencentCloudCkafkaTopicUpdate(d *schema.ResourceData, meta interfac
332
319
instanceId := d .Get ("instance_id" ).(string )
333
320
topicName := d .Get ("topic_name" ).(string )
334
321
whiteListSwitch := d .Get ("enable_white_list" ).(bool )
335
- var cleanUpPolicy , note string
336
- if v , ok := d .GetOk ("clean_up_policy" ); ok {
337
- cleanUpPolicy = v .(string )
338
- request .CleanUpPolicy = & cleanUpPolicy
339
- }
322
+ cleanUpPolicy := d .Get ("clean_up_policy" ).(string )
323
+ retention := d .Get ("retention" ).(int )
324
+ var note string
340
325
if v , ok := d .GetOk ("note" ); ok {
341
326
note = v .(string )
342
327
request .Note = & note
343
328
}
344
- if v , ok := d .GetOk ("retention" ); ok {
345
- if v .(int ) != 0 {
346
- request .RetentionMs = helper .IntInt64 (v .(int ))
347
- }
348
- }
349
329
if v , ok := d .GetOk ("segment" ); ok {
350
330
if v .(int ) != 0 {
351
331
request .SegmentMs = helper .IntInt64 (v .(int ))
@@ -356,6 +336,8 @@ func resourceTencentCloudCkafkaTopicUpdate(d *schema.ResourceData, meta interfac
356
336
request .EnableWhiteList = helper .BoolToInt64Ptr (whiteListSwitch )
357
337
request .MinInsyncReplicas = helper .IntInt64 (d .Get ("sync_replica_min_num" ).(int ))
358
338
request .UncleanLeaderElectionEnable = helper .BoolToInt64Ptr (d .Get ("unclean_leader_election_enable" ).(bool ))
339
+ request .CleanUpPolicy = & cleanUpPolicy
340
+ request .RetentionMs = helper .IntInt64 (retention )
359
341
if d .Get ("max_message_bytes" ).(int ) != 0 {
360
342
request .MaxMessageBytes = helper .IntInt64 (d .Get ("max_message_bytes" ).(int ))
361
343
}
0 commit comments