@@ -3,65 +3,123 @@ package cvm_test
33import (
44 "testing"
55
6- tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
6+ acctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
77
88 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
99)
1010
11- // go test -i; go test -test.run TestAccTencentCloudEipsDataSource_basic -v
12- func TestAccTencentCloudEipsDataSource_basic (t * testing.T ) {
11+ func TestAccTencentCloudCvmEipsDataSource_Basic (t * testing.T ) {
1312 t .Parallel ()
1413 resource .Test (t , resource.TestCase {
15- PreCheck : func () { tcacctest .AccPreCheck (t ) },
16- Providers : tcacctest .AccProviders ,
17- CheckDestroy : testAccCheckEipDestroy ,
14+ PreCheck : func () {
15+ acctest .AccPreCheck (t )
16+ },
17+ Providers : acctest .AccProviders ,
1818 Steps : []resource.TestStep {
1919 {
20- Config : testAccEipsDataSource ,
21- Check : resource .ComposeTestCheckFunc (
22- tcacctest .AccCheckTencentCloudDataSourceID ("data.tencentcloud_eips.example" ),
23- resource .TestCheckResourceAttr ("data.tencentcloud_eips.example" , "eip_list.#" , "0" ),
24-
25- tcacctest .AccCheckTencentCloudDataSourceID ("data.tencentcloud_eips.example_by_id" ),
26- resource .TestCheckResourceAttr ("data.tencentcloud_eips.example_by_id" , "eip_list.#" , "1" ),
27- resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.eip_id" ),
28- resource .TestCheckResourceAttr ("data.tencentcloud_eips.example_by_id" , "eip_list.0.eip_name" , "tf-example" ),
29- resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.eip_type" ),
30- resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.status" ),
31- resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.public_ip" ),
32- resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.create_time" ),
33-
34- tcacctest .AccCheckTencentCloudDataSourceID ("data.tencentcloud_eips.example_by_name" ),
35- resource .TestCheckResourceAttr ("data.tencentcloud_eips.example_by_name" , "eip_list.0.eip_name" , "tf-example" ),
36-
37- tcacctest .AccCheckTencentCloudDataSourceID ("data.tencentcloud_eips.example_by_tags" ),
38- resource .TestCheckResourceAttr ("data.tencentcloud_eips.example_by_tags" , "eip_list.0.tags.test" , "test" ),
39- ),
20+ Config : testAccCvmEipsDataSource_BasicCreate ,
21+ Check : resource .ComposeTestCheckFunc (acctest .AccCheckTencentCloudDataSourceID ("data.tencentcloud_eips.example" )),
4022 },
4123 },
4224 })
4325}
4426
45- const testAccEipsDataSource = `
46- resource "tencentcloud_eip" "example" {
47- name = "tf-example"
27+ const testAccCvmEipsDataSource_BasicCreate = `
28+
29+ data "tencentcloud_eips" "example" {
30+ }
31+
32+ `
4833
49- tags = {
50- "test" = "test"
51- }
34+ func TestAccTencentCloudCvmEipsDataSource_ById (t * testing.T ) {
35+ t .Parallel ()
36+ resource .Test (t , resource.TestCase {
37+ PreCheck : func () {
38+ acctest .AccPreCheck (t )
39+ },
40+ Providers : acctest .AccProviders ,
41+ Steps : []resource.TestStep {
42+ {
43+ Config : testAccCvmEipsDataSource_ByIdCreate ,
44+ Check : resource .ComposeTestCheckFunc (acctest .AccCheckTencentCloudDataSourceID ("data.tencentcloud_eips.example_by_id" ), resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.public_ip" ), resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.create_time" ), resource .TestCheckResourceAttr ("data.tencentcloud_eips.example_by_id" , "eip_list.#" , "1" ), resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.eip_id" ), resource .TestCheckResourceAttr ("data.tencentcloud_eips.example_by_id" , "eip_list.0.eip_name" , "tf-example" ), resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.eip_type" ), resource .TestCheckResourceAttrSet ("data.tencentcloud_eips.example_by_id" , "eip_list.0.status" )),
45+ },
46+ },
47+ })
5248}
5349
54- data "tencentcloud_eips" "example" {}
50+ const testAccCvmEipsDataSource_ByIdCreate = `
5551
5652data "tencentcloud_eips" "example_by_id" {
57- eip_id = tencentcloud_eip.example.id
53+ eip_id = tencentcloud_eip.example.id
54+ }
55+ resource "tencentcloud_eip" "example" {
56+
57+ tags = {
58+ test = "test"
59+ }
60+ name = "tf-example"
5861}
5962
63+ `
64+
65+ func TestAccTencentCloudCvmEipsDataSource_ByName (t * testing.T ) {
66+ t .Parallel ()
67+ resource .Test (t , resource.TestCase {
68+ PreCheck : func () {
69+ acctest .AccPreCheck (t )
70+ },
71+ Providers : acctest .AccProviders ,
72+ Steps : []resource.TestStep {
73+ {
74+ Config : testAccCvmEipsDataSource_ByNameCreate ,
75+ Check : resource .ComposeTestCheckFunc (acctest .AccCheckTencentCloudDataSourceID ("data.tencentcloud_eips.example_by_name" ), resource .TestCheckResourceAttr ("data.tencentcloud_eips.example_by_name" , "eip_list.0.eip_name" , "tf-example" )),
76+ },
77+ },
78+ })
79+ }
80+
81+ const testAccCvmEipsDataSource_ByNameCreate = `
82+
6083data "tencentcloud_eips" "example_by_name" {
61- eip_name = tencentcloud_eip.example.name
84+ eip_name = tencentcloud_eip.example.name
85+ }
86+ resource "tencentcloud_eip" "example" {
87+ name = "tf-example"
88+
89+ tags = {
90+ test = "test"
91+ }
6292}
6393
94+ `
95+
96+ func TestAccTencentCloudCvmEipsDataSource_ByTags (t * testing.T ) {
97+ t .Parallel ()
98+ resource .Test (t , resource.TestCase {
99+ PreCheck : func () {
100+ acctest .AccPreCheck (t )
101+ },
102+ Providers : acctest .AccProviders ,
103+ Steps : []resource.TestStep {
104+ {
105+ Config : testAccCvmEipsDataSource_ByTagsCreate ,
106+ Check : resource .ComposeTestCheckFunc (acctest .AccCheckTencentCloudDataSourceID ("data.tencentcloud_eips.example_by_tags" ), resource .TestCheckResourceAttr ("data.tencentcloud_eips.example_by_tags" , "eip_list.0.tags.test" , "test" )),
107+ },
108+ },
109+ })
110+ }
111+
112+ const testAccCvmEipsDataSource_ByTagsCreate = `
113+
64114data "tencentcloud_eips" "example_by_tags" {
65- tags = tencentcloud_eip.example.tags
115+ tags = tencentcloud_eip.example.tags
66116}
117+ resource "tencentcloud_eip" "example" {
118+ name = "tf-example"
119+
120+ tags = {
121+ test = "test"
122+ }
123+ }
124+
67125`
0 commit comments