@@ -11,13 +11,47 @@ import (
11
11
)
12
12
13
13
func TestAccContainerNodePool_basic (t * testing.T ) {
14
+ cluster := fmt .Sprintf ("tf-nodepool-test-%s" , acctest .RandString (10 ))
15
+ np := fmt .Sprintf ("tf-nodepool-test-%s" , acctest .RandString (10 ))
16
+
14
17
resource .Test (t , resource.TestCase {
15
18
PreCheck : func () { testAccPreCheck (t ) },
16
19
Providers : testAccProviders ,
17
20
CheckDestroy : testAccCheckContainerNodePoolDestroy ,
18
21
Steps : []resource.TestStep {
19
22
resource.TestStep {
20
- Config : testAccContainerNodePool_basic ,
23
+ Config : testAccContainerNodePool_basic (cluster , np ),
24
+ Check : resource .ComposeTestCheckFunc (
25
+ testAccCheckContainerNodePoolMatches ("google_container_node_pool.np" ),
26
+ ),
27
+ },
28
+ },
29
+ })
30
+ }
31
+
32
+ func TestAccContainerNodePool_autoscaling (t * testing.T ) {
33
+ cluster := fmt .Sprintf ("tf-nodepool-test-%s" , acctest .RandString (10 ))
34
+ np := fmt .Sprintf ("tf-nodepool-test-%s" , acctest .RandString (10 ))
35
+
36
+ resource .Test (t , resource.TestCase {
37
+ PreCheck : func () { testAccPreCheck (t ) },
38
+ Providers : testAccProviders ,
39
+ CheckDestroy : testAccCheckContainerNodePoolDestroy ,
40
+ Steps : []resource.TestStep {
41
+ resource.TestStep {
42
+ Config : testAccContainerNodePool_autoscaling (cluster , np ),
43
+ Check : resource .ComposeTestCheckFunc (
44
+ testAccCheckContainerNodePoolMatches ("google_container_node_pool.np" ),
45
+ ),
46
+ },
47
+ resource.TestStep {
48
+ Config : testAccContainerNodePool_updateAutoscaling (cluster , np ),
49
+ Check : resource .ComposeTestCheckFunc (
50
+ testAccCheckContainerNodePoolMatches ("google_container_node_pool.np" ),
51
+ ),
52
+ },
53
+ resource.TestStep {
54
+ Config : testAccContainerNodePool_basic (cluster , np ),
21
55
Check : resource .ComposeTestCheckFunc (
22
56
testAccCheckContainerNodePoolMatches ("google_container_node_pool.np" ),
23
57
),
@@ -77,13 +111,32 @@ func testAccCheckContainerNodePoolMatches(n string) resource.TestCheckFunc {
77
111
return fmt .Errorf ("Mismatched initialNodeCount. TF State: %s. GCP State: %d" ,
78
112
attributes ["initial_node_count" ], found .InitialNodeCount )
79
113
}
114
+
115
+ tfAS := attributes ["autoscaling.#" ] == "1"
116
+ if gcpAS := found .Autoscaling != nil && found .Autoscaling .Enabled == true ; tfAS != gcpAS {
117
+ return fmt .Errorf ("Mismatched autoscaling status. TF State: %t. GCP State: %t" , tfAS , gcpAS )
118
+ }
119
+ if tfAS {
120
+ if tf := attributes ["autoscaling.0.min_node_count" ]; strconv .FormatInt (found .Autoscaling .MinNodeCount , 10 ) != tf {
121
+ return fmt .Errorf ("Mismatched Autoscaling.MinNodeCount. TF State: %s. GCP State: %d" ,
122
+ tf , found .Autoscaling .MinNodeCount )
123
+ }
124
+
125
+ if tf := attributes ["autoscaling.0.max_node_count" ]; strconv .FormatInt (found .Autoscaling .MaxNodeCount , 10 ) != tf {
126
+ return fmt .Errorf ("Mismatched Autoscaling.MaxNodeCount. TF State: %s. GCP State: %d" ,
127
+ tf , found .Autoscaling .MaxNodeCount )
128
+ }
129
+
130
+ }
131
+
80
132
return nil
81
133
}
82
134
}
83
135
84
- var testAccContainerNodePool_basic = fmt .Sprintf (`
136
+ func testAccContainerNodePool_basic (cluster , np string ) string {
137
+ return fmt .Sprintf (`
85
138
resource "google_container_cluster" "cluster" {
86
- name = "tf-cluster-nodepool-test- %s"
139
+ name = "%s"
87
140
zone = "us-central1-a"
88
141
initial_node_count = 3
89
142
@@ -94,8 +147,59 @@ resource "google_container_cluster" "cluster" {
94
147
}
95
148
96
149
resource "google_container_node_pool" "np" {
97
- name = "tf-nodepool-test- %s"
150
+ name = "%s"
98
151
zone = "us-central1-a"
99
152
cluster = "${google_container_cluster.cluster.name}"
100
153
initial_node_count = 2
101
- }` , acctest .RandString (10 ), acctest .RandString (10 ))
154
+ }` , cluster , np )
155
+ }
156
+
157
+ func testAccContainerNodePool_autoscaling (cluster , np string ) string {
158
+ return fmt .Sprintf (`
159
+ resource "google_container_cluster" "cluster" {
160
+ name = "%s"
161
+ zone = "us-central1-a"
162
+ initial_node_count = 3
163
+
164
+ master_auth {
165
+ username = "mr.yoda"
166
+ password = "adoy.rm"
167
+ }
168
+ }
169
+
170
+ resource "google_container_node_pool" "np" {
171
+ name = "%s"
172
+ zone = "us-central1-a"
173
+ cluster = "${google_container_cluster.cluster.name}"
174
+ initial_node_count = 2
175
+ autoscaling {
176
+ min_node_count = 1
177
+ max_node_count = 3
178
+ }
179
+ }` , cluster , np )
180
+ }
181
+
182
+ func testAccContainerNodePool_updateAutoscaling (cluster , np string ) string {
183
+ return fmt .Sprintf (`
184
+ resource "google_container_cluster" "cluster" {
185
+ name = "%s"
186
+ zone = "us-central1-a"
187
+ initial_node_count = 3
188
+
189
+ master_auth {
190
+ username = "mr.yoda"
191
+ password = "adoy.rm"
192
+ }
193
+ }
194
+
195
+ resource "google_container_node_pool" "np" {
196
+ name = "%s"
197
+ zone = "us-central1-a"
198
+ cluster = "${google_container_cluster.cluster.name}"
199
+ initial_node_count = 2
200
+ autoscaling {
201
+ min_node_count = 1
202
+ max_node_count = 5
203
+ }
204
+ }` , cluster , np )
205
+ }
0 commit comments