|
| 1 | +package tencentcloud |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +func TestAccTencentCloudTestingClbInstanceResource_basic(t *testing.T) { |
| 9 | + t.Parallel() |
| 10 | + |
| 11 | + resource.Test(t, resource.TestCase{ |
| 12 | + PreCheck: func() { testAccPreCheck(t) }, |
| 13 | + Providers: testAccProviders, |
| 14 | + CheckDestroy: testAccCheckClbInstanceDestroy, |
| 15 | + Steps: []resource.TestStep{ |
| 16 | + { |
| 17 | + Config: testAccTestingClbInstance_basic, |
| 18 | + Check: resource.ComposeTestCheckFunc( |
| 19 | + testAccCheckClbInstanceExists("tencentcloud_clb_instance.clb_basic"), |
| 20 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_basic", "network_type", "OPEN"), |
| 21 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_basic", "clb_name", BasicClbName), |
| 22 | + ), |
| 23 | + }, |
| 24 | + { |
| 25 | + ResourceName: "tencentcloud_clb_instance.clb_basic", |
| 26 | + ImportState: true, |
| 27 | + ImportStateVerify: true, |
| 28 | + ImportStateVerifyIgnore: []string{"dynamic_vip"}, |
| 29 | + }, |
| 30 | + }, |
| 31 | + }) |
| 32 | +} |
| 33 | + |
| 34 | +func TestAccTencentCloudTestingClbInstanceResource_open(t *testing.T) { |
| 35 | + t.Parallel() |
| 36 | + |
| 37 | + resource.Test(t, resource.TestCase{ |
| 38 | + PreCheck: func() { testAccPreCheck(t) }, |
| 39 | + Providers: testAccProviders, |
| 40 | + CheckDestroy: testAccCheckClbInstanceDestroy, |
| 41 | + Steps: []resource.TestStep{ |
| 42 | + { |
| 43 | + Config: testAccTestingClbInstance_open, |
| 44 | + Check: resource.ComposeTestCheckFunc( |
| 45 | + testAccCheckClbInstanceExists("tencentcloud_clb_instance.clb_open"), |
| 46 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "network_type", "OPEN"), |
| 47 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "clb_name", OpenClbName), |
| 48 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "project_id", "0"), |
| 49 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "security_groups.#", "1"), |
| 50 | + resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.clb_open", "security_groups.0"), |
| 51 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "target_region_info_region", "ap-guangzhou"), |
| 52 | + resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.clb_open", "target_region_info_vpc_id"), |
| 53 | + ), |
| 54 | + }, |
| 55 | + { |
| 56 | + Config: testAccTestingClbInstance_update_open, |
| 57 | + Check: resource.ComposeTestCheckFunc( |
| 58 | + testAccCheckClbInstanceExists("tencentcloud_clb_instance.clb_open"), |
| 59 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "clb_name", OpenClbNameUpdate), |
| 60 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "network_type", "OPEN"), |
| 61 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "project_id", "0"), |
| 62 | + resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.clb_open", "vpc_id"), |
| 63 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "security_groups.#", "1"), |
| 64 | + resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.clb_open", "security_groups.0"), |
| 65 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.clb_open", "target_region_info_region", "ap-guangzhou"), |
| 66 | + resource.TestCheckResourceAttrSet("tencentcloud_clb_instance.clb_open", "target_region_info_vpc_id"), |
| 67 | + ), |
| 68 | + }, |
| 69 | + }, |
| 70 | + }) |
| 71 | +} |
| 72 | + |
| 73 | +func TestAccTencentCloudClbTestingInstanceResource_multiple_instance(t *testing.T) { |
| 74 | + t.Parallel() |
| 75 | + |
| 76 | + resource.Test(t, resource.TestCase{ |
| 77 | + PreCheck: func() { testAccPreCheck(t) }, |
| 78 | + Providers: testAccProviders, |
| 79 | + CheckDestroy: testAccCheckClbInstanceDestroy, |
| 80 | + Steps: []resource.TestStep{ |
| 81 | + { |
| 82 | + Config: testAccTestingClbInstance_Multi_Instance, |
| 83 | + Check: resource.ComposeTestCheckFunc( |
| 84 | + testAccCheckClbInstanceExists("tencentcloud_clb_instance.multiple_instance"), |
| 85 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "network_type", "OPEN"), |
| 86 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "clb_name", MultiClbName), |
| 87 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "master_zone_id", "100004"), |
| 88 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "slave_zone_id", "100003"), |
| 89 | + ), |
| 90 | + }, |
| 91 | + { |
| 92 | + Config: testAccTestingClbInstance_Multi_Instance_Update, |
| 93 | + Check: resource.ComposeTestCheckFunc( |
| 94 | + testAccCheckClbInstanceExists("tencentcloud_clb_instance.multiple_instance"), |
| 95 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "network_type", "OPEN"), |
| 96 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "clb_name", MultiClbName), |
| 97 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "master_zone_id", "100004"), |
| 98 | + resource.TestCheckResourceAttr("tencentcloud_clb_instance.multiple_instance", "slave_zone_id", "100003"), |
| 99 | + ), |
| 100 | + }, |
| 101 | + }, |
| 102 | + }) |
| 103 | +} |
| 104 | + |
| 105 | +const testAccTestingClbInstance_basic = ` |
| 106 | +resource "tencentcloud_clb_instance" "clb_basic" { |
| 107 | + network_type = "OPEN" |
| 108 | + clb_name = "` + BasicClbName + `" |
| 109 | +} |
| 110 | +` |
| 111 | + |
| 112 | +const testAccTestingClbInstance_open = ` |
| 113 | +resource "tencentcloud_security_group" "foo" { |
| 114 | + name = "keep-ci-temp-test-sg" |
| 115 | +} |
| 116 | +
|
| 117 | +resource "tencentcloud_vpc" "foo" { |
| 118 | + name = "clb-instance-open-vpc" |
| 119 | + cidr_block = "10.0.0.0/16" |
| 120 | +} |
| 121 | +
|
| 122 | +resource "tencentcloud_clb_instance" "clb_open" { |
| 123 | + network_type = "OPEN" |
| 124 | + clb_name = "` + OpenClbName + `" |
| 125 | + project_id = 0 |
| 126 | + vpc_id = tencentcloud_vpc.foo.id |
| 127 | + target_region_info_region = "ap-guangzhou" |
| 128 | + target_region_info_vpc_id = tencentcloud_vpc.foo.id |
| 129 | + security_groups = [tencentcloud_security_group.foo.id] |
| 130 | +} |
| 131 | +` |
| 132 | +const testAccTestingClbInstance_update_open = ` |
| 133 | +resource "tencentcloud_security_group" "foo" { |
| 134 | + name = "clb-instance-sg" |
| 135 | +} |
| 136 | +
|
| 137 | +resource "tencentcloud_vpc" "foo" { |
| 138 | + name = "clb-instance-open-vpc" |
| 139 | + cidr_block = "10.0.0.0/16" |
| 140 | +} |
| 141 | +
|
| 142 | +resource "tencentcloud_clb_instance" "clb_open" { |
| 143 | + network_type = "OPEN" |
| 144 | + clb_name = "` + OpenClbNameUpdate + `" |
| 145 | + vpc_id = tencentcloud_vpc.foo.id |
| 146 | + project_id = 0 |
| 147 | + target_region_info_region = "ap-guangzhou" |
| 148 | + target_region_info_vpc_id = tencentcloud_vpc.foo.id |
| 149 | + security_groups = [tencentcloud_security_group.foo.id] |
| 150 | +} |
| 151 | +` |
| 152 | +const testAccTestingClbInstance_Multi_Instance = ` |
| 153 | +resource "tencentcloud_clb_instance" "multiple_instance" { |
| 154 | + network_type = "OPEN" |
| 155 | + clb_name = "` + MultiClbName + `" |
| 156 | + master_zone_id = "100004" |
| 157 | + slave_zone_id = "100003" |
| 158 | +} |
| 159 | +` |
| 160 | + |
| 161 | +const testAccTestingClbInstance_Multi_Instance_Update = ` |
| 162 | +resource "tencentcloud_clb_instance" "multiple_instance" { |
| 163 | + network_type = "OPEN" |
| 164 | + clb_name = "` + MultiClbName + `" |
| 165 | + master_zone_id = "100004" |
| 166 | + slave_zone_id = "100003" |
| 167 | +} |
| 168 | +` |
0 commit comments