Skip to content

Commit f07c1b7

Browse files
authored
feat(tke): [116205708]kubenetes clusters datasource add kube_config_file_prefix field (#2530)
* kubenetes clusters datasource add kube_config_file_prefix field * add changelog 2530.txt
1 parent 331b7f2 commit f07c1b7

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

.changelog/2530.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
datasource/tencentcloud_kubernetes_clusters: add `kube_config_file_prefix` field
3+
```

tencentcloud/services/tke/data_source_tc_kubernetes_clusters.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tke
22

33
import (
44
"context"
5+
"fmt"
56
"log"
67

78
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
@@ -227,6 +228,11 @@ func DataSourceTencentCloudKubernetesClusters() *schema.Resource {
227228
Optional: true,
228229
Description: "Used to save results.",
229230
},
231+
"kube_config_file_prefix": {
232+
Type: schema.TypeString,
233+
Optional: true,
234+
Description: "The path prefix of kube config. You can store KubeConfig in a specified directory by specifying this field, such as ~/.kube/k8s, then public network access will use ~/.kube/k8s-clusterID-kubeconfig naming, and intranet access will use ~/.kube /k8s-clusterID-kubeconfig-intranet naming. If this field is not set, the KubeConfig will not be exported.",
235+
},
230236

231237
"list": {
232238
Type: schema.TypeList,
@@ -251,8 +257,9 @@ func dataSourceTencentCloudKubernetesClustersRead(d *schema.ResourceData, meta i
251257
}
252258

253259
var (
254-
id string
255-
name string
260+
id string
261+
name string
262+
kubeConfigFilePrefix string
256263
)
257264

258265
if v, ok := d.GetOk("cluster_id"); ok {
@@ -290,6 +297,10 @@ func dataSourceTencentCloudKubernetesClustersRead(d *schema.ResourceData, meta i
290297
}
291298
}
292299

300+
if v, ok := d.GetOk("kube_config_file_prefix"); ok {
301+
kubeConfigFilePrefix = v.(string)
302+
}
303+
293304
LOOP:
294305
for _, info := range infos {
295306
if len(tags) > 0 {
@@ -410,6 +421,18 @@ LOOP:
410421

411422
infoMap["kube_config"] = config
412423
infoMap["kube_config_intranet"] = intranetConfig
424+
425+
if kubeConfigFilePrefix != "" {
426+
kubeConfigFile := kubeConfigFilePrefix + fmt.Sprintf("-%s-kubeconfig", info.ClusterId)
427+
if err = tccommon.WriteToFile(kubeConfigFile, config); err != nil {
428+
return err
429+
}
430+
kubeConfigIntranetFile := kubeConfigFilePrefix + fmt.Sprintf("-%s-kubeconfig-intranet", info.ClusterId)
431+
if err = tccommon.WriteToFile(kubeConfigIntranetFile, intranetConfig); err != nil {
432+
return err
433+
}
434+
}
435+
413436
list = append(list, infoMap)
414437
}
415438

website/docs/d/kubernetes_clusters.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ The following arguments are supported:
2929

3030
* `cluster_id` - (Optional, String) ID of the cluster. Conflict with cluster_name, can not be set at the same time.
3131
* `cluster_name` - (Optional, String) Name of the cluster. Conflict with cluster_id, can not be set at the same time.
32+
* `kube_config_file_prefix` - (Optional, String) The path prefix of kube config. You can store KubeConfig in a specified directory by specifying this field, such as ~/.kube/k8s, then public network access will use ~/.kube/k8s-clusterID-kubeconfig naming, and intranet access will use ~/.kube /k8s-clusterID-kubeconfig-intranet naming. If this field is not set, the KubeConfig will not be exported.
3233
* `result_output_file` - (Optional, String) Used to save results.
3334
* `tags` - (Optional, Map) Tags of the cluster.
3435

0 commit comments

Comments
 (0)