@@ -15,6 +15,7 @@ import (
15
15
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
16
16
)
17
17
18
+ // go test -i; go test -test.run TestAccTencentCloudMonitorInstance_basic -v
18
19
func TestAccTencentCloudMonitorInstance_basic (t * testing.T ) {
19
20
t .Parallel ()
20
21
resource .Test (t , resource.TestCase {
@@ -25,24 +26,30 @@ func TestAccTencentCloudMonitorInstance_basic(t *testing.T) {
25
26
{
26
27
Config : testInstance_basic ,
27
28
Check : resource .ComposeTestCheckFunc (
28
- testAccCheckInstanceExists ("tencentcloud_monitor_tmp_instance.basic" ),
29
- resource .TestCheckResourceAttr ("tencentcloud_monitor_tmp_instance.basic" , "instance_name" , "demo-test" ),
30
- resource .TestCheckResourceAttr ("tencentcloud_monitor_tmp_instance.basic" , "data_retention_time" , "30" ),
29
+ testAccCheckInstanceExists ("tencentcloud_monitor_tmp_instance.example" ),
30
+ resource .TestCheckResourceAttr ("tencentcloud_monitor_tmp_instance.example" , "instance_name" , "tf-tmp-instance" ),
31
+ resource .TestCheckResourceAttrSet ("tencentcloud_monitor_tmp_instance.example" , "vpc_id" ),
32
+ resource .TestCheckResourceAttrSet ("tencentcloud_monitor_tmp_instance.example" , "subnet_id" ),
33
+ resource .TestCheckResourceAttr ("tencentcloud_monitor_tmp_instance.example" , "data_retention_time" , "30" ),
34
+ resource .TestCheckResourceAttrSet ("tencentcloud_monitor_tmp_instance.example" , "zone" ),
31
35
),
32
36
},
33
37
{
34
38
Config : testInstance_update ,
35
39
Check : resource .ComposeTestCheckFunc (
36
- testAccCheckInstanceExists ("tencentcloud_monitor_tmp_instance.update" ),
37
- resource .TestCheckResourceAttr ("tencentcloud_monitor_tmp_instance.update" , "instance_name" , "demo-test-update" ),
38
- resource .TestCheckResourceAttr ("tencentcloud_monitor_tmp_instance.update" , "data_retention_time" , "30" ),
40
+ testAccCheckInstanceExists ("tencentcloud_monitor_tmp_instance.example" ),
41
+ resource .TestCheckResourceAttr ("tencentcloud_monitor_tmp_instance.example" , "instance_name" , "tf-tmp-instance-update" ),
42
+ resource .TestCheckResourceAttrSet ("tencentcloud_monitor_tmp_instance.example" , "vpc_id" ),
43
+ resource .TestCheckResourceAttrSet ("tencentcloud_monitor_tmp_instance.example" , "subnet_id" ),
44
+ resource .TestCheckResourceAttr ("tencentcloud_monitor_tmp_instance.example" , "data_retention_time" , "90" ),
45
+ resource .TestCheckResourceAttrSet ("tencentcloud_monitor_tmp_instance.example" , "zone" ),
39
46
),
40
47
},
41
- // {
42
- // ResourceName: "tencentcloud_monitor_tmp_instance.basic ",
43
- // ImportState: true,
44
- // ImportStateVerify: true,
45
- // },
48
+ {
49
+ ResourceName : "tencentcloud_monitor_tmp_instance.example " ,
50
+ ImportState : true ,
51
+ ImportStateVerify : true ,
52
+ },
46
53
},
47
54
})
48
55
}
@@ -103,34 +110,60 @@ func testAccCheckInstanceExists(r string) resource.TestCheckFunc {
103
110
}
104
111
}
105
112
106
- const testInstanceVar = tcacctest .DefaultAzVariable + `
107
- variable "vpc_id" {
108
- default = "` + tcacctest .DefaultTmpVpcId + `"
113
+ const testInstance_basic = `
114
+ variable "availability_zone" {
115
+ default = "ap-guangzhou-4"
116
+ }
117
+
118
+ resource "tencentcloud_vpc" "vpc" {
119
+ cidr_block = "10.0.0.0/16"
120
+ name = "tf_monitor_vpc"
121
+ }
122
+
123
+ resource "tencentcloud_subnet" "subnet" {
124
+ vpc_id = tencentcloud_vpc.vpc.id
125
+ availability_zone = var.availability_zone
126
+ name = "tf_monitor_subnet"
127
+ cidr_block = "10.0.1.0/24"
128
+ }
129
+
130
+ resource "tencentcloud_monitor_tmp_instance" "example" {
131
+ instance_name = "tf-tmp-instance"
132
+ vpc_id = tencentcloud_vpc.vpc.id
133
+ subnet_id = tencentcloud_subnet.subnet.id
134
+ data_retention_time = 30
135
+ zone = var.availability_zone
136
+ tags = {
137
+ "createdBy" = "terraform"
138
+ }
109
139
}
110
- variable "subnet_id" {
111
- default = "` + tcacctest .DefaultTmpSubnetId + `"
140
+ `
141
+
142
+ const testInstance_update = `
143
+ variable "availability_zone" {
144
+ default = "ap-guangzhou-4"
145
+ }
146
+
147
+ resource "tencentcloud_vpc" "vpc" {
148
+ cidr_block = "10.0.0.0/16"
149
+ name = "tf_monitor_vpc"
150
+ }
151
+
152
+ resource "tencentcloud_subnet" "subnet" {
153
+ vpc_id = tencentcloud_vpc.vpc.id
154
+ availability_zone = var.availability_zone
155
+ name = "tf_monitor_subnet"
156
+ cidr_block = "10.0.1.0/24"
157
+ }
158
+
159
+ resource "tencentcloud_monitor_tmp_instance" "example" {
160
+ instance_name = "tf-tmp-instance-update"
161
+ vpc_id = tencentcloud_vpc.vpc.id
162
+ subnet_id = tencentcloud_subnet.subnet.id
163
+ data_retention_time = 90
164
+ zone = var.availability_zone
165
+ tags = {
166
+ "createdBy" = "terraformUpdate"
167
+ }
112
168
}
113
169
`
114
- const testInstance_basic = testInstanceVar + `
115
- resource "tencentcloud_monitor_tmp_instance" "basic" {
116
- instance_name = "demo-test"
117
- vpc_id = var.vpc_id
118
- subnet_id = var.subnet_id
119
- data_retention_time = 30
120
- zone = var.default_az
121
- tags = {
122
- "createdBy" = "terraform"
123
- }
124
- }`
125
-
126
- const testInstance_update = testInstanceVar + `
127
- resource "tencentcloud_monitor_tmp_instance" "update" {
128
- instance_name = "demo-test-update"
129
- vpc_id = var.vpc_id
130
- subnet_id = var.subnet_id
131
- data_retention_time = 30
132
- zone = var.default_az
133
- tags = {
134
- "createdBy" = "terraform"
135
- }
136
- }`
0 commit comments