Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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" {
}

`
43 changes: 43 additions & 0 deletions tencentcloud/resource_tc_cbs_storage_testing_test.go
Original file line number Diff line number Diff line change
@@ -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"},
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个资源不支持修改吗

},
})
}

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"
}
`
69 changes: 69 additions & 0 deletions tencentcloud/resource_tc_mysql_account_testing_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
76 changes: 76 additions & 0 deletions tencentcloud/resource_tc_vpc_acl_testing_test.go
Original file line number Diff line number Diff line change
@@ -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"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个资源不支持 import 吗

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",
]
}
`
50 changes: 50 additions & 0 deletions tencentcloud/resource_tc_vpc_dhcp_ip_testing_test.go
Original file line number Diff line number Diff line change
@@ -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"
}
`
70 changes: 70 additions & 0 deletions tencentcloud/resource_tc_vpc_flow_log_testing_test.go
Original file line number Diff line number Diff line change
@@ -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"
}
`
Loading