diff --git a/tencentcloud/data_source_tc_teo_zone_available_plans_testing_test.go b/tencentcloud/data_source_tc_teo_zone_available_plans_testing_test.go new file mode 100644 index 0000000000..5c4aae3a99 --- /dev/null +++ b/tencentcloud/data_source_tc_teo_zone_available_plans_testing_test.go @@ -0,0 +1,32 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +// go test -i; go test -test.run TestAccTencentCloudTestingTeoZoneAvailablePlansDataSource -v +func TestAccTencentCloudTestingTeoZoneAvailablePlansDataSource(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceTestingTeoZoneAvailablePlans, + Check: resource.ComposeTestCheckFunc( + testAccCheckTencentCloudDataSourceID("data.tencentcloud_teo_zone_available_plans.zone_available_plans"), + ), + }, + }, + }) +} + +const testAccDataSourceTestingTeoZoneAvailablePlans = ` + +data "tencentcloud_teo_zone_available_plans" "zone_available_plans" { +} + +` diff --git a/tencentcloud/resource_tc_cbs_storage_testing_test.go b/tencentcloud/resource_tc_cbs_storage_testing_test.go new file mode 100644 index 0000000000..f871c21c47 --- /dev/null +++ b/tencentcloud/resource_tc_cbs_storage_testing_test.go @@ -0,0 +1,43 @@ +package tencentcloud + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "testing" +) + +func TestAccTencentCloudTestingCbsStorageResource_basic(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCbsStorageDestroy, + Steps: []resource.TestStep{ + { + Config: testAccTestingCbsStorage_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckStorageExists("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"}, + }, + }, + }) +} + +const testAccTestingCbsStorage_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/resource_tc_mysql_account_testing_test.go b/tencentcloud/resource_tc_mysql_account_testing_test.go new file mode 100644 index 0000000000..a0482a64de --- /dev/null +++ b/tencentcloud/resource_tc_mysql_account_testing_test.go @@ -0,0 +1,69 @@ +package tencentcloud + +import ( + "fmt" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "testing" +) + +// go test -i; go test -test.run TestAccTencentCloudTestingMysqlAccountResource_basic -v +func TestAccTencentCloudTestingMysqlAccountResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckMysqlAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccTestingMysqlAccount(), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMysqlAccountExists("tencentcloud_mysql_account.mysql_account"), + resource.TestCheckResourceAttrSet("tencentcloud_mysql_account.mysql_account", "mysql_id"), + resource.TestCheckResourceAttr("tencentcloud_mysql_account.mysql_account", "name", "terraform_test"), + resource.TestCheckResourceAttr("tencentcloud_mysql_account.mysql_account", "description", "test from terraform"), + resource.TestCheckResourceAttr("tencentcloud_mysql_account.mysql_account", "max_user_connections", "10"), + ), + }, + { + Config: testAccTestingMysqlAccountUp(), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMysqlAccountExists("tencentcloud_mysql_account.mysql_account"), + resource.TestCheckResourceAttrSet("tencentcloud_mysql_account.mysql_account", "mysql_id"), + resource.TestCheckResourceAttr("tencentcloud_mysql_account.mysql_account", "name", "terraform_test"), + resource.TestCheckResourceAttr("tencentcloud_mysql_account.mysql_account", "description", "test from terraform"), + resource.TestCheckResourceAttr("tencentcloud_mysql_account.mysql_account", "max_user_connections", "10"), + ), + }, + }, + }) +} + +func testAccTestingMysqlAccount() string { + return fmt.Sprintf(` +%s + +resource "tencentcloud_mysql_account" "mysql_account" { + mysql_id = local.mysql_id + name = "terraform_test" + host = "192.168.0.%%" + password = "Test@123456#" + description = "test from terraform" + max_user_connections = 10 +} + `, CommonPresetMysql) +} + +func testAccTestingMysqlAccountUp() string { + return fmt.Sprintf(` +%s + +resource "tencentcloud_mysql_account" "mysql_account" { + mysql_id = local.mysql_id + name = "terraform_test" + host = "192.168.1.%%" + password = "Test@123456#" + description = "test from terraform" + max_user_connections = 10 +} + `, CommonPresetMysql) +} diff --git a/tencentcloud/resource_tc_vpc_acl_testing_test.go b/tencentcloud/resource_tc_vpc_acl_testing_test.go new file mode 100644 index 0000000000..1338ef4013 --- /dev/null +++ b/tencentcloud/resource_tc_vpc_acl_testing_test.go @@ -0,0 +1,76 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccTencentCloudTestingVpcAclRulesResource_Update(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccTestingVpcACLConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "name", "test_acl"), + resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "ingress.0", "ACCEPT#192.168.1.0/24#80#TCP"), + resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "ingress.1", "ACCEPT#192.168.1.0/24#80-90#TCP"), + resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "egress.0", "ACCEPT#192.168.1.0/24#80#TCP"), + resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "egress.1", "ACCEPT#192.168.1.0/24#80-90#TCP"), + ), + }, + { + Config: testAccTestingVpcACLConfigUpdate, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "name", "test_acl"), + resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "ingress.0", "ACCEPT#192.168.1.0/24#800#TCP"), + resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "ingress.1", "ACCEPT#192.168.1.0/24#800-900#TCP"), + resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "egress.0", "ACCEPT#192.168.1.0/24#800#TCP"), + resource.TestCheckResourceAttr("tencentcloud_vpc_acl.foo", "egress.1", "ACCEPT#192.168.1.0/24#800-900#TCP"), + ), + }, + }, + }) +} + +const testAccTestingVpcACLConfig = defaultVpcVariable + ` +resource "tencentcloud_vpc" "foo" { + name = var.instance_name + cidr_block = var.vpc_cidr +} +resource "tencentcloud_vpc_acl" "foo" { + vpc_id = tencentcloud_vpc.foo.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", + ] +} +` + +const testAccTestingVpcACLConfigUpdate = defaultVpcVariable + ` +resource "tencentcloud_vpc" "foo" { + name = var.instance_name + cidr_block = var.vpc_cidr +} + +resource "tencentcloud_vpc_acl" "foo" { + vpc_id = tencentcloud_vpc.foo.id + name = "test_acl" + ingress = [ + "ACCEPT#192.168.1.0/24#800#TCP", + "ACCEPT#192.168.1.0/24#800-900#TCP", + ] + egress = [ + "ACCEPT#192.168.1.0/24#800#TCP", + "ACCEPT#192.168.1.0/24#800-900#TCP", + ] +} +` diff --git a/tencentcloud/resource_tc_vpc_dhcp_ip_testing_test.go b/tencentcloud/resource_tc_vpc_dhcp_ip_testing_test.go new file mode 100644 index 0000000000..d67c542b84 --- /dev/null +++ b/tencentcloud/resource_tc_vpc_dhcp_ip_testing_test.go @@ -0,0 +1,50 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccTencentCloudTestingVpcDhcpIpResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccTestingVpcDhcpIp, + Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_vpc_dhcp_ip.example", "id")), + }, + { + ResourceName: "tencentcloud_vpc_dhcp_ip.example", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccTestingVpcDhcpIp = ` + +resource "tencentcloud_vpc" "vpc" { + name = "vpc-example" + cidr_block = "10.0.0.0/16" +} + +resource "tencentcloud_subnet" "subnet" { + availability_zone = "ap-guangzhou-2" + name = "subnet-example" + vpc_id = tencentcloud_vpc.vpc.id + cidr_block = "10.0.0.0/16" + is_multicast = false +} + +resource "tencentcloud_vpc_dhcp_ip" "example" { + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + dhcp_ip_name = "tf-example" +} +` diff --git a/tencentcloud/resource_tc_vpc_flow_log_testing_test.go b/tencentcloud/resource_tc_vpc_flow_log_testing_test.go new file mode 100644 index 0000000000..1c955d3564 --- /dev/null +++ b/tencentcloud/resource_tc_vpc_flow_log_testing_test.go @@ -0,0 +1,70 @@ +package tencentcloud + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "testing" +) + +func TestAccTencentCloudTestingVpcFlowLogResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccTestingVpcFlowLog, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_vpc_flow_log.flow_log", "id"), + resource.TestCheckResourceAttr("tencentcloud_vpc_flow_log.flow_log", "flow_log_name", "iac-test-1"), + resource.TestCheckResourceAttr("tencentcloud_vpc_flow_log.flow_log", "flow_log_description", "this is a testing flow log"), + ), + }, + { + ResourceName: "tencentcloud_vpc_flow_log.flow_log", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "cloud_log_region", + "flow_log_storage", + }, + }, + { + Config: testAccTestingVpcFlowLogUpdate, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_vpc_flow_log.flow_log", "id"), + resource.TestCheckResourceAttr("tencentcloud_vpc_flow_log.flow_log", "flow_log_name", "iac-test-2"), + resource.TestCheckResourceAttr("tencentcloud_vpc_flow_log.flow_log", "flow_log_description", "updated"), + ), + }, + }, + }) +} + +const testAccTestingVpcFlowLog = ` + +resource "tencentcloud_vpc_flow_log" "flow_log" { + flow_log_name = "iac-test-1" + resource_type = "NETWORKINTERFACE" + resource_id = "eni-qz9wxgmd" + traffic_type = "ACCEPT" + vpc_id = "vpc-humgpppd" + flow_log_description = "this is a testing flow log" + cloud_log_id = "e6acd27c-365c-4959-8257-751d86657439" # FIXME use data.logsets (not supported) instead + storage_type = "cls" +} +` + +const testAccTestingVpcFlowLogUpdate = ` +resource "tencentcloud_vpc_flow_log" "flow_log" { + flow_log_name = "iac-test-2" + resource_type = "NETWORKINTERFACE" + resource_id = "eni-qz9wxgmd" + traffic_type = "ACCEPT" + vpc_id = "vpc-humgpppd" + flow_log_description = "updated" + cloud_log_id = "e6acd27c-365c-4959-8257-751d86657439" # FIXME use data.logsets (not supported) instead + storage_type = "cls" +} +` diff --git a/tencentcloud/resource_tc_vpc_net_detect_testing_test.go b/tencentcloud/resource_tc_vpc_net_detect_testing_test.go new file mode 100644 index 0000000000..bb5f9ef601 --- /dev/null +++ b/tencentcloud/resource_tc_vpc_net_detect_testing_test.go @@ -0,0 +1,64 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccTencentCloudTestingVpcNetDetectResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccTestingVpcNetDetect, + Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_vpc_net_detect.net_detect", "id")), + }, + { + Config: testAccTestingVpcNetDetectUpdate, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("tencentcloud_vpc_net_detect.net_detect", "net_detect_name", "terraform-for-test"), + ), + }, + { + ResourceName: "tencentcloud_vpc_net_detect.net_detect", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccTestingVpcNetDetect = ` + +resource "tencentcloud_vpc_net_detect" "net_detect" { + net_detect_name = "terraform-test" + vpc_id = "vpc-jxnxbc07" + subnet_id = "subnet-ev908x0w" + next_hop_destination = "nat-bfnnl8wg" + next_hop_type = "NAT" + detect_destination_ip = [ + "172.16.128.110" + ] +} + +` + +const testAccTestingVpcNetDetectUpdate = ` + +resource "tencentcloud_vpc_net_detect" "net_detect" { + net_detect_name = "terraform-for-test" + vpc_id = "vpc-jxnxbc07" + subnet_id = "subnet-ev908x0w" + next_hop_destination = "nat-bfnnl8wg" + next_hop_type = "NAT" + detect_destination_ip = [ + "172.16.128.110" + ] +} + +` diff --git a/tencentcloud/resource_tc_vpc_testing_test.go b/tencentcloud/resource_tc_vpc_testing_test.go new file mode 100644 index 0000000000..e9562cd4dd --- /dev/null +++ b/tencentcloud/resource_tc_vpc_testing_test.go @@ -0,0 +1,58 @@ +package tencentcloud + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "testing" +) + +func TestAccTencentCloudTestingVpcV3Update(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccTestingVpcConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckVpcExists("tencentcloud_vpc.foo"), + resource.TestCheckResourceAttr("tencentcloud_vpc.foo", "cidr_block", defaultVpcCidr), + resource.TestCheckResourceAttr("tencentcloud_vpc.foo", "name", defaultInsName), + resource.TestCheckResourceAttr("tencentcloud_vpc.foo", "is_multicast", "true"), + + resource.TestCheckResourceAttrSet("tencentcloud_vpc.foo", "is_default"), + resource.TestCheckResourceAttrSet("tencentcloud_vpc.foo", "create_time"), + resource.TestCheckResourceAttrSet("tencentcloud_vpc.foo", "dns_servers.#"), + ), + }, + { + Config: testAccTestingVpcConfigUpdate, + Check: resource.ComposeTestCheckFunc( + testAccCheckVpcExists("tencentcloud_vpc.foo"), + resource.TestCheckResourceAttr("tencentcloud_vpc.foo", "cidr_block", defaultVpcCidrLess), + resource.TestCheckResourceAttr("tencentcloud_vpc.foo", "name", defaultInsNameUpdate), + resource.TestCheckResourceAttr("tencentcloud_vpc.foo", "is_multicast", "false"), + + resource.TestCheckResourceAttrSet("tencentcloud_vpc.foo", "is_default"), + resource.TestCheckResourceAttrSet("tencentcloud_vpc.foo", "create_time"), + resource.TestCheckResourceAttrSet("tencentcloud_vpc.foo", "dns_servers.#"), + ), + }, + }, + }) +} + +const testAccTestingVpcConfig = defaultVpcVariable + ` +resource "tencentcloud_vpc" "foo" { + name = var.instance_name + cidr_block = var.vpc_cidr +} +` + +const testAccTestingVpcConfigUpdate = defaultVpcVariable + ` +resource "tencentcloud_vpc" "foo" { + name = var.instance_name_update + cidr_block = var.vpc_cidr_less + + is_multicast = false +} +`