@@ -5,95 +5,95 @@ Example Usage
55
66```hcl
77
8- variable "availability_zone" {
9- default = "ap-guangzhou-3"
10- }
8+ variable "availability_zone" {
9+ default = "ap-guangzhou-3"
10+ }
1111
12- variable "cluster_cidr" {
13- default = "172.16.0.0/16"
14- }
12+ variable "cluster_cidr" {
13+ default = "172.16.0.0/16"
14+ }
1515
16- variable "default_instance_type" {
17- default = "S1.SMALL1"
18- }
16+ variable "default_instance_type" {
17+ default = "S1.SMALL1"
18+ }
1919
20- data "tencentcloud_images" "default" {
21- image_type = ["PUBLIC_IMAGE"]
22- os_name = "centos"
23- }
20+ data "tencentcloud_images" "default" {
21+ image_type = ["PUBLIC_IMAGE"]
22+ os_name = "centos"
23+ }
2424
25+ data "tencentcloud_vpc_subnets" "vpc" {
26+ is_default = true
27+ availability_zone = var.availability_zone
28+ }
2529
26- data "tencentcloud_vpc_subnets" "vpc" {
27- is_default = true
28- availability_zone = var.availability_zone
29- }
30+ data "tencentcloud_instance_types" "default" {
31+ filter {
32+ name = "instance-family"
33+ values = ["SA2"]
34+ }
3035
31- data "tencentcloud_instance_types" "default" {
32- filter {
33- name = "instance-family"
34- values = ["SA2"]
35- }
36+ cpu_core_count = 8
37+ memory_size = 16
38+ }
3639
37- cpu_core_count = 8
38- memory_size = 16
39- }
40+ resource "tencentcloud_instance" "foo" {
41+ instance_name = "tf-auto-test-1-1"
42+ availability_zone = var.availability_zone
43+ image_id = data.tencentcloud_images.default.images.0.image_id
44+ instance_type = var.default_instance_type
45+ system_disk_type = "CLOUD_PREMIUM"
46+ system_disk_size = 50
47+ }
4048
41- resource "tencentcloud_instance" "foo" {
42- instance_name = "tf-auto-test-1-1"
43- availability_zone = var.availability_zone
44- image_id = data.tencentcloud_images.default.images.0.image_id
45- instance_type = var.default_instance_type
46- system_disk_type = "CLOUD_PREMIUM"
47- system_disk_size = 50
48- }
49+ resource "tencentcloud_kubernetes_cluster" "managed_cluster" {
50+ vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
51+ cluster_cidr = "10.1.0.0/16"
52+ cluster_max_pod_num = 32
53+ cluster_name = "keep"
54+ cluster_desc = "test cluster desc"
55+ cluster_max_service_num = 32
4956
50- resource "tencentcloud_kubernetes_cluster" "managed_cluster" {
51- vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
52- cluster_cidr = "10.1.0.0/16"
53- cluster_max_pod_num = 32
54- cluster_name = "keep"
55- cluster_desc = "test cluster desc"
56- cluster_max_service_num = 32
57-
58- worker_config {
59- count = 1
60- availability_zone = var.availability_zone
61- instance_type = var.default_instance_type
62- system_disk_type = "CLOUD_SSD"
63- system_disk_size = 60
64- internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
65- internet_max_bandwidth_out = 100
66- public_ip_assigned = true
67- subnet_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.subnet_id
68-
69- data_disk {
70- disk_type = "CLOUD_PREMIUM"
71- disk_size = 50
72- }
73-
74- enhanced_security_service = false
75- enhanced_monitor_service = false
76- user_data = "dGVzdA=="
77- password = "ZZXXccvv1212"
78- }
79-
80- cluster_deploy_type = "MANAGED_CLUSTER"
81- }
57+ worker_config {
58+ count = 1
59+ availability_zone = var.availability_zone
60+ instance_type = var.default_instance_type
61+ system_disk_type = "CLOUD_SSD"
62+ system_disk_size = 60
63+ internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
64+ internet_max_bandwidth_out = 100
65+ public_ip_assigned = true
66+ subnet_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.subnet_id
8267
83- resource "tencentcloud_kubernetes_cluster_attachment" "test_attach" {
84- cluster_id = tencentcloud_kubernetes_cluster.managed_cluster.id
85- instance_id = tencentcloud_instance.foo.id
86- password = "Lo4wbdit"
68+ data_disk {
69+ disk_type = "CLOUD_PREMIUM"
70+ disk_size = 50
71+ }
8772
88- labels = {
89- "test1" = "test1",
90- "test2" = "test2",
91- }
73+ enhanced_security_service = false
74+ enhanced_monitor_service = false
75+ user_data = "dGVzdA=="
76+ password = "ZZXXccvv1212"
77+ }
78+
79+ cluster_deploy_type = "MANAGED_CLUSTER"
80+ }
81+
82+ resource "tencentcloud_kubernetes_cluster_attachment" "test_attach" {
83+ cluster_id = tencentcloud_kubernetes_cluster.managed_cluster.id
84+ instance_id = tencentcloud_instance.foo.id
85+ password = "Lo4wbdit"
86+
87+ labels = {
88+ "test1" = "test1",
89+ "test2" = "test2",
90+ }
91+
92+ worker_config_overrides {
93+ desired_pod_num = 8
94+ }
95+ }
9296
93- worker_config_overrides {
94- desired_pod_num = 8
95- }
96- }
9797```
9898*/
9999package tencentcloud
@@ -112,6 +112,101 @@ import (
112112 "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit"
113113)
114114
115+ func TKEGpuArgsSetting () map [string ]* schema.Schema {
116+ return map [string ]* schema.Schema {
117+ "mig_enable" : {
118+ Type : schema .TypeBool ,
119+ Optional : true ,
120+ Default : false ,
121+ Description : "Whether to enable MIG." ,
122+ },
123+ "driver" : {
124+ Type : schema .TypeMap ,
125+ Optional : true ,
126+ ValidateFunc : validateTkeGpuDriverVersion ,
127+ Elem : & schema.Resource {
128+ Schema : map [string ]* schema.Schema {
129+ "version" : {
130+ Type : schema .TypeString ,
131+ Required : true ,
132+ Description : "Version of GPU driver or CUDA." ,
133+ },
134+ "name" : {
135+ Type : schema .TypeString ,
136+ Required : true ,
137+ Description : "Name of GPU driver or CUDA." ,
138+ },
139+ },
140+ },
141+ Description : "GPU driver version." ,
142+ },
143+ "cuda" : {
144+ Type : schema .TypeMap ,
145+ Optional : true ,
146+ ValidateFunc : validateTkeGpuDriverVersion ,
147+ Elem : & schema.Resource {
148+ Schema : map [string ]* schema.Schema {
149+ "version" : {
150+ Type : schema .TypeString ,
151+ Required : true ,
152+ Description : "Version of GPU driver or CUDA." ,
153+ },
154+ "name" : {
155+ Type : schema .TypeString ,
156+ Required : true ,
157+ Description : "Name of GPU driver or CUDA." ,
158+ },
159+ },
160+ },
161+ Description : "CUDA version." ,
162+ },
163+ "cudnn" : {
164+ Type : schema .TypeMap ,
165+ Optional : true ,
166+ ValidateFunc : validateTkeGpuDriverVersion ,
167+ Elem : & schema.Resource {
168+ Schema : map [string ]* schema.Schema {
169+ "version" : {
170+ Type : schema .TypeString ,
171+ Required : true ,
172+ Description : "cuDNN version." ,
173+ },
174+ "name" : {
175+ Type : schema .TypeString ,
176+ Required : true ,
177+ Description : "cuDNN name." ,
178+ },
179+ "doc_name" : {
180+ Type : schema .TypeString ,
181+ Optional : true ,
182+ Description : "Doc name of cuDNN." ,
183+ },
184+ "dev_name" : {
185+ Type : schema .TypeString ,
186+ Optional : true ,
187+ Description : "Dev name of cuDNN." ,
188+ },
189+ },
190+ },
191+ Description : "cuDNN version." ,
192+ },
193+ "custom_driver" : {
194+ Type : schema .TypeMap ,
195+ Optional : true ,
196+ Elem : & schema.Resource {
197+ Schema : map [string ]* schema.Schema {
198+ "address" : {
199+ Type : schema .TypeString ,
200+ Optional : true ,
201+ Description : "URL of custom GPU driver address." ,
202+ },
203+ },
204+ },
205+ Description : "Custom GPU driver." ,
206+ },
207+ }
208+ }
209+
115210func TkeInstanceAdvancedSetting () map [string ]* schema.Schema {
116211 return map [string ]* schema.Schema {
117212 "mount_target" : {
@@ -206,6 +301,16 @@ func TkeInstanceAdvancedSetting() map[string]*schema.Schema {
206301 Optional : true ,
207302 Description : "Indicate to set desired pod number in node. valid when the cluster is podCIDR." ,
208303 },
304+ "gpu_args" : {
305+ Type : schema .TypeList ,
306+ Optional : true ,
307+ ForceNew : true ,
308+ MaxItems : 1 ,
309+ Elem : & schema.Resource {
310+ Schema : TKEGpuArgsSetting (),
311+ },
312+ Description : "GPU driver parameters." ,
313+ },
209314 }
210315}
211316
@@ -363,6 +468,51 @@ func tkeGetInstanceAdvancedPara(dMap map[string]interface{}, meta interface{}) (
363468 setting .ExtraArgs = & clusterExtraArgs
364469 }
365470
471+ // get gpu_args
472+ if v , ok := dMap ["gpu_args" ]; ok && len (v .([]interface {})) > 0 {
473+ gpuArgs := v .([]interface {})[0 ].(map [string ]interface {})
474+
475+ var (
476+ migEnable = gpuArgs ["mig_enable" ].(bool )
477+ driver = gpuArgs ["driver" ].(map [string ]interface {})
478+ cuda = gpuArgs ["cuda" ].(map [string ]interface {})
479+ cudnn = gpuArgs ["cudnn" ].(map [string ]interface {})
480+ customDriver = gpuArgs ["custom_driver" ].(map [string ]interface {})
481+ )
482+ tkeGpuArgs := tke.GPUArgs {}
483+ tkeGpuArgs .MIGEnable = & migEnable
484+ if len (driver ) > 0 {
485+ tkeGpuArgs .Driver = & tke.DriverVersion {
486+ Version : helper .String (driver ["version" ].(string )),
487+ Name : helper .String (driver ["name" ].(string )),
488+ }
489+ }
490+ if len (cuda ) > 0 {
491+ tkeGpuArgs .CUDA = & tke.DriverVersion {
492+ Version : helper .String (cuda ["version" ].(string )),
493+ Name : helper .String (cuda ["name" ].(string )),
494+ }
495+ }
496+ if len (cudnn ) > 0 {
497+ tkeGpuArgs .CUDNN = & tke.CUDNN {
498+ Version : helper .String (cudnn ["version" ].(string )),
499+ Name : helper .String (cudnn ["name" ].(string )),
500+ }
501+ if cudnn ["doc_name" ] != nil {
502+ tkeGpuArgs .CUDNN .DocName = helper .String (cudnn ["doc_name" ].(string ))
503+ }
504+ if cudnn ["dev_name" ] != nil {
505+ tkeGpuArgs .CUDNN .DevName = helper .String (cudnn ["dev_name" ].(string ))
506+ }
507+ }
508+ if len (customDriver ) > 0 {
509+ tkeGpuArgs .CustomDriver = & tke.CustomDriver {
510+ Address : helper .String (customDriver ["address" ].(string )),
511+ }
512+ }
513+ setting .GPUArgs = & tkeGpuArgs
514+ }
515+
366516 return setting
367517}
368518func resourceTencentCloudTkeClusterAttachmentRead (d * schema.ResourceData , meta interface {}) error {
0 commit comments