diff --git a/.changelog/2749.txt b/.changelog/2749.txt new file mode 100644 index 0000000000..5e8b148efe --- /dev/null +++ b/.changelog/2749.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_kubernetes_cluster_attachment: support `image_id` +``` diff --git a/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.go b/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.go index 6f547479c5..e7dcba97e4 100644 --- a/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.go +++ b/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.go @@ -1,4 +1,3 @@ -// Code generated by iacg; DO NOT EDIT. package tke import ( @@ -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, @@ -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)) @@ -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) diff --git a/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.md b/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.md index 6e852b1b02..842572027a 100644 --- a/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.md +++ b/tencentcloud/services/tke/resource_tc_kubernetes_cluster_attachment.md @@ -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 + } +} ``` \ No newline at end of file diff --git a/website/docs/r/kubernetes_cluster_attachment.html.markdown b/website/docs/r/kubernetes_cluster_attachment.html.markdown index 285de6a14d..e6d6b67f34 100644 --- a/website/docs/r/kubernetes_cluster_attachment.html.markdown +++ b/website/docs/r/kubernetes_cluster_attachment.html.markdown @@ -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.