11/*
22Provide a resource to configure kubernetes cluster app addons.
33
4+ ~> **NOTE**: Avoid to using legacy "1.0.0" version, leave the versions empty so we can fetch the latest while creating.
5+
46Example Usage
57
68```hcl
79
810resource "tencentcloud_kubernetes_addon_attachment" "addon_cbs" {
911 cluster_id = "cls-xxxxxxxx"
1012 name = "cbs"
11- version = "1.0.0 "
13+ # version = "1.0.5 "
1214 values = [
1315 "rootdir=/var/lib/kubelet"
1416 ]
@@ -17,7 +19,7 @@ resource "tencentcloud_kubernetes_addon_attachment" "addon_cbs" {
1719resource "tencentcloud_kubernetes_addon_attachment" "addon_tcr" {
1820 cluster_id = "cls-xxxxxxxx"
1921 name = "tcr"
20- version = "1.0.0"
22+ # version = "1.0.0"
2123 values = [
2224 # imagePullSecretsCrs is an array which can configure image pull
2325 "global.imagePullSecretsCrs[0].name=unique-sample-vpc",
@@ -52,7 +54,7 @@ resource "tencentcloud_kubernetes_addon_attachment" "addon_cbs" {
5254 "spec":{
5355 "chart":{
5456 "chartName":"cbs",
55- "chartVersion":"1.0.0 "
57+ "chartVersion":"1.0.5 "
5658 },
5759 "values":{
5860 "rawValuesType":"yaml",
@@ -78,6 +80,7 @@ package tencentcloud
7880import (
7981 "context"
8082 "fmt"
83+ tke "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke/v20180525"
8184 "log"
8285 "strings"
8386
@@ -103,6 +106,7 @@ func resourceTencentCloudTkeAddonAttachment() *schema.Resource {
103106 "version" : {
104107 Type : schema .TypeString ,
105108 Optional : true ,
109+ Computed : true ,
106110 Description : "Addon version, default latest version. Conflict with `request_body`." ,
107111 ConflictsWith : []string {"request_body" },
108112 },
@@ -156,6 +160,21 @@ func resourceTencentCloudTkeAddonAttachmentCreate(d *schema.ResourceData, meta i
156160 reqBody = d .Get ("request_body" ).(string )
157161 )
158162
163+ if version == "" {
164+ request := tke .NewGetTkeAppChartListRequest ()
165+ chartList , err := service .GetTkeAppChartList (ctx , request )
166+ if err != nil {
167+ return fmt .Errorf ("error while fetching latest chart versions, %s" , err .Error ())
168+ }
169+ for i := range chartList {
170+ chart := chartList [i ]
171+ if * chart .Name == addonName {
172+ version = * chart .LatestVersion
173+ break
174+ }
175+ }
176+ }
177+
159178 if reqBody == "" {
160179 var reqErr error
161180 v := helper .InterfacesStringsPoint (values )
0 commit comments