Skip to content

fix(tke): [118939719] support image_id params #2749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/2749.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_kubernetes_cluster_attachment: support `image_id`
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Code generated by iacg; DO NOT EDIT.
package tke

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

"image_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Description: "ID of Node image.",
},

"password": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -430,6 +437,10 @@ func resourceTencentCloudKubernetesClusterAttachmentCreate(d *schema.ResourceDat

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

if v, ok := d.GetOk("image_id"); ok {
request.ImageId = helper.String(v.(string))
}

loginSettings := tke.LoginSettings{}
if v, ok := d.GetOk("password"); ok {
loginSettings.Password = helper.String(v.(string))
Expand Down Expand Up @@ -636,6 +647,10 @@ func resourceTencentCloudKubernetesClusterAttachmentRead(d *schema.ResourceData,
_ = d.Set("security_groups", respData1.SecurityGroupIds)
}

if respData1.ImageId != nil {
_ = d.Set("image_id", respData1.ImageId)
}

var respData2 *tke.Instance
reqErr2 := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeKubernetesClusterAttachmentById2(ctx, instanceId, clusterId)
Expand Down
178 changes: 88 additions & 90 deletions tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,94 +3,92 @@ Provide a resource to attach an existing cvm to kubernetes cluster.
Example Usage

```hcl

variable "availability_zone" {
default = "ap-guangzhou-3"
}

variable "cluster_cidr" {
default = "172.16.0.0/16"
}

variable "default_instance_type" {
default = "S1.SMALL1"
}

data "tencentcloud_images" "default" {
image_type = ["PUBLIC_IMAGE"]
os_name = "centos"
}

data "tencentcloud_vpc_subnets" "vpc" {
is_default = true
availability_zone = var.availability_zone
}

data "tencentcloud_instance_types" "default" {
filter {
name = "instance-family"
values = ["SA2"]
}

cpu_core_count = 8
memory_size = 16
}

resource "tencentcloud_instance" "foo" {
instance_name = "tf-auto-test-1-1"
availability_zone = var.availability_zone
image_id = data.tencentcloud_images.default.images.0.image_id
instance_type = var.default_instance_type
system_disk_type = "CLOUD_PREMIUM"
system_disk_size = 50
}

resource "tencentcloud_kubernetes_cluster" "managed_cluster" {
vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
cluster_cidr = "10.1.0.0/16"
cluster_max_pod_num = 32
cluster_name = "keep"
cluster_desc = "test cluster desc"
cluster_max_service_num = 32

worker_config {
count = 1
availability_zone = var.availability_zone
instance_type = var.default_instance_type
system_disk_type = "CLOUD_SSD"
system_disk_size = 60
internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
internet_max_bandwidth_out = 100
public_ip_assigned = true
subnet_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.subnet_id

data_disk {
disk_type = "CLOUD_PREMIUM"
disk_size = 50
}

enhanced_security_service = false
enhanced_monitor_service = false
user_data = "dGVzdA=="
password = "ZZXXccvv1212"
}

cluster_deploy_type = "MANAGED_CLUSTER"
}

resource "tencentcloud_kubernetes_cluster_attachment" "test_attach" {
cluster_id = tencentcloud_kubernetes_cluster.managed_cluster.id
instance_id = tencentcloud_instance.foo.id
password = "Lo4wbdit"

labels = {
"test1" = "test1",
"test2" = "test2",
}

worker_config_overrides {
desired_pod_num = 8
}
}

variable "availability_zone" {
default = "ap-guangzhou-3"
}

variable "cluster_cidr" {
default = "172.16.0.0/16"
}

variable "default_instance_type" {
default = "S1.SMALL1"
}

data "tencentcloud_images" "default" {
image_type = ["PUBLIC_IMAGE"]
os_name = "centos"
}

data "tencentcloud_vpc_subnets" "vpc" {
is_default = true
availability_zone = var.availability_zone
}

data "tencentcloud_instance_types" "default" {
filter {
name = "instance-family"
values = ["SA2"]
}

cpu_core_count = 8
memory_size = 16
}

resource "tencentcloud_instance" "foo" {
instance_name = "tf-auto-test-1-1"
availability_zone = var.availability_zone
image_id = data.tencentcloud_images.default.images.0.image_id
instance_type = var.default_instance_type
system_disk_type = "CLOUD_PREMIUM"
system_disk_size = 50
}

resource "tencentcloud_kubernetes_cluster" "managed_cluster" {
vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
cluster_cidr = "10.1.0.0/16"
cluster_max_pod_num = 32
cluster_name = "keep"
cluster_desc = "test cluster desc"
cluster_max_service_num = 32

worker_config {
count = 1
availability_zone = var.availability_zone
instance_type = var.default_instance_type
system_disk_type = "CLOUD_SSD"
system_disk_size = 60
internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
internet_max_bandwidth_out = 100
public_ip_assigned = true
subnet_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.subnet_id

data_disk {
disk_type = "CLOUD_PREMIUM"
disk_size = 50
}

enhanced_security_service = false
enhanced_monitor_service = false
user_data = "dGVzdA=="
password = "ZZXXccvv1212"
}

cluster_deploy_type = "MANAGED_CLUSTER"
}

resource "tencentcloud_kubernetes_cluster_attachment" "test_attach" {
cluster_id = tencentcloud_kubernetes_cluster.managed_cluster.id
instance_id = tencentcloud_instance.foo.id
password = "Lo4wbdit"

labels = {
"test1" = "test1",
"test2" = "test2",
}

worker_config_overrides {
desired_pod_num = 8
}
}
```
1 change: 1 addition & 0 deletions website/docs/r/kubernetes_cluster_attachment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ The following arguments are supported:
* `cluster_id` - (Required, String, ForceNew) ID of the cluster.
* `instance_id` - (Required, String, ForceNew) ID of the CVM instance, this cvm will reinstall the system.
* `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 (-).
* `image_id` - (Optional, String, ForceNew) ID of Node image.
* `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.
* `labels` - (Optional, Map, ForceNew) Labels of tke attachment exits CVM.
* `password` - (Optional, String, ForceNew) Password to access, should be set if `key_ids` not set.
Expand Down
Loading