diff --git a/tencentcloud/basic_test.go b/tencentcloud/basic_test.go index 09019a3820..f1a490a59d 100644 --- a/tencentcloud/basic_test.go +++ b/tencentcloud/basic_test.go @@ -62,13 +62,16 @@ const ( defaultVpcCidr = "172.16.0.0/16" defaultVpcCidrLess = "172.16.0.0/18" - defaultCvmAZone = "ap-guangzhou-7" - defaultCvmVpcId = "vpc-l0dw94uh" - defaultCvmSubnetId = "subnet-ccj2qg0m" - defaultCvmTestingAZone = "ap-guangzhou-2" - defaultCvmTestingVpcId = "vpc-701bm52d" - defaultCvmTestingSubnetId = "subnet-1q62lj3m" - defaultCvmTestingImgId = "img-eb30mz89" + defaultCvmAZone = "ap-guangzhou-7" + defaultCvmInternationalZone = "ap-guangzhou-3" + defaultCvmVpcId = "vpc-l0dw94uh" + defaultCvmSubnetId = "subnet-ccj2qg0m" + defaultCvmTestingAZone = "ap-guangzhou-2" + defaultCvmTestingVpcId = "vpc-701bm52d" + defaultCvmTestingSubnetId = "subnet-1q62lj3m" + defaultCvmTestingImgId = "img-eb30mz89" + defaultCvmInternationalVpcId = "vpc-m7ryq37p" + defaultCvmInternationalSubnetId = "subnet-lwrsb7a0" defaultAZone = "ap-guangzhou-3" defaultSubnetId = "subnet-enm92y0m" @@ -183,9 +186,11 @@ data "tencentcloud_instance_types" "default" { // ckafka const ( - defaultKafkaInstanceId = "ckafka-vv7wpvae" - defaultKafkaVpcId = "vpc-njbzmzyd" - defaultKafkaSubnetId = "subnet-2txtpql8" + defaultKafkaInstanceId = "ckafka-vv7wpvae" + defaultKafkaVpcId = "vpc-njbzmzyd" + defaultKafkaSubnetId = "subnet-2txtpql8" + defaultKafkaInternationalVpcId = "vpc-ereuklyj" + defaultKafkaInternationalSubnetId = "subnet-e7rvxfx2" ) const defaultKafkaVariable = ` @@ -198,6 +203,12 @@ variable "vpc_id" { variable "subnet_id" { default = "` + defaultKafkaSubnetId + `" } +variable "international_vpc_id" { + default = "` + defaultKafkaInternationalVpcId + `" +} +variable "international_subnet_id" { + default = "` + defaultKafkaInternationalSubnetId + `" +} ` // Tke Exclusive Network Environment @@ -216,12 +227,14 @@ const ( // Cloud monitoring grafana visualization const ( - defaultGrafanaVpcId = "vpc-391sv4w3" - defaultGrafanaSubnetId = "subnet-ljyn7h30" - defaultGrafanaInstanceId = "grafana-dp2hnnfa" - defaultGrafanaReceiver = "Consumer-nfyxuzmbmq" - defaultGrafanaPlugin = "grafana-clock-panel" - defaultGrafanaVersion = "1.2.0" + defaultGrafanaVpcId = "vpc-391sv4w3" + defaultGrafanaSubnetId = "subnet-ljyn7h30" + defaultInternationalGrafanaVpcId = "vpc-dg21ckzx" + defaultInternationalGrafanaSubnetId = "subnet-i5lq9vy4" + defaultGrafanaInstanceId = "grafana-dp2hnnfa" + defaultGrafanaReceiver = "Consumer-nfyxuzmbmq" + defaultGrafanaPlugin = "grafana-clock-panel" + defaultGrafanaVersion = "1.2.0" ) /* @@ -251,6 +264,10 @@ variable "availability_cvm_zone" { default = "` + defaultCvmAZone + `" } +variable "availability_cvm_international_zone" { + default = "` + defaultCvmInternationalZone + `" +} + variable "availability_cvm_testing_zone" { default = "` + defaultCvmTestingAZone + `" } @@ -275,6 +292,15 @@ variable "cvm_subnet_id" { default = "` + defaultCvmSubnetId + `" } +variable "cvm_international_vpc_id" { + default = "` + defaultCvmInternationalVpcId + `" +} + +variable "cvm_international_subnet_id" { + default = "` + defaultCvmInternationalSubnetId + `" +} + + variable "vpc_id" { default = "` + defaultVpcId + `" } diff --git a/tencentcloud/resource_tc_gaap_layer4_listener_international_test.go b/tencentcloud/resource_tc_gaap_layer4_listener_international_test.go new file mode 100644 index 0000000000..9e52768b4f --- /dev/null +++ b/tencentcloud/resource_tc_gaap_layer4_listener_international_test.go @@ -0,0 +1,65 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccTencentCloudInternationalGaapResource_listener4(t *testing.T) { + t.Parallel() + id := new(string) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccInternationalGaapLayer4ListenerBasic, + Check: resource.ComposeTestCheckFunc( + testAccCheckGaapLayer4ListenerExists("tencentcloud_gaap_layer4_listener.foo", id, "TCP"), + resource.TestCheckResourceAttr("tencentcloud_gaap_layer4_listener.foo", "protocol", "TCP"), + resource.TestCheckResourceAttr("tencentcloud_gaap_layer4_listener.foo", "name", "ci-test-gaap-4-listener"), + resource.TestCheckResourceAttr("tencentcloud_gaap_layer4_listener.foo", "port", "9090"), + resource.TestCheckResourceAttr("tencentcloud_gaap_layer4_listener.foo", "realserver_type", "IP"), + resource.TestCheckResourceAttrSet("tencentcloud_gaap_layer4_listener.foo", "proxy_id"), + resource.TestCheckResourceAttr("tencentcloud_gaap_layer4_listener.foo", "health_check", "true"), + resource.TestCheckResourceAttr("tencentcloud_gaap_layer4_listener.foo", "interval", "5"), + resource.TestCheckResourceAttr("tencentcloud_gaap_layer4_listener.foo", "connect_timeout", "2"), + resource.TestCheckResourceAttr("tencentcloud_gaap_layer4_listener.foo", "realserver_bind_set.#", "2"), + resource.TestCheckResourceAttrSet("tencentcloud_gaap_layer4_listener.foo", "status"), + resource.TestCheckResourceAttrSet("tencentcloud_gaap_layer4_listener.foo", "create_time"), + resource.TestCheckResourceAttrSet("tencentcloud_gaap_layer4_listener.foo", "proxy_id"), + ), + }, + { + ResourceName: "tencentcloud_gaap_layer4_listener.foo", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +var testAccInternationalGaapLayer4ListenerBasic = ` +resource tencentcloud_gaap_layer4_listener "foo" { + protocol = "TCP" + name = "ci-test-gaap-4-listener" + port = 9090 + realserver_type = "IP" + proxy_id = "link-092unjav" + health_check = true + + realserver_bind_set { + id = "rs-5qfe73i1" + ip = "1.1.1.5" + port = 80 + } + + realserver_bind_set { + id = "rs-7smh4tmf" + ip = "119.29.29.35" + port = 80 + } +} +` diff --git a/tencentcloud/resource_tc_gaap_layer7_listener_international_test.go b/tencentcloud/resource_tc_gaap_layer7_listener_international_test.go new file mode 100644 index 0000000000..4a0494a157 --- /dev/null +++ b/tencentcloud/resource_tc_gaap_layer7_listener_international_test.go @@ -0,0 +1,46 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccTencentCloudInternationalGaapResource_listener7(t *testing.T) { + t.Parallel() + id := new(string) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccInternationalGaapLayer7ListenerBasic, + Check: resource.ComposeTestCheckFunc( + testAccCheckGaapLayer7ListenerExists("tencentcloud_gaap_layer7_listener.foo", id, "HTTP"), + resource.TestCheckResourceAttr("tencentcloud_gaap_layer7_listener.foo", "protocol", "HTTP"), + resource.TestCheckResourceAttr("tencentcloud_gaap_layer7_listener.foo", "name", "ci-test-gaap-l7-listener"), + resource.TestCheckResourceAttr("tencentcloud_gaap_layer7_listener.foo", "port", "8080"), + resource.TestCheckResourceAttr("tencentcloud_gaap_layer7_listener.foo", "client_certificate_ids.#", "0"), + resource.TestCheckResourceAttrSet("tencentcloud_gaap_layer7_listener.foo", "status"), + resource.TestCheckResourceAttrSet("tencentcloud_gaap_layer7_listener.foo", "create_time"), + resource.TestCheckResourceAttrSet("tencentcloud_gaap_layer7_listener.foo", "proxy_id"), + ), + }, + { + ResourceName: "tencentcloud_gaap_layer7_listener.foo", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +var testAccInternationalGaapLayer7ListenerBasic = ` +resource tencentcloud_gaap_layer7_listener "foo" { + protocol = "HTTP" + name = "ci-test-gaap-l7-listener" + port = 8080 + proxy_id = "link-092unjav" +} +` diff --git a/tencentcloud/resource_tc_gaap_proxy_international_test.go b/tencentcloud/resource_tc_gaap_proxy_international_test.go new file mode 100644 index 0000000000..fb07281534 --- /dev/null +++ b/tencentcloud/resource_tc_gaap_proxy_international_test.go @@ -0,0 +1,57 @@ +package tencentcloud + +import ( + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccTencentCloudInternationalGaapResource_proxy(t *testing.T) { + id := new(string) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckGaapProxyDestroy(id), + Steps: []resource.TestStep{ + { + Config: testAccInternationalGaapProxyBasic, + Check: resource.ComposeTestCheckFunc( + testAccCheckGaapProxyExists("tencentcloud_gaap_proxy.foo", id), + resource.TestCheckResourceAttr("tencentcloud_gaap_proxy.foo", "name", "ci-test-gaap-proxy"), + resource.TestCheckResourceAttr("tencentcloud_gaap_proxy.foo", "bandwidth", "10"), + resource.TestCheckResourceAttr("tencentcloud_gaap_proxy.foo", "concurrent", "2"), + resource.TestCheckResourceAttr("tencentcloud_gaap_proxy.foo", "project_id", "0"), + resource.TestCheckResourceAttr("tencentcloud_gaap_proxy.foo", "access_region", "Guangzhou"), + resource.TestCheckResourceAttr("tencentcloud_gaap_proxy.foo", "realserver_region", "Beijing"), + resource.TestCheckResourceAttr("tencentcloud_gaap_proxy.foo", "enable", "true"), + resource.TestCheckNoResourceAttr("tencentcloud_gaap_proxy.foo", "tags"), + resource.TestCheckResourceAttrSet("tencentcloud_gaap_proxy.foo", "create_time"), + resource.TestCheckResourceAttrSet("tencentcloud_gaap_proxy.foo", "status"), + resource.TestCheckResourceAttrSet("tencentcloud_gaap_proxy.foo", "domain"), + resource.TestCheckResourceAttrSet("tencentcloud_gaap_proxy.foo", "ip"), + resource.TestCheckResourceAttrSet("tencentcloud_gaap_proxy.foo", "scalable"), + resource.TestMatchResourceAttr("tencentcloud_gaap_proxy.foo", "support_protocols.#", regexp.MustCompile(`^[1-9]\d*$`)), + resource.TestCheckResourceAttrSet("tencentcloud_gaap_proxy.foo", "forward_ip"), + ), + }, + { + ResourceName: "tencentcloud_gaap_proxy.foo", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccInternationalGaapProxyBasic = ` +resource tencentcloud_gaap_proxy "foo" { + name = "ci-test-gaap-proxy" + bandwidth = 10 + concurrent = 2 + access_region = "Guangzhou" + realserver_region = "Beijing" + network_type = "normal" +} +` diff --git a/tencentcloud/resource_tc_kubernetes_cluster_international_test.go b/tencentcloud/resource_tc_kubernetes_cluster_international_test.go new file mode 100644 index 0000000000..02ce5d44f4 --- /dev/null +++ b/tencentcloud/resource_tc_kubernetes_cluster_international_test.go @@ -0,0 +1,117 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +var testInternationalTkeClusterName = "tencentcloud_kubernetes_cluster" +var testInternationalTkeClusterResourceKey = testInternationalTkeClusterName + ".managed_cluster" + +func TestAccInternationalTencentCloudKubernetesResource_cluster(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckTkeDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInternationalTkeCluster, + Check: resource.ComposeTestCheckFunc( + testAccCheckTkeExists(testTkeClusterResourceKey), + resource.TestCheckResourceAttr(testTkeClusterResourceKey, "cluster_cidr", "10.31.0.0/23"), + resource.TestCheckResourceAttr(testTkeClusterResourceKey, "cluster_max_pod_num", "32"), + resource.TestCheckResourceAttr(testTkeClusterResourceKey, "cluster_name", "test"), + resource.TestCheckResourceAttr(testTkeClusterResourceKey, "cluster_desc", "test cluster desc"), + resource.TestCheckResourceAttr(testTkeClusterResourceKey, "cluster_node_num", "1"), + resource.TestCheckResourceAttr(testTkeClusterResourceKey, "worker_instances_list.#", "1"), + resource.TestCheckResourceAttrSet(testTkeClusterResourceKey, "worker_instances_list.0.instance_id"), + resource.TestCheckResourceAttrSet(testTkeClusterResourceKey, "certification_authority"), + resource.TestCheckResourceAttrSet(testTkeClusterResourceKey, "user_name"), + resource.TestCheckResourceAttrSet(testTkeClusterResourceKey, "password"), + resource.TestCheckResourceAttr(testTkeClusterResourceKey, "tags.test", "test"), + //resource.TestCheckResourceAttr(testTkeClusterResourceKey, "security_policy.#", "2"), + //resource.TestCheckResourceAttrSet(testTkeClusterResourceKey, "cluster_external_endpoint"), + resource.TestCheckResourceAttr(testTkeClusterResourceKey, "cluster_level", "L5"), + resource.TestCheckResourceAttr(testTkeClusterResourceKey, "auto_upgrade_cluster_level", "true"), + resource.TestCheckResourceAttr(testTkeClusterResourceKey, "labels.test1", "test1"), + resource.TestCheckResourceAttr(testTkeClusterResourceKey, "labels.test2", "test2"), + resource.TestCheckResourceAttr(testTkeClusterResourceKey, "cluster_internet_domain", "tf.cluster-internet.com"), + resource.TestCheckResourceAttr(testTkeClusterResourceKey, "cluster_intranet_domain", "tf.cluster-intranet.com"), + ), + }, + }, + }) +} + +const InternationalTkeDeps = TkeExclusiveNetwork + TkeInstanceType + TkeCIDRs + defaultImages + defaultSecurityGroupData + +const testAccInternationalTkeCluster = InternationalTkeDeps + ` +variable "availability_zone" { + default = "ap-guangzhou-3" +} + +resource "tencentcloud_kubernetes_cluster" "managed_cluster" { + vpc_id = local.vpc_id + cluster_cidr = var.tke_cidr_a.0 + cluster_max_pod_num = 32 + cluster_name = "test" + cluster_desc = "test cluster desc" + cluster_max_service_num = 32 + cluster_internet = true + cluster_internet_domain = "tf.cluster-internet.com" + cluster_intranet = true + cluster_intranet_domain = "tf.cluster-intranet.com" + cluster_version = "1.22.5" + cluster_os = "tlinux2.2(tkernel3)x86_64" + cluster_level = "L5" + auto_upgrade_cluster_level = true + cluster_intranet_subnet_id = local.subnet_id + cluster_internet_security_group = local.sg_id + managed_cluster_internet_security_policies = ["3.3.3.3", "1.1.1.1"] + worker_config { + count = 1 + availability_zone = var.availability_zone + instance_type = local.final_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 = local.subnet_id + img_id = var.default_img_id + security_group_ids = [local.sg_id] + + data_disk { + disk_type = "CLOUD_PREMIUM" + disk_size = 50 + file_system = "ext3" + auto_format_and_mount = "true" + mount_target = "/var/lib/docker" + disk_partition = "/dev/sdb1" + } + + enhanced_security_service = false + enhanced_monitor_service = false + user_data = "dGVzdA==" + password = "ZZXXccvv1212" + } + + cluster_deploy_type = "MANAGED_CLUSTER" + + tags = { + "test" = "test" + } + + unschedulable = 0 + + labels = { + "test1" = "test1", + "test2" = "test2", + } + extra_args = [ + "root-dir=/var/lib/kubelet" + ] +} +` diff --git a/tencentcloud/resource_tc_monitor_tmp_instance_international_test.go b/tencentcloud/resource_tc_monitor_tmp_instance_international_test.go new file mode 100644 index 0000000000..1454eb874e --- /dev/null +++ b/tencentcloud/resource_tc_monitor_tmp_instance_international_test.go @@ -0,0 +1,66 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccTencentCloudInternationalMonitorResource_tmpInstance(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckMonInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testInternationalInstance_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckInstanceExists("tencentcloud_monitor_tmp_instance.basic"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_instance.basic", "instance_name", "demo-test"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_instance.basic", "data_retention_time", "30"), + ), + }, + { + Config: testInternationalInstance_update, + Check: resource.ComposeTestCheckFunc( + testAccCheckInstanceExists("tencentcloud_monitor_tmp_instance.update"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_instance.update", "instance_name", "demo-test-update"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_instance.update", "data_retention_time", "30"), + ), + }, + }, + }) +} + +const testInternationalInstanceVar = ` +variable "vpc_id" { + default = "` + defaultInternationalGrafanaVpcId + `" +} +variable "subnet_id" { + default = "` + defaultInternationalGrafanaSubnetId + `" +} +` +const testInternationalInstance_basic = testInternationalInstanceVar + ` +resource "tencentcloud_monitor_tmp_instance" "basic" { + instance_name = "demo-test" + vpc_id = var.vpc_id + subnet_id = var.subnet_id + data_retention_time = 30 + zone = "ap-guangzhou-4" + tags = { + "createdBy" = "terraform" + } +}` + +const testInternationalInstance_update = testInternationalInstanceVar + ` +resource "tencentcloud_monitor_tmp_instance" "update" { + instance_name = "demo-test-update" + vpc_id = var.vpc_id + subnet_id = var.subnet_id + data_retention_time = 30 + zone = "ap-guangzhou-4" + tags = { + "createdBy" = "terraform" + } +}` diff --git a/tencentcloud/resource_tc_vpc_acl_international_test.go b/tencentcloud/resource_tc_vpc_acl_international_test.go new file mode 100644 index 0000000000..16625bbe9e --- /dev/null +++ b/tencentcloud/resource_tc_vpc_acl_international_test.go @@ -0,0 +1,99 @@ +package tencentcloud + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccTencentCloudInternationalVpcAclResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckVpcACLDestroy, + Steps: []resource.TestStep{ + { + Config: testAccVpcACLConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckVpcACLExists("tencentcloud_vpc_acl.foo"), + resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "name", "test_acl"), + resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "ingress.#", "2"), + resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "egress.#", "2"), + ), + }, + { + ResourceName: "tencentcloud_vpc_acl.foo", + ImportState: true, + }, + }, + }) +} + +func testAccInternationalCheckVpcACLExists(r string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + rs, ok := s.RootModule().Resources[r] + if !ok { + return fmt.Errorf("resource %s is not found", r) + } + + service := VpcService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + _, has, err := service.DescribeNetWorkByACLID(ctx, rs.Primary.ID) + if err != nil { + return err + } + if has > 0 { + return nil + } + + return fmt.Errorf("vpc network acl %s not exists", rs.Primary.ID) + } +} + +func testAccInternationalCheckVpcACLDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := VpcService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_vpc_acl" { + continue + } + _, has, err := service.DescribeNetWorkByACLID(ctx, rs.Primary.ID) + if err != nil { + return err + } + if has == 0 { + return nil + } + + return fmt.Errorf("vpc acl %s still exists", rs.Primary.ID) + } + + return nil +} + +const testAccInternationalVpcACLConfig = ` +data "tencentcloud_vpc_instances" "default" { + is_default = true +} + +resource "tencentcloud_vpc_acl" "foo" { + vpc_id = data.tencentcloud_vpc_instances.default.instance_list.0.vpc_id + name = "test_acl" + ingress = [ + "ACCEPT#192.168.1.0/24#80#TCP", + "ACCEPT#192.168.1.0/24#80-90#TCP", + ] + egress = [ + "ACCEPT#192.168.1.0/24#80#TCP", + "ACCEPT#192.168.1.0/24#80-90#TCP", + ] +} +` diff --git a/tencentcloud/resource_tc_vpc_international_test.go b/tencentcloud/resource_tc_vpc_international_test.go new file mode 100644 index 0000000000..bb1ff42f87 --- /dev/null +++ b/tencentcloud/resource_tc_vpc_international_test.go @@ -0,0 +1,90 @@ +package tencentcloud + +import ( + "context" + "fmt" + "testing" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccTencentCloudInternationalVpcResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccInternationalCheckVpcDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInternationalVpcConfig, + Check: resource.ComposeTestCheckFunc( + testAccInternationalCheckVpcExists("tencentcloud_vpc.foo"), + resource.TestCheckResourceAttr("tencentcloud_vpc.foo", "cidr_block", "172.16.0.0/16"), + resource.TestCheckResourceAttr("tencentcloud_vpc.foo", "name", "tf-vpc"), + resource.TestCheckResourceAttr("tencentcloud_vpc.foo", "is_multicast", "true"), + resource.TestCheckResourceAttrSet("tencentcloud_vpc.foo", "default_route_table_id"), + ), + }, + { + ResourceName: "tencentcloud_vpc.foo", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccInternationalCheckVpcExists(r string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + rs, ok := s.RootModule().Resources[r] + if !ok { + return fmt.Errorf("resource %s is not found", r) + } + + service := VpcService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + _, has, err := service.DescribeVpc(ctx, rs.Primary.ID, "", "") + if err != nil { + return err + } + if has > 0 { + return nil + } + + return fmt.Errorf("vpc %s not exists", rs.Primary.ID) + } +} + +func testAccInternationalCheckVpcDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := VpcService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_vpc" { + continue + } + time.Sleep(5 * time.Second) + _, has, err := service.DescribeVpc(ctx, rs.Primary.ID, "", "") + if err != nil { + return err + } + if has == 0 { + return nil + } + return fmt.Errorf("vpc %s still exists", rs.Primary.ID) + } + + return nil +} + +const testAccInternationalVpcConfig = ` +resource "tencentcloud_vpc" "foo" { + name = "tf-vpc" + cidr_block = "172.16.0.0/16" +} +` diff --git a/tencentcloud/services/cbs/data_source_tc_cbs_snapshot_policies_international_test.go b/tencentcloud/services/cbs/data_source_tc_cbs_snapshot_policies_international_test.go new file mode 100644 index 0000000000..53f1950181 --- /dev/null +++ b/tencentcloud/services/cbs/data_source_tc_cbs_snapshot_policies_international_test.go @@ -0,0 +1,46 @@ +package cbs_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudInternationalCbsDataSource_snapshotPolicies(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheck(t) }, + Providers: tcacctest.AccProviders, + CheckDestroy: testAccCheckCbsSnapshotPolicyDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInternationalCbsSnapshotPoliciesDataSource, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckSnapshotPolicyExists("tencentcloud_cbs_snapshot_policy.policy"), + resource.TestCheckResourceAttr("data.tencentcloud_cbs_snapshot_policies.policies", "snapshot_policy_list.#", "1"), + resource.TestCheckResourceAttrSet("data.tencentcloud_cbs_snapshot_policies.policies", "snapshot_policy_list.0.snapshot_policy_id"), + resource.TestCheckResourceAttr("data.tencentcloud_cbs_snapshot_policies.policies", "snapshot_policy_list.0.snapshot_policy_name", "tf-test-snapshot-policy"), + resource.TestCheckResourceAttr("data.tencentcloud_cbs_snapshot_policies.policies", "snapshot_policy_list.0.repeat_weekdays.#", "2"), + resource.TestCheckResourceAttr("data.tencentcloud_cbs_snapshot_policies.policies", "snapshot_policy_list.0.repeat_hours.#", "1"), + resource.TestCheckResourceAttr("data.tencentcloud_cbs_snapshot_policies.policies", "snapshot_policy_list.0.retention_days", "30"), + ), + }, + }, + }) +} + +const testAccInternationalCbsSnapshotPoliciesDataSource = ` +resource "tencentcloud_cbs_snapshot_policy" "policy" { + snapshot_policy_name = "tf-test-snapshot-policy" + repeat_weekdays = [0, 3] + repeat_hours = [0] + retention_days = 30 +} + +data "tencentcloud_cbs_snapshot_policies" "policies" { + snapshot_policy_id = tencentcloud_cbs_snapshot_policy.policy.id + snapshot_policy_name = tencentcloud_cbs_snapshot_policy.policy.snapshot_policy_name +} +` diff --git a/tencentcloud/services/cbs/data_source_tc_cbs_storages_international_test.go b/tencentcloud/services/cbs/data_source_tc_cbs_storages_international_test.go new file mode 100644 index 0000000000..74500fc193 --- /dev/null +++ b/tencentcloud/services/cbs/data_source_tc_cbs_storages_international_test.go @@ -0,0 +1,53 @@ +package cbs_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudInternationalCbsDataSource_storages(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheck(t) }, + Providers: tcacctest.AccProviders, + CheckDestroy: testAccCheckCbsStorageDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInternationalCbsStoragesDataSource, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckStorageExists("tencentcloud_cbs_storage.storage"), + resource.TestCheckResourceAttr("data.tencentcloud_cbs_storages.storages", "storage_list.#", "1"), + resource.TestCheckResourceAttrSet("data.tencentcloud_cbs_storages.storages", "storage_list.0.storage_id"), + resource.TestCheckResourceAttr("data.tencentcloud_cbs_storages.storages", "storage_list.0.storage_name", "tf-test-storage"), + resource.TestCheckResourceAttr("data.tencentcloud_cbs_storages.storages", "storage_list.0.storage_type", "CLOUD_PREMIUM"), + resource.TestCheckResourceAttr("data.tencentcloud_cbs_storages.storages", "storage_list.0.storage_size", "50"), + resource.TestCheckResourceAttr("data.tencentcloud_cbs_storages.storages", "storage_list.0.availability_zone", "ap-guangzhou-3"), + resource.TestCheckResourceAttr("data.tencentcloud_cbs_storages.storages", "storage_list.0.project_id", "0"), + resource.TestCheckResourceAttr("data.tencentcloud_cbs_storages.storages", "storage_list.0.encrypt", "false"), + resource.TestCheckResourceAttr("data.tencentcloud_cbs_storages.storages", "storage_list.0.attached", "false"), + resource.TestCheckResourceAttrSet("data.tencentcloud_cbs_storages.storages", "storage_list.0.create_time"), + resource.TestCheckResourceAttrSet("data.tencentcloud_cbs_storages.storages", "storage_list.0.status"), + resource.TestCheckResourceAttrSet("data.tencentcloud_cbs_storages.storages", "storage_list.0.charge_type"), + ), + }, + }, + }) +} + +const testAccInternationalCbsStoragesDataSource = ` +resource "tencentcloud_cbs_storage" "storage" { + storage_type = "CLOUD_PREMIUM" + storage_name = "tf-test-storage" + storage_size = 50 + availability_zone = "ap-guangzhou-3" + project_id = 0 + encrypt = false +} + +data "tencentcloud_cbs_storages" "storages" { + storage_id = tencentcloud_cbs_storage.storage.id +} +` diff --git a/tencentcloud/services/cbs/resource_tc_cbs_disk_backup_international_test.go b/tencentcloud/services/cbs/resource_tc_cbs_disk_backup_international_test.go new file mode 100644 index 0000000000..7a7dba8e9c --- /dev/null +++ b/tencentcloud/services/cbs/resource_tc_cbs_disk_backup_international_test.go @@ -0,0 +1,37 @@ +package cbs_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudInternationalCbsResource_diskBackup(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheck(t) }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccInternationalCbsDiskBackup, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_cbs_disk_backup.disk_backup", "id"), + ), + }, + { + ResourceName: "tencentcloud_cbs_disk_backup.disk_backup", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccInternationalCbsDiskBackup = ` +resource "tencentcloud_cbs_disk_backup" "disk_backup" { + disk_id = "disk-j8wrj3uq" + disk_backup_name = "test-disk-backup" +} +` diff --git a/tencentcloud/services/cbs/resource_tc_cbs_snapshot_international_test.go b/tencentcloud/services/cbs/resource_tc_cbs_snapshot_international_test.go new file mode 100644 index 0000000000..bdc114df67 --- /dev/null +++ b/tencentcloud/services/cbs/resource_tc_cbs_snapshot_international_test.go @@ -0,0 +1,117 @@ +package cbs_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + localcbs "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/cbs" +) + +func TestAccTencentCloudInternationalCbsResource_snapshot(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheck(t) }, + Providers: tcacctest.AccProviders, + CheckDestroy: testAccCheckInternationalCbsSnapshotDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInternationalCbsSnapshot, + Check: resource.ComposeTestCheckFunc( + testAccCheckSnapshotExists("tencentcloud_cbs_snapshot.snapshot"), + resource.TestCheckResourceAttrSet("tencentcloud_cbs_snapshot.snapshot", "storage_id"), + resource.TestCheckResourceAttr("tencentcloud_cbs_snapshot.snapshot", "snapshot_name", "tf-test-snapshot"), + ), + }, + { + Config: testAccInternationalCbsSnapshot_update, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("tencentcloud_cbs_snapshot.snapshot", "snapshot_name", "tf-test-snapshot-update"), + ), + }, + { + ResourceName: "tencentcloud_cbs_snapshot.snapshot", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckInternationalCbsSnapshotDestroy(s *terraform.State) error { + logId := tccommon.GetLogId(tccommon.ContextNil) + ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + + cbsService := localcbs.NewCbsService(tcacctest.AccProvider.Meta().(tccommon.ProviderMeta).GetAPIV3Conn()) + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_cbs_snapshot" { + continue + } + + snapshot, err := cbsService.DescribeSnapshotById(ctx, rs.Primary.ID) + if err != nil { + return err + } + if snapshot != nil { + return fmt.Errorf("cbs snapshot still exists: %s", rs.Primary.ID) + } + } + return nil +} + +func testAccInternationalCheckSnapshotExists(n string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := tccommon.GetLogId(tccommon.ContextNil) + ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("cbs snapshot %s is not found", n) + } + if rs.Primary.ID == "" { + return fmt.Errorf("cbs snapshot id is set") + } + cbsService := localcbs.NewCbsService(tcacctest.AccProvider.Meta().(tccommon.ProviderMeta).GetAPIV3Conn()) + snapshot, err := cbsService.DescribeSnapshotById(ctx, rs.Primary.ID) + if err != nil { + return err + } + if snapshot == nil { + return fmt.Errorf("cbs snapshot is not exist") + } + return nil + } +} + +const testAccInternationalCbsSnapshot = ` +resource "tencentcloud_cbs_storage" "storage" { + availability_zone = "ap-guangzhou-3" + storage_size = 50 + storage_type = "CLOUD_PREMIUM" + storage_name = "tf-test-storage" +} + +resource "tencentcloud_cbs_snapshot" "snapshot" { + storage_id = tencentcloud_cbs_storage.storage.id + snapshot_name = "tf-test-snapshot" +} +` + +const testAccInternationalCbsSnapshot_update = ` +resource "tencentcloud_cbs_storage" "storage" { + availability_zone = "ap-guangzhou-3" + storage_size = 50 + storage_type = "CLOUD_PREMIUM" + storage_name = "tf-test-storage" +} + +resource "tencentcloud_cbs_snapshot" "snapshot" { + storage_id = tencentcloud_cbs_storage.storage.id + snapshot_name = "tf-test-snapshot-update" +} +` diff --git a/tencentcloud/services/cbs/resource_tc_cbs_snapshot_policy_attachment_international_test.go b/tencentcloud/services/cbs/resource_tc_cbs_snapshot_policy_attachment_international_test.go new file mode 100644 index 0000000000..efccfbd27e --- /dev/null +++ b/tencentcloud/services/cbs/resource_tc_cbs_snapshot_policy_attachment_international_test.go @@ -0,0 +1,115 @@ +package cbs_test + +import ( + "context" + "errors" + "fmt" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + localcbs "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/cbs" +) + +func TestAccTencentCloudInternationalCbsResource_snapshotPolicyAttachment(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheck(t) }, + Providers: tcacctest.AccProviders, + CheckDestroy: testAccInternationalCheckCbsSnapshotPolicyAttachmentDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInternationalCbsSnapshotPolicyAttachmentConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckCbsSnapshotPolicyAttachmentExists("tencentcloud_cbs_snapshot_policy_attachment.foo"), + resource.TestCheckResourceAttrSet("tencentcloud_cbs_snapshot_policy_attachment.foo", "storage_id"), + resource.TestCheckResourceAttrSet("tencentcloud_cbs_snapshot_policy_attachment.foo", "snapshot_policy_id"), + ), + }, + }, + }) +} + +func testAccInternationalCheckCbsSnapshotPolicyAttachmentDestroy(s *terraform.State) error { + logId := tccommon.GetLogId(tccommon.ContextNil) + ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + + cbsService := localcbs.NewCbsService(tcacctest.AccProvider.Meta().(tccommon.ProviderMeta).GetAPIV3Conn()) + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_cbs_snapshot_policy_attachment" { + continue + } + id := rs.Primary.ID + idSplit := strings.Split(id, tccommon.FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("tencentcloud_cbs_snapshot_policy_attachment id is illegal: %s", id) + } + storageId := idSplit[0] + policyId := idSplit[1] + policy, err := cbsService.DescribeAttachedSnapshotPolicy(ctx, storageId, policyId) + if err != nil { + return err + } + if policy != nil { + return errors.New("cbs snapshot policy attachment still exists") + } + } + + return nil +} + +func testAccInternationalCheckCbsSnapshotPolicyAttachmentExists(n string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := tccommon.GetLogId(tccommon.ContextNil) + ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("cbs snapshot policy attachment %s is not found", n) + } + if rs.Primary.ID == "" { + return errors.New("cbs snapshot policy attachment id is not set") + } + id := rs.Primary.ID + idSplit := strings.Split(id, tccommon.FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("tencentcloud_cbs_snapshot_policy_attachment id is illegal: %s", id) + } + storageId := idSplit[0] + policyId := idSplit[1] + cbsService := localcbs.NewCbsService(tcacctest.AccProvider.Meta().(tccommon.ProviderMeta).GetAPIV3Conn()) + policy, err := cbsService.DescribeAttachedSnapshotPolicy(ctx, storageId, policyId) + if err != nil { + return err + } + if policy == nil { + return errors.New("cbs snapshot policy attachment not exists") + } + return nil + } +} + +const testAccInternationalCbsSnapshotPolicyAttachmentConfig = tcacctest.DefaultVpcVariable + ` +resource "tencentcloud_cbs_storage" "foo" { + availability_zone = var.availability_zone + storage_size = 100 + storage_type = "CLOUD_PREMIUM" + storage_name = var.instance_name +} + +resource "tencentcloud_cbs_snapshot_policy" "policy" { + snapshot_policy_name = "tf-test-snapshot-policy" + repeat_weekdays = [0, 3] + repeat_hours = [0] + retention_days = 30 +} + +resource "tencentcloud_cbs_snapshot_policy_attachment" "foo" { + storage_id = tencentcloud_cbs_storage.foo.id + snapshot_policy_id = tencentcloud_cbs_snapshot_policy.policy.id +} +` diff --git a/tencentcloud/services/cbs/resource_tc_cbs_snapshot_policy_international_test.go b/tencentcloud/services/cbs/resource_tc_cbs_snapshot_policy_international_test.go new file mode 100644 index 0000000000..70f5cb0e1a --- /dev/null +++ b/tencentcloud/services/cbs/resource_tc_cbs_snapshot_policy_international_test.go @@ -0,0 +1,97 @@ +package cbs_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + localcbs "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/cbs" +) + +func TestAccTencentCloudInternationalCbsResource_snapshotPolicy(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheck(t) }, + Providers: tcacctest.AccProviders, + CheckDestroy: testAccCheckInternationalCbsSnapshotPolicyDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCbsSnapshotPolicy, + Check: resource.ComposeTestCheckFunc( + testAccCheckSnapshotPolicyExists("tencentcloud_cbs_snapshot_policy.snapshot_policy"), + resource.TestCheckResourceAttr("tencentcloud_cbs_snapshot_policy.snapshot_policy", "snapshot_policy_name", "tf-test-snapshot-policy"), + resource.TestCheckResourceAttr("tencentcloud_cbs_snapshot_policy.snapshot_policy", "repeat_weekdays.#", "2"), + resource.TestCheckResourceAttr("tencentcloud_cbs_snapshot_policy.snapshot_policy", "repeat_weekdays.0", "0"), + resource.TestCheckResourceAttr("tencentcloud_cbs_snapshot_policy.snapshot_policy", "repeat_weekdays.1", "3"), + resource.TestCheckResourceAttr("tencentcloud_cbs_snapshot_policy.snapshot_policy", "repeat_hours.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_cbs_snapshot_policy.snapshot_policy", "repeat_hours.0", "0"), + resource.TestCheckResourceAttr("tencentcloud_cbs_snapshot_policy.snapshot_policy", "retention_days", "30"), + ), + }, + { + ResourceName: "tencentcloud_cbs_snapshot_policy.snapshot_policy", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckInternationalCbsSnapshotPolicyDestroy(s *terraform.State) error { + logId := tccommon.GetLogId(tccommon.ContextNil) + ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + + cbsService := localcbs.NewCbsService(tcacctest.AccProvider.Meta().(tccommon.ProviderMeta).GetAPIV3Conn()) + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_cbs_snapshot_policy" { + continue + } + + policy, err := cbsService.DescribeSnapshotPolicyById(ctx, rs.Primary.ID) + if err != nil { + return err + } + if policy != nil { + return fmt.Errorf("cbs snapshot policy still exists: %s", rs.Primary.ID) + } + } + return nil +} + +func testAccCheckInternationalSnapshotPolicyExists(n string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := tccommon.GetLogId(tccommon.ContextNil) + ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("cbs snapshot policy %s is not found", n) + } + if rs.Primary.ID == "" { + return fmt.Errorf("cbs snapshot policy id is not set") + } + cbsService := localcbs.NewCbsService(tcacctest.AccProvider.Meta().(tccommon.ProviderMeta).GetAPIV3Conn()) + policy, err := cbsService.DescribeSnapshotPolicyById(ctx, rs.Primary.ID) + if err != nil { + return err + } + if policy == nil { + return fmt.Errorf("cbs snapshot policy is not exist") + } + return nil + } +} + +const testAccInternationalCbsSnapshotPolicy = ` +resource "tencentcloud_cbs_snapshot_policy" "snapshot_policy" { + snapshot_policy_name = "tf-test-snapshot-policy" + repeat_weekdays = [0, 3] + repeat_hours = [0] + retention_days = 30 +} +` diff --git a/tencentcloud/services/cbs/resource_tc_cbs_storage_attachment_international_test.go b/tencentcloud/services/cbs/resource_tc_cbs_storage_attachment_international_test.go new file mode 100644 index 0000000000..fca2563bf0 --- /dev/null +++ b/tencentcloud/services/cbs/resource_tc_cbs_storage_attachment_international_test.go @@ -0,0 +1,109 @@ +package cbs_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + localcbs "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/cbs" +) + +func TestAccTencentCloudInternationalCbsResource_storageAttachment(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheck(t) }, + Providers: tcacctest.AccProviders, + CheckDestroy: testAccCheckInternationalCbsStorageAttachmentDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInternationalCbsStorageAttachmentConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckInternationalCbsStorageAttachmentExists("tencentcloud_cbs_storage_attachment.foo"), + resource.TestCheckResourceAttrSet("tencentcloud_cbs_storage_attachment.foo", "storage_id"), + resource.TestCheckResourceAttrSet("tencentcloud_cbs_storage_attachment.foo", "instance_id"), + ), + }, + { + ResourceName: "tencentcloud_cbs_storage_attachment.foo", + ImportState: true, + }, + }, + }) +} + +func testAccCheckInternationalCbsStorageAttachmentDestroy(s *terraform.State) error { + logId := tccommon.GetLogId(tccommon.ContextNil) + ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + + cbsService := localcbs.NewCbsService(tcacctest.AccProvider.Meta().(tccommon.ProviderMeta).GetAPIV3Conn()) + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_cbs_storage_attachment" { + continue + } + + storage, err := cbsService.DescribeDiskById(ctx, rs.Primary.ID) + if storage == nil { + continue + } + if err != nil { + return err + } + if *storage.Attached { + return fmt.Errorf("cbs storage attchment still exists") + } + } + + return nil +} + +func testAccCheckInternationalCbsStorageAttachmentExists(n string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := tccommon.GetLogId(tccommon.ContextNil) + ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("cbs storage attachment %s is not found", n) + } + if rs.Primary.ID == "" { + return fmt.Errorf("cbs storage attachment id is not set") + } + cbsService := localcbs.NewCbsService(tcacctest.AccProvider.Meta().(tccommon.ProviderMeta).GetAPIV3Conn()) + storage, err := cbsService.DescribeDiskById(ctx, rs.Primary.ID) + if err != nil { + return err + } + if storage == nil || *storage.Attached == false { + return fmt.Errorf("cbs storage attchment not exists") + } + return nil + } +} + +const testAccInternationalCbsStorageAttachmentConfig = tcacctest.DefaultInstanceVariable + tcacctest.DefaultAzVariable + ` +resource "tencentcloud_instance" "test_cbs_attach" { + instance_name = "test-cbs-attach-cvm" + availability_zone = var.default_az + image_id = data.tencentcloud_images.default.images.0.image_id + system_disk_type = "CLOUD_PREMIUM" + instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type +} + +resource "tencentcloud_cbs_storage" "foo" { + availability_zone = var.default_az + storage_size = 100 + storage_type = "CLOUD_PREMIUM" + storage_name = "test-cbs-attachment" + charge_type = "POSTPAID_BY_HOUR" +} + +resource "tencentcloud_cbs_storage_attachment" "foo" { + storage_id = tencentcloud_cbs_storage.foo.id + instance_id = tencentcloud_instance.test_cbs_attach.id +} +` diff --git a/tencentcloud/services/cbs/resource_tc_cbs_storage_international_test.go b/tencentcloud/services/cbs/resource_tc_cbs_storage_international_test.go new file mode 100644 index 0000000000..38c4794e21 --- /dev/null +++ b/tencentcloud/services/cbs/resource_tc_cbs_storage_international_test.go @@ -0,0 +1,95 @@ +package cbs_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + localcbs "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/cbs" +) + +func TestAccTencentCloudInternationalCbsResource_storage(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheck(t) }, + Providers: tcacctest.AccProviders, + CheckDestroy: testAccCheckInternationalCbsStorageDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInternationalCbsStorage_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckInternationalStorageExists("tencentcloud_cbs_storage.storage_basic"), + resource.TestCheckResourceAttr("tencentcloud_cbs_storage.storage_basic", "storage_name", "tf-storage-basic"), + resource.TestCheckResourceAttr("tencentcloud_cbs_storage.storage_basic", "storage_type", "CLOUD_PREMIUM"), + resource.TestCheckResourceAttr("tencentcloud_cbs_storage.storage_basic", "storage_size", "50"), + resource.TestCheckResourceAttr("tencentcloud_cbs_storage.storage_basic", "availability_zone", "ap-guangzhou-3"), + ), + }, + { + ResourceName: "tencentcloud_cbs_storage.storage_basic", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_delete"}, + }, + }, + }) +} + +func testAccCheckInternationalCbsStorageDestroy(s *terraform.State) error { + logId := tccommon.GetLogId(tccommon.ContextNil) + ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + + cbsService := localcbs.NewCbsService(tcacctest.AccProvider.Meta().(tccommon.ProviderMeta).GetAPIV3Conn()) + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_cbs_storage" { + continue + } + + storage, err := cbsService.DescribeDiskById(ctx, rs.Primary.ID) + if err != nil { + return err + } + if storage != nil { + return fmt.Errorf("cbs storage still exists: %s", rs.Primary.ID) + } + } + return nil +} + +func testAccCheckInternationalStorageExists(n string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := tccommon.GetLogId(tccommon.ContextNil) + ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("cbs storage %s is not found", n) + } + if rs.Primary.ID == "" { + return fmt.Errorf("cbs storage id is not set") + } + cbsService := localcbs.NewCbsService(tcacctest.AccProvider.Meta().(tccommon.ProviderMeta).GetAPIV3Conn()) + storage, err := cbsService.DescribeDiskById(ctx, rs.Primary.ID) + if err != nil { + return err + } + if storage == nil { + return fmt.Errorf("cbs storage is not exist") + } + return nil + } +} + +const testAccInternationalCbsStorage_basic = ` +resource "tencentcloud_cbs_storage" "storage_basic" { + storage_type = "CLOUD_PREMIUM" + storage_name = "tf-storage-basic" + storage_size = 50 + availability_zone = "ap-guangzhou-3" +} +` diff --git a/tencentcloud/services/cdb/resource_tc_mysql_instance_international_test.go b/tencentcloud/services/cdb/resource_tc_mysql_instance_international_test.go new file mode 100644 index 0000000000..2cbee55b23 --- /dev/null +++ b/tencentcloud/services/cdb/resource_tc_mysql_instance_international_test.go @@ -0,0 +1,80 @@ +package cdb_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudMysqlResource_instance(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheck(t) }, + Providers: tcacctest.AccProviders, + CheckDestroy: testAccCheckMysqlMasterInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInternationalMysqlMasterInstance_basic(), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMysqlMasterInstanceExists("tencentcloud_mysql_instance.mysql_master"), + resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "instance_name", TestAccTencentCloudMysqlInstanceName), + resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "slave_deploy_mode", "0"), + resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "slave_sync_mode", "2"), + resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "availability_zone", TestAccTencentCloudMysqlMasterInstance_availability_zone), + resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "first_slave_zone", TestAccTencentCloudMysqlMasterInstance_availability_zone), + resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "second_slave_zone", TestAccTencentCloudMysqlMasterInstance_availability_zone), + ), + }, + { + Config: testAccInternationalMysqlMasterInstanceUp_basic(), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMysqlMasterInstanceExists("tencentcloud_mysql_instance.mysql_master"), + resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "instance_name", TestAccTencentCloudMysqlInstanceName), + resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "slave_deploy_mode", "1"), + resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "slave_sync_mode", "1"), + resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "availability_zone", TestAccTencentCloudMysqlMasterInstance_availability_zone), + resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "first_slave_zone", TestAccTencentCloudMysqlMasterInstance_availability_zone_4), + resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "second_slave_zone", TestAccTencentCloudMysqlMasterInstance_availability_zone_4), + ), + }, + }, + }) +} + +func testAccInternationalMysqlMasterInstance_basic() string { + return ` +resource "tencentcloud_mysql_instance" "mysql_master" { + charge_type = "POSTPAID" + mem_size = 1000 + volume_size = 50 + instance_name = "testAccMysql" + engine_version = "5.7" + root_password = "test1234" + intranet_port = 3360 + availability_zone = "ap-guangzhou-3" + slave_deploy_mode = 0 + first_slave_zone = "ap-guangzhou-3" + second_slave_zone = "ap-guangzhou-3" + slave_sync_mode = 2 + force_delete = true +}` +} + +func testAccInternationalMysqlMasterInstanceUp_basic() string { + return ` +resource "tencentcloud_mysql_instance" "mysql_master" { + charge_type = "POSTPAID" + mem_size = 1000 + volume_size = 50 + instance_name = "testAccMysql" + engine_version = "5.7" + root_password = "test1234" + intranet_port = 3360 + availability_zone = "ap-guangzhou-3" + slave_deploy_mode = 1 + first_slave_zone = "ap-guangzhou-4" + second_slave_zone = "ap-guangzhou-4" + slave_sync_mode = 1 + force_delete = true +}` +} diff --git a/tencentcloud/services/ckafka/resource_tc_ckafka_instance_international_test.go b/tencentcloud/services/ckafka/resource_tc_ckafka_instance_international_test.go new file mode 100644 index 0000000000..2923756f5b --- /dev/null +++ b/tencentcloud/services/ckafka/resource_tc_ckafka_instance_international_test.go @@ -0,0 +1,170 @@ +package ckafka_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudInternationalCkafkaResource_instance(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheck(t) }, + Providers: tcacctest.AccProviders, + CheckDestroy: testAccTencentCloudKafkaInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInternationalKafkaInstancePostpaid, + Check: resource.ComposeTestCheckFunc( + testAccCheckKafkaInstanceExists("tencentcloud_ckafka_instance.kafka_instance_postpaid"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance_postpaid", "instance_name", "ckafka-instance-postpaid"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance_postpaid", "zone_id", "100007"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance_postpaid", "msg_retention_time", "1300"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance_postpaid", "kafka_version", "1.1.1"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance_postpaid", "disk_size", "500"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance_postpaid", "disk_type", "CLOUD_BASIC"), + resource.TestCheckResourceAttrSet("tencentcloud_ckafka_instance.kafka_instance_postpaid", "vip"), + resource.TestCheckResourceAttrSet("tencentcloud_ckafka_instance.kafka_instance_postpaid", "vport"), + ), + }, + { + Config: testAccInternationalKafkaInstanceUpdatePostpaid, + Check: resource.ComposeTestCheckFunc( + testAccCheckKafkaInstanceExists("tencentcloud_ckafka_instance.kafka_instance_postpaid"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance_postpaid", "instance_name", "ckafka-instance-postpaid"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance_postpaid", "zone_id", "100007"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance_postpaid", "msg_retention_time", "1200"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance_postpaid", "kafka_version", "1.1.1"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance_postpaid", "disk_size", "500"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_instance.kafka_instance_postpaid", "disk_type", "CLOUD_BASIC"), + ), + }, + { + ResourceName: "tencentcloud_ckafka_instance.kafka_instance_postpaid", + ImportState: true, + ImportStateVerifyIgnore: []string{"period", "max_message_byte", "charge_type", "upgrade_strategy"}, + }, + }, + }) +} + +const testAccInternationalKafkaInstancePostpaid = tcacctest.DefaultKafkaVariable + ` +resource "tencentcloud_ckafka_instance" "kafka_instance_postpaid" { + instance_name = "ckafka-instance-postpaid" + zone_id = 100007 + vpc_id = var.international_vpc_id + subnet_id = var.international_subnet_id + msg_retention_time = 1300 + kafka_version = "1.1.1" + disk_size = 500 + band_width = 20 + disk_type = "CLOUD_BASIC" + partition = 400 + charge_type = "POSTPAID_BY_HOUR" + + config { + auto_create_topic_enable = true + default_num_partitions = 3 + default_replication_factor = 3 + } + + dynamic_retention_config { + enable = 1 + } +} + +resource "tencentcloud_ckafka_topic" "foo" { + instance_id = tencentcloud_ckafka_instance.kafka_instance_postpaid.id + topic_name = "tmp" + note = "topic note" + replica_num = 2 + partition_num = 1 + clean_up_policy = "delete" + sync_replica_min_num = 1 + unclean_leader_election_enable = false + retention = 60000 +} +` + +const testAccInternationalKafkaInstanceUpdatePostpaid = tcacctest.DefaultKafkaVariable + ` +resource "tencentcloud_ckafka_instance" "kafka_instance_postpaid" { + instance_name = "ckafka-instance-postpaid" + zone_id = 100007 + vpc_id = var.international_vpc_id + subnet_id = var.international_subnet_id + msg_retention_time = 1200 + kafka_version = "1.1.1" + disk_type = "CLOUD_BASIC" + disk_size = 500 + band_width = 20 + charge_type = "POSTPAID_BY_HOUR" + + config { + auto_create_topic_enable = true + default_num_partitions = 3 + default_replication_factor = 3 + } + + dynamic_retention_config { + enable = 1 + } + + tag_set = { + createdBy = "terraform" + } +} + +resource "tencentcloud_ckafka_topic" "foo" { + instance_id = tencentcloud_ckafka_instance.kafka_instance_postpaid.id + topic_name = "tmp" + note = "topic note" + replica_num = 2 + partition_num = 1 + clean_up_policy = "delete" + sync_replica_min_num = 1 + unclean_leader_election_enable = false + retention = 60000 +} +` + +const testAccInternationalKafkaInstanceUpdatePostpaidDiskSize = tcacctest.DefaultKafkaVariable + ` +resource "tencentcloud_ckafka_instance" "kafka_instance_postpaid" { + instance_name = "ckafka-instance-postpaid" + zone_id = 100007 + vpc_id = var.international_vpc_id + subnet_id = var.international_subnet_id + msg_retention_time = 1200 + kafka_version = "1.1.1" + disk_type = "CLOUD_BASIC" + disk_size = 400 + band_width = 20 + charge_type = "POSTPAID_BY_HOUR" + + config { + auto_create_topic_enable = true + default_num_partitions = 3 + default_replication_factor = 3 + } + + dynamic_retention_config { + enable = 1 + } + + tag_set = { + createdBy = "terraform" + } +} + +resource "tencentcloud_ckafka_topic" "foo" { + instance_id = tencentcloud_ckafka_instance.kafka_instance_postpaid.id + topic_name = "tmp" + note = "topic note" + replica_num = 2 + partition_num = 1 + clean_up_policy = "delete" + sync_replica_min_num = 1 + unclean_leader_election_enable = false + retention = 60000 +} +` diff --git a/tencentcloud/services/ckafka/resource_tc_ckafka_topic_international_test.go b/tencentcloud/services/ckafka/resource_tc_ckafka_topic_international_test.go new file mode 100644 index 0000000000..0d3ee827f6 --- /dev/null +++ b/tencentcloud/services/ckafka/resource_tc_ckafka_topic_international_test.go @@ -0,0 +1,86 @@ +package ckafka_test + +import ( + "testing" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudInternationalCkafkaResource_topic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheck(t) }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccInternationalKafkaTopicInstance, + Check: resource.ComposeTestCheckFunc( + testAccCheckKafkaTopicInstanceExists("tencentcloud_ckafka_topic.kafka_topic"), + resource.TestCheckResourceAttrSet("tencentcloud_ckafka_topic.kafka_topic", "instance_id"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_topic.kafka_topic", "topic_name", "ckafka-topic-tf-test"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_topic.kafka_topic", "note", "this is test ckafka topic"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_topic.kafka_topic", "replica_num", "2"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_topic.kafka_topic", "partition_num", "2"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_topic.kafka_topic", "enable_white_list", "true"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_topic.kafka_topic", "ip_white_list.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_topic.kafka_topic", "ip_white_list.0", "192.168.1.1"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_topic.kafka_topic", "clean_up_policy", "delete"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_topic.kafka_topic", "sync_replica_min_num", "1"), + resource.TestCheckResourceAttrSet("tencentcloud_ckafka_topic.kafka_topic", "unclean_leader_election_enable"), + resource.TestCheckResourceAttr("tencentcloud_ckafka_topic.kafka_topic", "segment", "86400000"), + ), + }, + { + PreConfig: func() { + time.Sleep(60 * time.Second) + }, + ResourceName: "tencentcloud_ckafka_topic.kafka_topic", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccInternationalKafkaTopicInstance = tcacctest.DefaultKafkaVariable + ` +resource "tencentcloud_ckafka_instance" "kafka_instance_postpaid" { + instance_name = "ckafka-instance-postpaid" + zone_id = 100007 + vpc_id = var.international_vpc_id + subnet_id = var.international_subnet_id + msg_retention_time = 1300 + kafka_version = "1.1.1" + disk_size = 500 + band_width = 20 + disk_type = "CLOUD_BASIC" + partition = 400 + charge_type = "POSTPAID_BY_HOUR" + + config { + auto_create_topic_enable = true + default_num_partitions = 3 + default_replication_factor = 3 + } + + dynamic_retention_config { + enable = 1 + } +} + +resource "tencentcloud_ckafka_topic" "kafka_topic" { + instance_id = tencentcloud_ckafka_instance.kafka_instance_postpaid.id + topic_name = "ckafka-topic-tf-test" + note = "this is test ckafka topic" + replica_num = 2 + partition_num = 2 + enable_white_list = true + ip_white_list = ["192.168.1.1"] + clean_up_policy = "delete" + sync_replica_min_num = 1 + unclean_leader_election_enable = false + segment = 86400000 + max_message_bytes = 1024 +} +` diff --git a/tencentcloud/services/clb/resource_tc_clb_instance_international_test.go b/tencentcloud/services/clb/resource_tc_clb_instance_international_test.go new file mode 100644 index 0000000000..f6b9a049f5 --- /dev/null +++ b/tencentcloud/services/clb/resource_tc_clb_instance_international_test.go @@ -0,0 +1,47 @@ +package clb_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudInternationalClbResource_instance(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheck(t) }, + Providers: tcacctest.AccProviders, + CheckDestroy: testAccCheckClbInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInternationalClbInstance_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckClbInstanceExists("tencentcloud_clb_instance.clb_basic"), + resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_basic", "network_type", "OPEN"), + resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_basic", "clb_name", "tf-clb"), + resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_basic", "tags.test", "tf"), + resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_basic", "tags.test1", "tf1"), + ), + }, + { + ResourceName: "tencentcloud_clb_instance.clb_basic", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"dynamic_vip"}, + }, + }, + }) +} + +const testAccInternationalClbInstance_basic = ` +resource "tencentcloud_clb_instance" "clb_basic" { + network_type = "OPEN" + clb_name = "tf-clb" + tags = { + test = "tf" + test1 = "tf1" + } +} +` diff --git a/tencentcloud/services/clb/resource_tc_clb_listener_international_test.go b/tencentcloud/services/clb/resource_tc_clb_listener_international_test.go new file mode 100644 index 0000000000..7ceda3b8b6 --- /dev/null +++ b/tencentcloud/services/clb/resource_tc_clb_listener_international_test.go @@ -0,0 +1,54 @@ +package clb_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudInternationalClbResource_listener(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheck(t) }, + Providers: tcacctest.AccProviders, + CheckDestroy: testAccCheckClbListenerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInternationalClbListener_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckClbListenerExists("tencentcloud_clb_listener.listener_basic"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_listener.listener_basic", "clb_id"), + resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic", "protocol", "TCP"), + resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic", "listener_name", "listener_basic"), + resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic", "session_expire_time", "30"), + resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic", "port", "1"), + resource.TestCheckResourceAttr("tencentcloud_clb_listener.listener_basic", "scheduler", "WRR"), + ), + }, + { + ResourceName: "tencentcloud_clb_listener.listener_basic", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccInternationalClbListener_basic = ` +resource "tencentcloud_clb_instance" "clb_basic" { + network_type = "OPEN" + clb_name = "tf-clb-listener-basic" +} + +resource "tencentcloud_clb_listener" "listener_basic" { + clb_id = tencentcloud_clb_instance.clb_basic.id + port = 1 + protocol = "TCP" + listener_name = "listener_basic" + session_expire_time = 30 + scheduler = "WRR" + target_type = "TARGETGROUP" +} +` diff --git a/tencentcloud/services/cvm/resource_tc_instance_international_test.go b/tencentcloud/services/cvm/resource_tc_instance_international_test.go new file mode 100644 index 0000000000..edf3523ef2 --- /dev/null +++ b/tencentcloud/services/cvm/resource_tc_instance_international_test.go @@ -0,0 +1,52 @@ +package cvm_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudInstanceResource_basic(t *testing.T) { + t.Parallel() + + id := "tencentcloud_instance.cvm_basic" + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheck(t) }, + IDRefreshName: id, + Providers: tcacctest.AccProviders, + CheckDestroy: testAccCheckInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInternationalTencentCloudInstanceBasic, + Check: resource.ComposeTestCheckFunc( + tcacctest.AccCheckTencentCloudDataSourceID(id), + testAccCheckTencentCloudInstanceExists(id), + resource.TestCheckResourceAttr(id, "instance_status", "RUNNING"), + resource.TestCheckResourceAttrSet(id, "private_ip"), + resource.TestCheckResourceAttrSet(id, "vpc_id"), + resource.TestCheckResourceAttrSet(id, "subnet_id"), + resource.TestCheckResourceAttrSet(id, "project_id"), + ), + }, + { + ResourceName: id, + ImportState: true, + ImportStateVerifyIgnore: []string{"disable_monitor_service", "disable_security_service", "hostname", "password", "force_delete"}, + }, + }, + }) +} + +const testAccInternationalTencentCloudInstanceBasic = tcacctest.DefaultInstanceVariable + ` +resource "tencentcloud_instance" "cvm_basic" { + instance_name = var.instance_name + availability_zone = var.availability_cvm_international_zone + image_id = data.tencentcloud_images.default.images.0.image_id + instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type + vpc_id = var.cvm_international_vpc_id + subnet_id = var.cvm_international_subnet_id + system_disk_type = "CLOUD_PREMIUM" + project_id = 0 +} +`