diff --git a/tencentcloud/resource_tc_cvm_launch_template.go b/tencentcloud/resource_tc_cvm_launch_template.go index a54bdd6340..a02829a66b 100644 --- a/tencentcloud/resource_tc_cvm_launch_template.go +++ b/tencentcloud/resource_tc_cvm_launch_template.go @@ -1,18 +1,21 @@ /* -Provides a resource to create a cvm launch_template +Provides a resource to create a cvm launch template Example Usage ```hcl +data "tencentcloud_images" "my_favorite_image" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} + resource "tencentcloud_cvm_launch_template" "demo" { launch_template_name = "test" placement { zone = "ap-guangzhou-6" project_id = 0 - host_ids = [] - host_ips = [] } - image_id = "img-xxxxxxxxx" + image_id = data.tencentcloud_images.my_favorite_image.images.0.image_id } ``` */ diff --git a/tencentcloud/resource_tc_instance.go b/tencentcloud/resource_tc_instance.go index 2d3d48baa9..e41c7a58b0 100644 --- a/tencentcloud/resource_tc_instance.go +++ b/tencentcloud/resource_tc_instance.go @@ -3,24 +3,24 @@ Provides a CVM instance resource. ~> **NOTE:** You can launch an CVM instance for a VPC network via specifying parameter `vpc_id`. One instance can only belong to one VPC. -~> **NOTE:** At present, 'PREPAID' instance cannot be deleted and must wait it to be outdated and released automatically. +~> **NOTE:** At present, 'PREPAID' instance cannot be deleted directly and must wait it to be outdated and released automatically. Example Usage ```hcl data "tencentcloud_images" "my_favorite_image" { image_type = ["PUBLIC_IMAGE"] - os_name = "Tencent Linux release 3.2 (Final)" + image_name_regex = "Final" } data "tencentcloud_instance_types" "my_favorite_instance_types" { filter { name = "instance-family" - values = ["S3"] + values = ["S1", "S2", "S3", "S4", "S5"] } - cpu_core_count = 1 - memory_size = 1 + cpu_core_count = 2 + exclude_sold_out = true } data "tencentcloud_availability_zones" "my_favorite_zones" { @@ -39,9 +39,9 @@ resource "tencentcloud_subnet" "app" { cidr_block = "10.0.1.0/24" } -// Create 2 CVM instances to host awesome_app -resource "tencentcloud_instance" "my_awesome_app" { - instance_name = "awesome_app" +// Create a POSTPAID_BY_HOUR CVM instance +resource "tencentcloud_instance" "cvm_postpaid" { + instance_name = "cvm_postpaid" availability_zone = data.tencentcloud_availability_zones.my_favorite_zones.zones.0.name image_id = data.tencentcloud_images.my_favorite_image.images.0.image_id instance_type = data.tencentcloud_instance_types.my_favorite_instance_types.instance_types.0.instance_type @@ -51,7 +51,6 @@ resource "tencentcloud_instance" "my_awesome_app" { project_id = 0 vpc_id = tencentcloud_vpc.app.id subnet_id = tencentcloud_subnet.app.id - count = 2 data_disks { data_disk_type = "CLOUD_PREMIUM" @@ -63,63 +62,30 @@ resource "tencentcloud_instance" "my_awesome_app" { tagKey = "tagValue" } } -``` - -Create CVM instance based on CDH -```hcl -variable "availability_zone" { - default = "ap-shanghai-4" -} -resource "tencentcloud_cdh_instance" "foo" { - availability_zone = var.availability_zone - host_type = "HM50" - charge_type = "PREPAID" +// Create a PREPAID CVM instance +resource "tencentcloud_instance" "cvm_prepaid" { + instance_name = "cvm_prepaid" + availability_zone = data.tencentcloud_availability_zones.my_favorite_zones.zones.0.name + image_id = data.tencentcloud_images.my_favorite_image.images.0.image_id + instance_type = data.tencentcloud_instance_types.my_favorite_instance_types.instance_types.0.instance_type + system_disk_type = "CLOUD_PREMIUM" + system_disk_size = 50 + hostname = "user" + project_id = 0 + vpc_id = tencentcloud_vpc.app.id + subnet_id = tencentcloud_subnet.app.id + instance_charge_type = "PREPAID" instance_charge_type_prepaid_period = 1 - hostname = "test" - prepaid_renew_flag = "DISABLE_NOTIFY_AND_MANUAL_RENEW" -} - -data "tencentcloud_cdh_instances" "list" { - availability_zone = var.availability_zone - host_id = tencentcloud_cdh_instance.foo.id - hostname = "test" - host_state = "RUNNING" -} - -resource "tencentcloud_key_pair" "random_key" { - key_ids = ["tf_example_key6"] - public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDjd8fTnp7Dcuj4mLaQxf9Zs/ORgUL9fQxRCNKkPgP1paTy1I513maMX126i36Lxxl3+FUB52oVbo/FgwlIfX8hyCnv8MCxqnuSDozf1CD0/wRYHcTWAtgHQHBPCC2nJtod6cVC3kB18KeV4U7zsxmwFeBIxojMOOmcOBuh7+trRw==" -} - -resource "tencentcloud_placement_group" "foo" { - name = "test" - type = "HOST" -} - -resource "tencentcloud_instance" "foo" { - availability_zone = var.availability_zone - instance_name = "terraform-testing" - image_id = "img-ix05e4px" - key_ids = [tencentcloud_key_pair.random_key.id] - placement_group_id = tencentcloud_placement_group.foo.id - security_groups = ["sg-9c3f33xk"] - system_disk_type = "CLOUD_PREMIUM" - - instance_charge_type = "CDHPAID" - cdh_instance_type = "CDH_10C10G" - cdh_host_id = tencentcloud_cdh_instance.foo.id - - vpc_id = "vpc-31zmeluu" - subnet_id = "subnet-aujc02np" - allocate_public_ip = true - internet_max_bandwidth_out = 2 - count = 3 - + instance_charge_type_prepaid_renew_flag = "NOTIFY_AND_MANUAL_RENEW" data_disks { data_disk_type = "CLOUD_PREMIUM" data_disk_size = 50 - encrypt = false + encrypt = false + } + force_delete = true + tags = { + tagKey = "tagValue" } } ``` diff --git a/website/docs/r/cvm_launch_template.html.markdown b/website/docs/r/cvm_launch_template.html.markdown index 10f7d4fb3c..28bed209a8 100644 --- a/website/docs/r/cvm_launch_template.html.markdown +++ b/website/docs/r/cvm_launch_template.html.markdown @@ -4,25 +4,28 @@ layout: "tencentcloud" page_title: "TencentCloud: tencentcloud_cvm_launch_template" sidebar_current: "docs-tencentcloud-resource-cvm_launch_template" description: |- - Provides a resource to create a cvm launch_template + Provides a resource to create a cvm launch template --- # tencentcloud_cvm_launch_template -Provides a resource to create a cvm launch_template +Provides a resource to create a cvm launch template ## Example Usage ```hcl +data "tencentcloud_images" "my_favorite_image" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} + resource "tencentcloud_cvm_launch_template" "demo" { launch_template_name = "test" placement { zone = "ap-guangzhou-6" project_id = 0 - host_ids = [] - host_ips = [] } - image_id = "img-xxxxxxxxx" + image_id = data.tencentcloud_images.my_favorite_image.images.0.image_id } ``` diff --git a/website/docs/r/instance.html.markdown b/website/docs/r/instance.html.markdown index 64a85d94af..efb0288e05 100644 --- a/website/docs/r/instance.html.markdown +++ b/website/docs/r/instance.html.markdown @@ -13,24 +13,24 @@ Provides a CVM instance resource. ~> **NOTE:** You can launch an CVM instance for a VPC network via specifying parameter `vpc_id`. One instance can only belong to one VPC. -~> **NOTE:** At present, 'PREPAID' instance cannot be deleted and must wait it to be outdated and released automatically. +~> **NOTE:** At present, 'PREPAID' instance cannot be deleted directly and must wait it to be outdated and released automatically. ## Example Usage ```hcl data "tencentcloud_images" "my_favorite_image" { - image_type = ["PUBLIC_IMAGE"] - os_name = "Tencent Linux release 3.2 (Final)" + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" } data "tencentcloud_instance_types" "my_favorite_instance_types" { filter { name = "instance-family" - values = ["S3"] + values = ["S1", "S2", "S3", "S4", "S5"] } - cpu_core_count = 1 - memory_size = 1 + cpu_core_count = 2 + exclude_sold_out = true } data "tencentcloud_availability_zones" "my_favorite_zones" { @@ -49,9 +49,9 @@ resource "tencentcloud_subnet" "app" { cidr_block = "10.0.1.0/24" } -// Create 2 CVM instances to host awesome_app -resource "tencentcloud_instance" "my_awesome_app" { - instance_name = "awesome_app" +// Create a POSTPAID_BY_HOUR CVM instance +resource "tencentcloud_instance" "cvm_postpaid" { + instance_name = "cvm_postpaid" availability_zone = data.tencentcloud_availability_zones.my_favorite_zones.zones.0.name image_id = data.tencentcloud_images.my_favorite_image.images.0.image_id instance_type = data.tencentcloud_instance_types.my_favorite_instance_types.instance_types.0.instance_type @@ -61,7 +61,6 @@ resource "tencentcloud_instance" "my_awesome_app" { project_id = 0 vpc_id = tencentcloud_vpc.app.id subnet_id = tencentcloud_subnet.app.id - count = 2 data_disks { data_disk_type = "CLOUD_PREMIUM" @@ -73,65 +72,31 @@ resource "tencentcloud_instance" "my_awesome_app" { tagKey = "tagValue" } } -``` - -### Create CVM instance based on CDH - -```hcl -variable "availability_zone" { - default = "ap-shanghai-4" -} - -resource "tencentcloud_cdh_instance" "foo" { - availability_zone = var.availability_zone - host_type = "HM50" - charge_type = "PREPAID" - instance_charge_type_prepaid_period = 1 - hostname = "test" - prepaid_renew_flag = "DISABLE_NOTIFY_AND_MANUAL_RENEW" -} - -data "tencentcloud_cdh_instances" "list" { - availability_zone = var.availability_zone - host_id = tencentcloud_cdh_instance.foo.id - hostname = "test" - host_state = "RUNNING" -} - -resource "tencentcloud_key_pair" "random_key" { - key_ids = ["tf_example_key6"] - public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDjd8fTnp7Dcuj4mLaQxf9Zs/ORgUL9fQxRCNKkPgP1paTy1I513maMX126i36Lxxl3+FUB52oVbo/FgwlIfX8hyCnv8MCxqnuSDozf1CD0/wRYHcTWAtgHQHBPCC2nJtod6cVC3kB18KeV4U7zsxmwFeBIxojMOOmcOBuh7+trRw==" -} - -resource "tencentcloud_placement_group" "foo" { - name = "test" - type = "HOST" -} - -resource "tencentcloud_instance" "foo" { - availability_zone = var.availability_zone - instance_name = "terraform-testing" - image_id = "img-ix05e4px" - key_ids = [tencentcloud_key_pair.random_key.id] - placement_group_id = tencentcloud_placement_group.foo.id - security_groups = ["sg-9c3f33xk"] - system_disk_type = "CLOUD_PREMIUM" - - instance_charge_type = "CDHPAID" - cdh_instance_type = "CDH_10C10G" - cdh_host_id = tencentcloud_cdh_instance.foo.id - - vpc_id = "vpc-31zmeluu" - subnet_id = "subnet-aujc02np" - allocate_public_ip = true - internet_max_bandwidth_out = 2 - count = 3 +// Create a PREPAID CVM instance +resource "tencentcloud_instance" "cvm_prepaid" { + instance_name = "cvm_prepaid" + availability_zone = data.tencentcloud_availability_zones.my_favorite_zones.zones.0.name + image_id = data.tencentcloud_images.my_favorite_image.images.0.image_id + instance_type = data.tencentcloud_instance_types.my_favorite_instance_types.instance_types.0.instance_type + system_disk_type = "CLOUD_PREMIUM" + system_disk_size = 50 + hostname = "user" + project_id = 0 + vpc_id = tencentcloud_vpc.app.id + subnet_id = tencentcloud_subnet.app.id + instance_charge_type = "PREPAID" + instance_charge_type_prepaid_period = 1 + instance_charge_type_prepaid_renew_flag = "NOTIFY_AND_MANUAL_RENEW" data_disks { data_disk_type = "CLOUD_PREMIUM" data_disk_size = 50 encrypt = false } + force_delete = true + tags = { + tagKey = "tagValue" + } } ```