From f5e34e7a6fbffcc3471319409453a960a5f9f9ff Mon Sep 17 00:00:00 2001 From: nickyinluo Date: Tue, 27 Jun 2023 10:45:03 +0800 Subject: [PATCH] add changelog and doc --- .../resource_tc_cynosdb_cluster_slave_zone.go | 99 ++++++++++++++++- ...urce_tc_cynosdb_cluster_slave_zone_test.go | 34 ++++-- .../cynosdb_cluster_slave_zone.html.markdown | 103 +++++++++++++++++- 3 files changed, 216 insertions(+), 20 deletions(-) diff --git a/tencentcloud/resource_tc_cynosdb_cluster_slave_zone.go b/tencentcloud/resource_tc_cynosdb_cluster_slave_zone.go index 5113d4ad4a..f7874dd144 100644 --- a/tencentcloud/resource_tc_cynosdb_cluster_slave_zone.go +++ b/tencentcloud/resource_tc_cynosdb_cluster_slave_zone.go @@ -1,12 +1,103 @@ /* -Provides a resource to create a cynosdb cluster_slave_zone +Provides a resource to create a cynosdb cluster slave zone. Example Usage +Set a new slave zone for a cynosdb cluster. ```hcl +locals { + vpc_id = data.tencentcloud_vpc_subnets.gz3.instance_list.0.vpc_id + subnet_id = data.tencentcloud_vpc_subnets.gz3.instance_list.0.subnet_id + sg_id = data.tencentcloud_security_groups.internal.security_groups.0.security_group_id + sg_id2 = data.tencentcloud_security_groups.exclusive.security_groups.0.security_group_id +} + +variable "fixed_tags" { + default = { + fixed_resource: "do_not_remove" + } +} + +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +variable "new_availability_zone" { + default = "ap-guangzhou-6" +} + +variable "my_param_template" { + default = "15765" +} + +data "tencentcloud_security_groups" "internal" { + name = "default" + tags = var.fixed_tags +} + +data "tencentcloud_security_groups" "exclusive" { + name = "test_preset_sg" +} + +data "tencentcloud_vpc_subnets" "gz3" { + availability_zone = var.default_az + is_default = true +} + +resource "tencentcloud_cynosdb_cluster" "instance" { + available_zone = var.availability_zone + vpc_id = local.vpc_id + subnet_id = local.subnet_id + db_type = "MYSQL" + db_version = "5.7" + storage_limit = 1000 + cluster_name = "tf_test_cynosdb_cluster_slave_zone" + password = "cynos@123" + instance_maintain_duration = 3600 + instance_maintain_start_time = 10800 + instance_maintain_weekdays = [ + "Fri", + "Mon", + "Sat", + "Sun", + "Thu", + "Wed", + "Tue", + ] + + instance_cpu_core = 1 + instance_memory_size = 2 + param_items { + name = "character_set_server" + current_value = "utf8" + } + param_items { + name = "time_zone" + current_value = "+09:00" + } + + force_delete = true + + rw_group_sg = [ + local.sg_id + ] + ro_group_sg = [ + local.sg_id + ] + prarm_template_id = var.my_param_template +} + +resource "tencentcloud_cynosdb_cluster_slave_zone" "cluster_slave_zone" { + cluster_id = tencentcloud_cynosdb_cluster.instance.id + slave_zone = var.new_availability_zone +} +``` + +Update the slave zone with specified value. +``` resource "tencentcloud_cynosdb_cluster_slave_zone" "cluster_slave_zone" { - cluster_id = "cynosdbmysql-xxxxxxxx" - slave_zone = "ap-guangzhou-3" + cluster_id = tencentcloud_cynosdb_cluster.instance.id + slave_zone = var.availability_zone } ``` @@ -15,7 +106,7 @@ Import cynosdb cluster_slave_zone can be imported using the id, e.g. ``` -terraform import tencentcloud_cynosdb_cluster_slave_zone.cluster_slave_zone cluster_slave_zone_id +terraform import tencentcloud_cynosdb_cluster_slave_zone.cluster_slave_zone cluster_id#slave_zone ``` */ package tencentcloud diff --git a/tencentcloud/resource_tc_cynosdb_cluster_slave_zone_test.go b/tencentcloud/resource_tc_cynosdb_cluster_slave_zone_test.go index c4f45108e2..d68ad88cb4 100644 --- a/tencentcloud/resource_tc_cynosdb_cluster_slave_zone_test.go +++ b/tencentcloud/resource_tc_cynosdb_cluster_slave_zone_test.go @@ -39,15 +39,27 @@ func TestAccTencentCloudCynosdbClusterSlaveZoneResource_basic(t *testing.T) { }) } -const testAccCynosdbClusterSlaveZone_instance = testAccCynosdbBasic + ` -resource "tencentcloud_cynosdb_cluster" "foo" { +const testAccCynosdbClusterSlaveZone_instance = defaultSecurityGroupData + defaultVpcSubnets + ` +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +variable "new_availability_zone" { + default = "ap-guangzhou-6" +} + +variable "my_param_template" { + default = "15765" +} + +resource "tencentcloud_cynosdb_cluster" "instance" { available_zone = var.availability_zone - vpc_id = var.my_vpc - subnet_id = var.my_subnet + vpc_id = local.vpc_id + subnet_id = local.subnet_id db_type = "MYSQL" db_version = "5.7" storage_limit = 1000 - cluster_name = "tf-cynosdb-salve-zone" + cluster_name = "tf_test_cynosdb_cluster_slave_zone" password = "cynos@123" instance_maintain_duration = 3600 instance_maintain_start_time = 10800 @@ -64,11 +76,11 @@ resource "tencentcloud_cynosdb_cluster" "foo" { instance_cpu_core = 1 instance_memory_size = 2 param_items { - name = "character_set_server" + name = "character_set_server" current_value = "utf8" } param_items { - name = "time_zone" + name = "time_zone" current_value = "+09:00" } @@ -87,8 +99,8 @@ resource "tencentcloud_cynosdb_cluster" "foo" { const testAccCynosdbClusterSlaveZone = testAccCynosdbClusterSlaveZone_instance + ` resource "tencentcloud_cynosdb_cluster_slave_zone" "cluster_slave_zone" { - cluster_id = tencentcloud_cynosdb_cluster.foo.id - slave_zone = "ap-guangzhou-6" + cluster_id = tencentcloud_cynosdb_cluster.instance.id + slave_zone = var.new_availability_zone } ` @@ -96,8 +108,8 @@ resource "tencentcloud_cynosdb_cluster_slave_zone" "cluster_slave_zone" { const testAccCynosdbClusterSlaveZone_update = testAccCynosdbClusterSlaveZone_instance + ` resource "tencentcloud_cynosdb_cluster_slave_zone" "cluster_slave_zone" { - cluster_id = tencentcloud_cynosdb_cluster.foo.id - slave_zone = "ap-guangzhou-4" + cluster_id = tencentcloud_cynosdb_cluster.instance.id + slave_zone = var.availability_zone } ` diff --git a/website/docs/r/cynosdb_cluster_slave_zone.html.markdown b/website/docs/r/cynosdb_cluster_slave_zone.html.markdown index fb407a6fec..7d190f35d6 100644 --- a/website/docs/r/cynosdb_cluster_slave_zone.html.markdown +++ b/website/docs/r/cynosdb_cluster_slave_zone.html.markdown @@ -4,19 +4,112 @@ layout: "tencentcloud" page_title: "TencentCloud: tencentcloud_cynosdb_cluster_slave_zone" sidebar_current: "docs-tencentcloud-resource-cynosdb_cluster_slave_zone" description: |- - Provides a resource to create a cynosdb cluster_slave_zone + Provides a resource to create a cynosdb cluster slave zone. --- # tencentcloud_cynosdb_cluster_slave_zone -Provides a resource to create a cynosdb cluster_slave_zone +Provides a resource to create a cynosdb cluster slave zone. ## Example Usage +Set a new slave zone for a cynosdb cluster. + +```hcl +locals { + vpc_id = data.tencentcloud_vpc_subnets.gz3.instance_list.0.vpc_id + subnet_id = data.tencentcloud_vpc_subnets.gz3.instance_list.0.subnet_id + sg_id = data.tencentcloud_security_groups.internal.security_groups.0.security_group_id + sg_id2 = data.tencentcloud_security_groups.exclusive.security_groups.0.security_group_id +} + +variable "fixed_tags" { + default = { + fixed_resource : "do_not_remove" + } +} + +variable "availability_zone" { + default = "ap-guangzhou-4" +} + +variable "new_availability_zone" { + default = "ap-guangzhou-6" +} + +variable "my_param_template" { + default = "15765" +} + +data "tencentcloud_security_groups" "internal" { + name = "default" + tags = var.fixed_tags +} + +data "tencentcloud_security_groups" "exclusive" { + name = "test_preset_sg" +} + +data "tencentcloud_vpc_subnets" "gz3" { + availability_zone = var.default_az + is_default = true +} + +resource "tencentcloud_cynosdb_cluster" "instance" { + available_zone = var.availability_zone + vpc_id = local.vpc_id + subnet_id = local.subnet_id + db_type = "MYSQL" + db_version = "5.7" + storage_limit = 1000 + cluster_name = "tf_test_cynosdb_cluster_slave_zone" + password = "cynos@123" + instance_maintain_duration = 3600 + instance_maintain_start_time = 10800 + instance_maintain_weekdays = [ + "Fri", + "Mon", + "Sat", + "Sun", + "Thu", + "Wed", + "Tue", + ] + + instance_cpu_core = 1 + instance_memory_size = 2 + param_items { + name = "character_set_server" + current_value = "utf8" + } + param_items { + name = "time_zone" + current_value = "+09:00" + } + + force_delete = true + + rw_group_sg = [ + local.sg_id + ] + ro_group_sg = [ + local.sg_id + ] + prarm_template_id = var.my_param_template +} + +resource "tencentcloud_cynosdb_cluster_slave_zone" "cluster_slave_zone" { + cluster_id = tencentcloud_cynosdb_cluster.instance.id + slave_zone = var.new_availability_zone +} +``` + +Update the slave zone with specified value. + ```hcl resource "tencentcloud_cynosdb_cluster_slave_zone" "cluster_slave_zone" { - cluster_id = "cynosdbmysql-xxxxxxxx" - slave_zone = "ap-guangzhou-3" + cluster_id = tencentcloud_cynosdb_cluster.instance.id + slave_zone = var.availability_zone } ``` @@ -40,6 +133,6 @@ In addition to all arguments above, the following attributes are exported: cynosdb cluster_slave_zone can be imported using the id, e.g. ``` -terraform import tencentcloud_cynosdb_cluster_slave_zone.cluster_slave_zone cluster_slave_zone_id +terraform import tencentcloud_cynosdb_cluster_slave_zone.cluster_slave_zone cluster_id#slave_zone ```