1- // Code generated by iacg; DO NOT EDIT.
21package tke
32
43import (
@@ -28,12 +27,14 @@ func ResourceTencentCloudKubernetesHealthCheckPolicy() *schema.Resource {
2827 "cluster_id" : {
2928 Type : schema .TypeString ,
3029 Required : true ,
30+ ForceNew : true ,
3131 Description : "ID of the cluster." ,
3232 },
3333
3434 "name" : {
3535 Type : schema .TypeString ,
3636 Required : true ,
37+ ForceNew : true ,
3738 Description : "Health Check Policy Name." ,
3839 },
3940
@@ -69,115 +70,115 @@ func resourceTencentCloudKubernetesHealthCheckPolicyCreate(d *schema.ResourceDat
6970 defer tccommon .LogElapsed ("resource.tencentcloud_kubernetes_health_check_policy.create" )()
7071 defer tccommon .InconsistentCheck (d , meta )()
7172
72- logId := tccommon .GetLogId (tccommon .ContextNil )
73- 74- ctx := tccommon .NewResourceLifeCycleHandleFuncContext (context .Background (), logId , d , meta )
75- 7673 var (
74+ logId = tccommon .GetLogId (tccommon .ContextNil )
75+ ctx = tccommon .NewResourceLifeCycleHandleFuncContext (context .Background (), logId , d , meta )
76+ request = tkev20220501 .NewCreateHealthCheckPolicyRequest ()
77+ response = tkev20220501 .NewCreateHealthCheckPolicyResponse ()
7778 clusterId string
7879 name string
7980 )
80- var (
81- request = tkev20220501 .NewCreateHealthCheckPolicyRequest ()
82- response = tkev20220501 .NewCreateHealthCheckPolicyResponse ()
83- )
84- 85- if v , ok := d .GetOk ("cluster_id" ); ok {
86- clusterId = v .(string )
87- }
88- if v , ok := d .GetOk ("name" ); ok {
89- name = v .(string )
90- }
9181
9282 if v , ok := d .GetOk ("cluster_id" ); ok {
9383 request .ClusterId = helper .String (v .(string ))
84+ clusterId = v .(string )
9485 }
9586
9687 healthCheckPolicy := tkev20220501.HealthCheckPolicy {}
9788 if v , ok := d .GetOk ("name" ); ok {
9889 healthCheckPolicy .Name = helper .String (v .(string ))
9990 }
91+ 10092 if v , ok := d .GetOk ("rules" ); ok {
10193 for _ , item := range v .([]interface {}) {
10294 rulesMap := item .(map [string ]interface {})
10395 healthCheckPolicyRule := tkev20220501.HealthCheckPolicyRule {}
10496 if v , ok := rulesMap ["auto_repair_enabled" ]; ok {
10597 healthCheckPolicyRule .AutoRepairEnabled = helper .Bool (v .(bool ))
10698 }
99+ 107100 if v , ok := rulesMap ["enabled" ]; ok {
108101 healthCheckPolicyRule .Enabled = helper .Bool (v .(bool ))
109102 }
103+ 110104 if v , ok := rulesMap ["name" ]; ok {
111105 healthCheckPolicyRule .Name = helper .String (v .(string ))
112106 }
107+ 113108 healthCheckPolicy .Rules = append (healthCheckPolicy .Rules , & healthCheckPolicyRule )
114109 }
115110 }
116- request .HealthCheckPolicy = & healthCheckPolicy
117111
112+ request .HealthCheckPolicy = & healthCheckPolicy
118113 err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
119114 result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseTkeV20220501Client ().CreateHealthCheckPolicyWithContext (ctx , request )
120115 if e != nil {
121116 return tccommon .RetryError (e )
122117 } else {
123118 log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
124119 }
120+ 121+ if result == nil || result .Response == nil {
122+ return resource .NonRetryableError (fmt .Errorf ("Create kubernetes health check policy failed, Response is nil." ))
123+ }
124+ 125125 response = result
126126 return nil
127127 })
128+ 128129 if err != nil {
129130 log .Printf ("[CRITAL]%s create kubernetes health check policy failed, reason:%+v" , logId , err )
130131 return err
131132 }
132133
133- name = * response .Response .HealthCheckPolicyName
134+ if response .Response .HealthCheckPolicyName == nil {
135+ return fmt .Errorf ("HealthCheckPolicyName is nil." )
136+ }
134137
138+ name = * response .Response .HealthCheckPolicyName
135139 d .SetId (strings .Join ([]string {clusterId , name }, tccommon .FILED_SP ))
136- 137140 return resourceTencentCloudKubernetesHealthCheckPolicyRead (d , meta )
138141}
139142
140143func resourceTencentCloudKubernetesHealthCheckPolicyRead (d * schema.ResourceData , meta interface {}) error {
141144 defer tccommon .LogElapsed ("resource.tencentcloud_kubernetes_health_check_policy.read" )()
142145 defer tccommon .InconsistentCheck (d , meta )()
143146
144- logId := tccommon . GetLogId ( tccommon . ContextNil )
145- 146- ctx : = tccommon .NewResourceLifeCycleHandleFuncContext (context .Background (), logId , d , meta )
147- 148- service := TkeService { client : meta .(tccommon. ProviderMeta ). GetAPIV3Conn ()}
147+ var (
148+ logId = tccommon . GetLogId ( tccommon . ContextNil )
149+ ctx = tccommon .NewResourceLifeCycleHandleFuncContext (context .Background (), logId , d , meta )
150+ service = TkeService { client : meta .(tccommon. ProviderMeta ). GetAPIV3Conn ()}
151+ )
149152
150153 idSplit := strings .Split (d .Id (), tccommon .FILED_SP )
151154 if len (idSplit ) != 2 {
152155 return fmt .Errorf ("id is broken,%s" , d .Id ())
153156 }
157+ 154158 clusterId := idSplit [0 ]
155159 name := idSplit [1 ]
156160
157- _ = d .Set ("cluster_id" , clusterId )
158- 159- _ = d .Set ("name" , name )
160- 161161 respData , err := service .DescribeKubernetesHealthCheckPolicyById (ctx , clusterId , name )
162162 if err != nil {
163163 return err
164164 }
165165
166166 if respData == nil {
167+ log .Printf ("[WARN]%s resource `tencentcloud_kubernetes_health_check_policy` [%s] not found, please check if it has been deleted.\n " , logId , d .Id ())
167168 d .SetId ("" )
168- log .Printf ("[WARN]%s resource `kubernetes_health_check_policy` [%s] not found, please check if it has been deleted.\n " , logId , d .Id ())
169169 return nil
170170 }
171+ 172+ _ = d .Set ("cluster_id" , clusterId )
173+ 171174 if respData .Name != nil {
172175 _ = d .Set ("name" , respData .Name )
173- name = * respData .Name
174176 }
175177
176- rulesList := make ([]map [string ]interface {}, 0 , len (respData .Rules ))
177178 if respData .Rules != nil {
179+ rulesList := make ([]map [string ]interface {}, 0 , len (respData .Rules ))
178180 for _ , rules := range respData .Rules {
179181 rulesMap := map [string ]interface {}{}
180- 181182 if rules .AutoRepairEnabled != nil {
182183 rulesMap ["auto_repair_enabled" ] = rules .AutoRepairEnabled
183184 }
@@ -203,37 +204,21 @@ func resourceTencentCloudKubernetesHealthCheckPolicyUpdate(d *schema.ResourceDat
203204 defer tccommon .LogElapsed ("resource.tencentcloud_kubernetes_health_check_policy.update" )()
204205 defer tccommon .InconsistentCheck (d , meta )()
205206
206- logId := tccommon .GetLogId (tccommon .ContextNil )
207- 208- ctx := tccommon .NewResourceLifeCycleHandleFuncContext (context .Background (), logId , d , meta )
207+ var (
208+ logId = tccommon .GetLogId (tccommon .ContextNil )
209+ ctx = tccommon .NewResourceLifeCycleHandleFuncContext (context .Background (), logId , d , meta )
210+ )
209211
210- immutableArgs := []string {"cluster_id" , "name" }
211- for _ , v := range immutableArgs {
212- if d .HasChange (v ) {
213- return fmt .Errorf ("argument `%s` cannot be changed" , v )
214- }
215- }
216212 idSplit := strings .Split (d .Id (), tccommon .FILED_SP )
217213 if len (idSplit ) != 2 {
218214 return fmt .Errorf ("id is broken,%s" , d .Id ())
219215 }
216+ 220217 clusterId := idSplit [0 ]
221218 name := idSplit [1 ]
222219
223- needChange := false
224- mutableArgs := []string {"rules" }
225- for _ , v := range mutableArgs {
226- if d .HasChange (v ) {
227- needChange = true
228- break
229- }
230- }
231- 232- if needChange {
220+ if d .HasChange ("rules" ) {
233221 request := tkev20220501 .NewModifyHealthCheckPolicyRequest ()
234- 235- request .ClusterId = helper .String (clusterId )
236- 237222 healthCheckPolicy := tkev20220501.HealthCheckPolicy {}
238223 healthCheckPolicy .Name = helper .String (name )
239224 if v , ok := d .GetOk ("rules" ); ok {
@@ -243,26 +228,32 @@ func resourceTencentCloudKubernetesHealthCheckPolicyUpdate(d *schema.ResourceDat
243228 if v , ok := rulesMap ["auto_repair_enabled" ]; ok {
244229 healthCheckPolicyRule .AutoRepairEnabled = helper .Bool (v .(bool ))
245230 }
231+ 246232 if v , ok := rulesMap ["enabled" ]; ok {
247233 healthCheckPolicyRule .Enabled = helper .Bool (v .(bool ))
248234 }
235+ 249236 if v , ok := rulesMap ["name" ]; ok {
250237 healthCheckPolicyRule .Name = helper .String (v .(string ))
251238 }
239+ 252240 healthCheckPolicy .Rules = append (healthCheckPolicy .Rules , & healthCheckPolicyRule )
253241 }
254242 }
255- request .HealthCheckPolicy = & healthCheckPolicy
256243
244+ request .HealthCheckPolicy = & healthCheckPolicy
245+ request .ClusterId = helper .String (clusterId )
257246 err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
258247 result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseTkeV20220501Client ().ModifyHealthCheckPolicyWithContext (ctx , request )
259248 if e != nil {
260249 return tccommon .RetryError (e )
261250 } else {
262251 log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
263252 }
253+ 264254 return nil
265255 })
256+ 266257 if err != nil {
267258 log .Printf ("[CRITAL]%s update kubernetes health check policy failed, reason:%+v" , logId , err )
268259 return err
@@ -276,40 +267,37 @@ func resourceTencentCloudKubernetesHealthCheckPolicyDelete(d *schema.ResourceDat
276267 defer tccommon .LogElapsed ("resource.tencentcloud_kubernetes_health_check_policy.delete" )()
277268 defer tccommon .InconsistentCheck (d , meta )()
278269
279- logId := tccommon .GetLogId (tccommon .ContextNil )
280- ctx := tccommon .NewResourceLifeCycleHandleFuncContext (context .Background (), logId , d , meta )
270+ var (
271+ logId = tccommon .GetLogId (tccommon .ContextNil )
272+ ctx = tccommon .NewResourceLifeCycleHandleFuncContext (context .Background (), logId , d , meta )
273+ request = tkev20220501 .NewDeleteHealthCheckPolicyRequest ()
274+ )
281275
282276 idSplit := strings .Split (d .Id (), tccommon .FILED_SP )
283277 if len (idSplit ) != 2 {
284278 return fmt .Errorf ("id is broken,%s" , d .Id ())
285279 }
280+ 286281 clusterId := idSplit [0 ]
287282 name := idSplit [1 ]
288283
289- var (
290- request = tkev20220501 .NewDeleteHealthCheckPolicyRequest ()
291- response = tkev20220501 .NewDeleteHealthCheckPolicyResponse ()
292- )
293- 294284 request .ClusterId = helper .String (clusterId )
295- 296285 request .HealthCheckPolicyName = helper .String (name )
297- 298286 err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
299287 result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseTkeV20220501Client ().DeleteHealthCheckPolicyWithContext (ctx , request )
300288 if e != nil {
301289 return tccommon .RetryError (e )
302290 } else {
303291 log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
304292 }
305- response = result
293+ 306294 return nil
307295 })
296+ 308297 if err != nil {
309298 log .Printf ("[CRITAL]%s delete kubernetes health check policy failed, reason:%+v" , logId , err )
310299 return err
311300 }
312301
313- _ = response
314302 return nil
315303}
0 commit comments