@@ -175,49 +175,32 @@ func resourceTencentCloudCkafkaTopicCreate(d *schema.ResourceData, meta interfac
175175 ckafkcService = CkafkaService {
176176 client : meta .(* TencentCloudClient ).apiV3Conn ,
177177 }
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 )
186189 )
187190 for _ , value := range ipWhiteLists {
188191 ipWhiteList = append (ipWhiteList , helper .String (value .(string )))
189192 }
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 )
206197 }
207- }
208- if v , ok := d .GetOk ("clean_up_policy" ); ok {
209- cleanUpPolicy = v .(string )
210- request .CleanUpPolicy = & cleanUpPolicy
198+ request .IpWhiteList = ipWhiteList
211199 }
212200 if v , ok := d .GetOk ("note" ); ok {
213201 note = v .(string )
214202 request .Note = & note
215203 }
216- if v , ok := d .GetOk ("retention" ); ok {
217- if v .(int ) != 0 {
218- request .RetentionMs = helper .IntInt64 (v .(int ))
219- }
220- }
221204 if v , ok := d .GetOk ("segment" ); ok {
222205 if v .(int ) != 0 {
223206 request .SegmentMs = helper .IntInt64 (v .(int ))
@@ -227,6 +210,10 @@ func resourceTencentCloudCkafkaTopicCreate(d *schema.ResourceData, meta interfac
227210 request .TopicName = & topicName
228211 request .PartitionNum = helper .IntInt64 (d .Get ("partition_num" ).(int ))
229212 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 )
230217 //Before create topic,Check if kafka exists
231218 _ , has , error := ckafkcService .DescribeInstanceById (ctx , instanceId )
232219 if error != nil {
@@ -332,20 +319,13 @@ func resourceTencentCloudCkafkaTopicUpdate(d *schema.ResourceData, meta interfac
332319 instanceId := d .Get ("instance_id" ).(string )
333320 topicName := d .Get ("topic_name" ).(string )
334321 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
340325 if v , ok := d .GetOk ("note" ); ok {
341326 note = v .(string )
342327 request .Note = & note
343328 }
344- if v , ok := d .GetOk ("retention" ); ok {
345- if v .(int ) != 0 {
346- request .RetentionMs = helper .IntInt64 (v .(int ))
347- }
348- }
349329 if v , ok := d .GetOk ("segment" ); ok {
350330 if v .(int ) != 0 {
351331 request .SegmentMs = helper .IntInt64 (v .(int ))
@@ -356,6 +336,8 @@ func resourceTencentCloudCkafkaTopicUpdate(d *schema.ResourceData, meta interfac
356336 request .EnableWhiteList = helper .BoolToInt64Ptr (whiteListSwitch )
357337 request .MinInsyncReplicas = helper .IntInt64 (d .Get ("sync_replica_min_num" ).(int ))
358338 request .UncleanLeaderElectionEnable = helper .BoolToInt64Ptr (d .Get ("unclean_leader_election_enable" ).(bool ))
339+ request .CleanUpPolicy = & cleanUpPolicy
340+ request .RetentionMs = helper .IntInt64 (retention )
359341 if d .Get ("max_message_bytes" ).(int ) != 0 {
360342 request .MaxMessageBytes = helper .IntInt64 (d .Get ("max_message_bytes" ).(int ))
361343 }
0 commit comments