Skip to content

Commit d84f29c

Browse files
authored
fix(tke): [118939719] support image_id params (#2749)
* add * add * add
1 parent 0d2c7ba commit d84f29c

File tree

4 files changed

+108
-91
lines changed

4 files changed

+108
-91
lines changed

.changelog/2749.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_kubernetes_cluster_attachment: support `image_id`
3+
```

tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Code generated by iacg; DO NOT EDIT.
21
package tke
32

43
import (
@@ -36,6 +35,14 @@ func ResourceTencentCloudKubernetesClusterAttachment() *schema.Resource {
3635
Description: "ID of the CVM instance, this cvm will reinstall the system.",
3736
},
3837

38+
"image_id": {
39+
Type: schema.TypeString,
40+
Optional: true,
41+
Computed: true,
42+
ForceNew: true,
43+
Description: "ID of Node image.",
44+
},
45+
3946
"password": {
4047
Type: schema.TypeString,
4148
Optional: true,
@@ -430,6 +437,10 @@ func resourceTencentCloudKubernetesClusterAttachmentCreate(d *schema.ResourceDat
430437

431438
request.InstanceIds = []*string{helper.String(instanceId)}
432439

440+
if v, ok := d.GetOk("image_id"); ok {
441+
request.ImageId = helper.String(v.(string))
442+
}
443+
433444
loginSettings := tke.LoginSettings{}
434445
if v, ok := d.GetOk("password"); ok {
435446
loginSettings.Password = helper.String(v.(string))
@@ -636,6 +647,10 @@ func resourceTencentCloudKubernetesClusterAttachmentRead(d *schema.ResourceData,
636647
_ = d.Set("security_groups", respData1.SecurityGroupIds)
637648
}
638649

650+
if respData1.ImageId != nil {
651+
_ = d.Set("image_id", respData1.ImageId)
652+
}
653+
639654
var respData2 *tke.Instance
640655
reqErr2 := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
641656
result, e := service.DescribeKubernetesClusterAttachmentById2(ctx, instanceId, clusterId)

tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.md

Lines changed: 88 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -3,94 +3,92 @@ Provide a resource to attach an existing cvm to kubernetes cluster.
33
Example Usage
44

55
```hcl
6-
7-
variable "availability_zone" {
8-
default = "ap-guangzhou-3"
9-
}
10-
11-
variable "cluster_cidr" {
12-
default = "172.16.0.0/16"
13-
}
14-
15-
variable "default_instance_type" {
16-
default = "S1.SMALL1"
17-
}
18-
19-
data "tencentcloud_images" "default" {
20-
image_type = ["PUBLIC_IMAGE"]
21-
os_name = "centos"
22-
}
23-
24-
data "tencentcloud_vpc_subnets" "vpc" {
25-
is_default = true
26-
availability_zone = var.availability_zone
27-
}
28-
29-
data "tencentcloud_instance_types" "default" {
30-
filter {
31-
name = "instance-family"
32-
values = ["SA2"]
33-
}
34-
35-
cpu_core_count = 8
36-
memory_size = 16
37-
}
38-
39-
resource "tencentcloud_instance" "foo" {
40-
instance_name = "tf-auto-test-1-1"
41-
availability_zone = var.availability_zone
42-
image_id = data.tencentcloud_images.default.images.0.image_id
43-
instance_type = var.default_instance_type
44-
system_disk_type = "CLOUD_PREMIUM"
45-
system_disk_size = 50
46-
}
47-
48-
resource "tencentcloud_kubernetes_cluster" "managed_cluster" {
49-
vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
50-
cluster_cidr = "10.1.0.0/16"
51-
cluster_max_pod_num = 32
52-
cluster_name = "keep"
53-
cluster_desc = "test cluster desc"
54-
cluster_max_service_num = 32
55-
56-
worker_config {
57-
count = 1
58-
availability_zone = var.availability_zone
59-
instance_type = var.default_instance_type
60-
system_disk_type = "CLOUD_SSD"
61-
system_disk_size = 60
62-
internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
63-
internet_max_bandwidth_out = 100
64-
public_ip_assigned = true
65-
subnet_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.subnet_id
66-
67-
data_disk {
68-
disk_type = "CLOUD_PREMIUM"
69-
disk_size = 50
70-
}
71-
72-
enhanced_security_service = false
73-
enhanced_monitor_service = false
74-
user_data = "dGVzdA=="
75-
password = "ZZXXccvv1212"
76-
}
77-
78-
cluster_deploy_type = "MANAGED_CLUSTER"
79-
}
80-
81-
resource "tencentcloud_kubernetes_cluster_attachment" "test_attach" {
82-
cluster_id = tencentcloud_kubernetes_cluster.managed_cluster.id
83-
instance_id = tencentcloud_instance.foo.id
84-
password = "Lo4wbdit"
85-
86-
labels = {
87-
"test1" = "test1",
88-
"test2" = "test2",
89-
}
90-
91-
worker_config_overrides {
92-
desired_pod_num = 8
93-
}
94-
}
95-
6+
variable "availability_zone" {
7+
default = "ap-guangzhou-3"
8+
}
9+
10+
variable "cluster_cidr" {
11+
default = "172.16.0.0/16"
12+
}
13+
14+
variable "default_instance_type" {
15+
default = "S1.SMALL1"
16+
}
17+
18+
data "tencentcloud_images" "default" {
19+
image_type = ["PUBLIC_IMAGE"]
20+
os_name = "centos"
21+
}
22+
23+
data "tencentcloud_vpc_subnets" "vpc" {
24+
is_default = true
25+
availability_zone = var.availability_zone
26+
}
27+
28+
data "tencentcloud_instance_types" "default" {
29+
filter {
30+
name = "instance-family"
31+
values = ["SA2"]
32+
}
33+
34+
cpu_core_count = 8
35+
memory_size = 16
36+
}
37+
38+
resource "tencentcloud_instance" "foo" {
39+
instance_name = "tf-auto-test-1-1"
40+
availability_zone = var.availability_zone
41+
image_id = data.tencentcloud_images.default.images.0.image_id
42+
instance_type = var.default_instance_type
43+
system_disk_type = "CLOUD_PREMIUM"
44+
system_disk_size = 50
45+
}
46+
47+
resource "tencentcloud_kubernetes_cluster" "managed_cluster" {
48+
vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
49+
cluster_cidr = "10.1.0.0/16"
50+
cluster_max_pod_num = 32
51+
cluster_name = "keep"
52+
cluster_desc = "test cluster desc"
53+
cluster_max_service_num = 32
54+
55+
worker_config {
56+
count = 1
57+
availability_zone = var.availability_zone
58+
instance_type = var.default_instance_type
59+
system_disk_type = "CLOUD_SSD"
60+
system_disk_size = 60
61+
internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
62+
internet_max_bandwidth_out = 100
63+
public_ip_assigned = true
64+
subnet_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.subnet_id
65+
66+
data_disk {
67+
disk_type = "CLOUD_PREMIUM"
68+
disk_size = 50
69+
}
70+
71+
enhanced_security_service = false
72+
enhanced_monitor_service = false
73+
user_data = "dGVzdA=="
74+
password = "ZZXXccvv1212"
75+
}
76+
77+
cluster_deploy_type = "MANAGED_CLUSTER"
78+
}
79+
80+
resource "tencentcloud_kubernetes_cluster_attachment" "test_attach" {
81+
cluster_id = tencentcloud_kubernetes_cluster.managed_cluster.id
82+
instance_id = tencentcloud_instance.foo.id
83+
password = "Lo4wbdit"
84+
85+
labels = {
86+
"test1" = "test1",
87+
"test2" = "test2",
88+
}
89+
90+
worker_config_overrides {
91+
desired_pod_num = 8
92+
}
93+
}
9694
```

website/docs/r/kubernetes_cluster_attachment.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ The following arguments are supported:
111111
* `cluster_id` - (Required, String, ForceNew) ID of the cluster.
112112
* `instance_id` - (Required, String, ForceNew) ID of the CVM instance, this cvm will reinstall the system.
113113
* `hostname` - (Optional, String, ForceNew) The host name of the attached instance. Dot (.) and dash (-) cannot be used as the first and last characters of HostName and cannot be used consecutively. Windows example: The length of the name character is [2, 15], letters (capitalization is not restricted), numbers and dashes (-) are allowed, dots (.) are not supported, and not all numbers are allowed. Examples of other types (Linux, etc.): The character length is [2, 60], and multiple dots are allowed. There is a segment between the dots. Each segment allows letters (with no limitation on capitalization), numbers and dashes (-).
114+
* `image_id` - (Optional, String, ForceNew) ID of Node image.
114115
* `key_ids` - (Optional, List: [`String`], ForceNew) The key pair to use for the instance, it looks like skey-16jig7tx, it should be set if `password` not set.
115116
* `labels` - (Optional, Map, ForceNew) Labels of tke attachment exits CVM.
116117
* `password` - (Optional, String, ForceNew) Password to access, should be set if `key_ids` not set.

0 commit comments

Comments
 (0)