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
168 changes: 168 additions & 0 deletions tencentcloud/resource_tc_clb_instance_testing_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package tencentcloud

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"testing"
)

func TestAccTencentCloudTestingClbInstanceResource_basic(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckClbInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccTestingClbInstance_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", BasicClbName),
),
},
{
ResourceName: "tencentcloud_clb_instance.clb_basic",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"dynamic_vip"},
},
},
})
}

func TestAccTencentCloudTestingClbInstanceResource_open(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckClbInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccTestingClbInstance_open,
Check: resource.ComposeTestCheckFunc(
testAccCheckClbInstanceExists("tencentcloud_clb_instance.clb_open"),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "network_type", "OPEN"),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "clb_name", OpenClbName),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "project_id", "0"),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "security_groups.#", "1"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.clb_open", "security_groups.0"),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "target_region_info_region", "ap-guangzhou"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.clb_open", "target_region_info_vpc_id"),
),
},
{
Config: testAccTestingClbInstance_update_open,
Check: resource.ComposeTestCheckFunc(
testAccCheckClbInstanceExists("tencentcloud_clb_instance.clb_open"),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "clb_name", OpenClbNameUpdate),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "network_type", "OPEN"),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "project_id", "0"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.clb_open", "vpc_id"),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "security_groups.#", "1"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.clb_open", "security_groups.0"),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "target_region_info_region", "ap-guangzhou"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.clb_open", "target_region_info_vpc_id"),
),
},
},
})
}

func TestAccTencentCloudClbTestingInstanceResource_multiple_instance(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckClbInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccTestingClbInstance_Multi_Instance,
Check: resource.ComposeTestCheckFunc(
testAccCheckClbInstanceExists("tencentcloud_clb_instance.multiple_instance"),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "network_type", "OPEN"),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "clb_name", MultiClbName),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "master_zone_id", "100004"),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "slave_zone_id", "100003"),
),
},
{
Config: testAccTestingClbInstance_Multi_Instance_Update,
Check: resource.ComposeTestCheckFunc(
testAccCheckClbInstanceExists("tencentcloud_clb_instance.multiple_instance"),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "network_type", "OPEN"),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "clb_name", MultiClbName),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "master_zone_id", "100004"),
resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "slave_zone_id", "100003"),
),
},
},
})
}

const testAccTestingClbInstance_basic = `
resource "tencentcloud_clb_instance" "clb_basic" {
network_type = "OPEN"
clb_name = "` + BasicClbName + `"
}
`

const testAccTestingClbInstance_open = `
resource "tencentcloud_security_group" "foo" {
name = "keep-ci-temp-test-sg"
}

resource "tencentcloud_vpc" "foo" {
name = "clb-instance-open-vpc"
cidr_block = "10.0.0.0/16"
}

resource "tencentcloud_clb_instance" "clb_open" {
network_type = "OPEN"
clb_name = "` + OpenClbName + `"
project_id = 0
vpc_id = tencentcloud_vpc.foo.id
target_region_info_region = "ap-guangzhou"
target_region_info_vpc_id = tencentcloud_vpc.foo.id
security_groups = [tencentcloud_security_group.foo.id]
}
`
const testAccTestingClbInstance_update_open = `
resource "tencentcloud_security_group" "foo" {
name = "clb-instance-sg"
}

resource "tencentcloud_vpc" "foo" {
name = "clb-instance-open-vpc"
cidr_block = "10.0.0.0/16"
}

resource "tencentcloud_clb_instance" "clb_open" {
network_type = "OPEN"
clb_name = "` + OpenClbNameUpdate + `"
vpc_id = tencentcloud_vpc.foo.id
project_id = 0
target_region_info_region = "ap-guangzhou"
target_region_info_vpc_id = tencentcloud_vpc.foo.id
security_groups = [tencentcloud_security_group.foo.id]
}
`
const testAccTestingClbInstance_Multi_Instance = `
resource "tencentcloud_clb_instance" "multiple_instance" {
network_type = "OPEN"
clb_name = "` + MultiClbName + `"
master_zone_id = "100004"
slave_zone_id = "100003"
}
`

const testAccTestingClbInstance_Multi_Instance_Update = `
resource "tencentcloud_clb_instance" "multiple_instance" {
network_type = "OPEN"
clb_name = "` + MultiClbName + `"
master_zone_id = "100004"
slave_zone_id = "100003"
}
`
79 changes: 79 additions & 0 deletions tencentcloud/resource_tc_clb_listener_testing_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package tencentcloud

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"testing"
)

func TestAccTencentCloudTestingClbListener_basic(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckClbListenerDestroy,
Steps: []resource.TestStep{
{
Config: testAccClbTestingListener_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"),
),
},
{
Config: testAccClbTestingListenerUpdate_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_update"),
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 testAccClbTestingListener_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"
}
`
const testAccClbTestingListenerUpdate_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_update"
session_expire_time = 30
scheduler = "WRR"
target_type = "TARGETGROUP"
}
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package tencentcloud

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccTencentCloudTestingClbSecurityGroupAttachmentResource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccTestingClbSecurityGroupAttachment,
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_clb_security_group_attachment.security_group_attachment", "id")),
},
{
ResourceName: "tencentcloud_clb_security_group_attachment.security_group_attachment",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

const testAccTestingClbSecurityGroupAttachment = `

resource "tencentcloud_clb_security_group_attachment" "security_group_attachment" {
security_group = "sg-46x20487"
load_balancer_ids = ["lb-d72hklcc"]
}

`
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package tencentcloud

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"testing"
)

func TestAccTencentCloudTestingClbTGAttachmentInstance_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckClbTGAttachmentInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccTestingClbTGAttachmentInstance_basic,
Check: resource.ComposeTestCheckFunc(
testAccCheckClbTGAttachmentInstanceExists("tencentcloud_clb_target_group_instance_attachment.test"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_target_group_instance_attachment.test", "target_group_id"),
resource.TestCheckResourceAttr("tencentcloud_clb_target_group_instance_attachment.test", "bind_ip", "172.16.0.17"),
resource.TestCheckResourceAttr("tencentcloud_clb_target_group_instance_attachment.test", "port", "99"),
resource.TestCheckResourceAttr("tencentcloud_clb_target_group_instance_attachment.test", "weight", "3"),
),
},
{
Config: testAccTestingClbTGAttachmentInstance_update,
Check: resource.ComposeTestCheckFunc(
testAccCheckClbTGAttachmentInstanceExists("tencentcloud_clb_target_group_instance_attachment.test"),
resource.TestCheckResourceAttrSet("tencentcloud_clb_target_group_instance_attachment.test", "target_group_id"),
resource.TestCheckResourceAttr("tencentcloud_clb_target_group_instance_attachment.test", "bind_ip", "172.16.0.17"),
resource.TestCheckResourceAttr("tencentcloud_clb_target_group_instance_attachment.test", "port", "99"),
resource.TestCheckResourceAttr("tencentcloud_clb_target_group_instance_attachment.test", "weight", "5"),
),
},
},
})
}

const testAccTestingClbTGAttachmentInstance_basic = `

resource "tencentcloud_clb_target_group" "test"{
target_group_name = "test"
vpc_id = "vpc-humgpppd"
}

resource "tencentcloud_clb_target_group_instance_attachment" "test"{
target_group_id = tencentcloud_clb_target_group.test.id
bind_ip = "172.16.0.17"
port = 99
weight = 3
}
`

const testAccTestingClbTGAttachmentInstance_update = `

resource "tencentcloud_clb_target_group" "test"{
target_group_name = "test"
vpc_id = "vpc-humgpppd"
}

resource "tencentcloud_clb_target_group_instance_attachment" "test"{
target_group_id = tencentcloud_clb_target_group.test.id
bind_ip = "172.16.0.17"
port = 99
weight = 5
}
`
Loading