@@ -6,16 +6,16 @@ import (
66 "time"
77
88 "google.golang.org/api/googleapi"
9- "google.golang.org/api/autoscaler/v1beta2 "
9+ "google.golang.org/api/compute/v1 "
1010 "github.com/hashicorp/terraform/helper/schema"
1111)
1212
13- func resourceAutoscaler () * schema.Resource {
13+ func resourceComputeAutoscaler () * schema.Resource {
1414 return & schema.Resource {
15- Create : resourceAutoscalerCreate ,
16- Read : resourceAutoscalerRead ,
17- Update : resourceAutoscalerUpdate ,
18- Delete : resourceAutoscalerDelete ,
15+ Create : resourceComputeAutoscalerCreate ,
16+ Read : resourceComputeAutoscalerRead ,
17+ Update : resourceComputeAutoscalerUpdate ,
18+ Delete : resourceComputeAutoscalerDelete ,
1919
2020 Schema : map [string ]* schema.Schema {
2121 "name" : & schema.Schema {
@@ -120,10 +120,10 @@ func resourceAutoscaler() *schema.Resource {
120120 }
121121}
122122
123- func buildAutoscaler (d * schema.ResourceData ) (* autoscaler .Autoscaler , error ) {
123+ func buildAutoscaler (d * schema.ResourceData ) (* compute .Autoscaler , error ) {
124124
125125 // Build the parameter
126- scaler := & autoscaler .Autoscaler {
126+ scaler := & compute .Autoscaler {
127127 Name : d .Get ("name" ).(string ),
128128 Target : d .Get ("target" ).(string ),
129129 }
@@ -140,7 +140,7 @@ func buildAutoscaler(d *schema.ResourceData) (*autoscaler.Autoscaler, error) {
140140
141141 prefix := "autoscaling_policy.0."
142142
143- scaler .AutoscalingPolicy = & autoscaler .AutoscalingPolicy {
143+ scaler .AutoscalingPolicy = & compute .AutoscalingPolicy {
144144 MaxNumReplicas : int64 (d .Get (prefix + "max_replicas" ).(int )),
145145 MinNumReplicas : int64 (d .Get (prefix + "min_replicas" ).(int )),
146146 CoolDownPeriodSec : int64 (d .Get (prefix + "cooldown_period" ).(int )),
@@ -156,7 +156,7 @@ func buildAutoscaler(d *schema.ResourceData) (*autoscaler.Autoscaler, error) {
156156 return nil , fmt .Errorf ("The autoscaling_policy must have exactly one cpu_utilization, found %d." , cpuUtilCount )
157157 }
158158 policyCounter ++
159- scaler .AutoscalingPolicy .CpuUtilization = & autoscaler .AutoscalingPolicyCpuUtilization {
159+ scaler .AutoscalingPolicy .CpuUtilization = & compute .AutoscalingPolicyCpuUtilization {
160160 UtilizationTarget : d .Get (prefix + "cpu_utilization.0.target" ).(float64 ),
161161 }
162162 }
@@ -168,7 +168,7 @@ func buildAutoscaler(d *schema.ResourceData) (*autoscaler.Autoscaler, error) {
168168 if metricCount != 1 {
169169 return nil , fmt .Errorf ("The autoscaling_policy must have exactly one metric, found %d." , metricCount )
170170 }
171- scaler .AutoscalingPolicy .CustomMetricUtilizations = []* autoscaler .AutoscalingPolicyCustomMetricUtilization {
171+ scaler .AutoscalingPolicy .CustomMetricUtilizations = []* compute .AutoscalingPolicyCustomMetricUtilization {
172172 {
173173 Metric : d .Get (prefix + "metric.0.name" ).(string ),
174174 UtilizationTarget : d .Get (prefix + "metric.0.target" ).(float64 ),
@@ -185,7 +185,7 @@ func buildAutoscaler(d *schema.ResourceData) (*autoscaler.Autoscaler, error) {
185185 if lbuCount != 1 {
186186 return nil , fmt .Errorf ("The autoscaling_policy must have exactly one load_balancing_utilization, found %d." , lbuCount )
187187 }
188- scaler .AutoscalingPolicy .LoadBalancingUtilization = & autoscaler .AutoscalingPolicyLoadBalancingUtilization {
188+ scaler .AutoscalingPolicy .LoadBalancingUtilization = & compute .AutoscalingPolicyLoadBalancingUtilization {
189189 UtilizationTarget : d .Get (prefix + "load_balancing_utilization.0.target" ).(float64 ),
190190 }
191191 }
@@ -198,7 +198,7 @@ func buildAutoscaler(d *schema.ResourceData) (*autoscaler.Autoscaler, error) {
198198 return scaler , nil
199199}
200200
201- func resourceAutoscalerCreate (d * schema.ResourceData , meta interface {}) error {
201+ func resourceComputeAutoscalerCreate (d * schema.ResourceData , meta interface {}) error {
202202 config := meta .(* Config )
203203
204204 // Get the zone
@@ -215,7 +215,7 @@ func resourceAutoscalerCreate(d *schema.ResourceData, meta interface{}) error {
215215 return err
216216 }
217217
218- op , err := config .clientAutoscaler .Autoscalers .Insert (
218+ op , err := config .clientCompute .Autoscalers .Insert (
219219 config .Project , zone .Name , scaler ).Do ()
220220 if err != nil {
221221 return fmt .Errorf ("Error creating Autoscaler: %s" , err )
@@ -225,10 +225,11 @@ func resourceAutoscalerCreate(d *schema.ResourceData, meta interface{}) error {
225225 d .SetId (scaler .Name )
226226
227227 // Wait for the operation to complete
228- w := & AutoscalerOperationWaiter {
229- Service : config .clientAutoscaler ,
228+ w := & OperationWaiter {
229+ Service : config .clientCompute ,
230230 Op : op ,
231231 Project : config .Project ,
232+ Type : OperationWaitZone ,
232233 Zone : zone .Name ,
233234 }
234235 state := w .Conf ()
@@ -238,23 +239,23 @@ func resourceAutoscalerCreate(d *schema.ResourceData, meta interface{}) error {
238239 if err != nil {
239240 return fmt .Errorf ("Error waiting for Autoscaler to create: %s" , err )
240241 }
241- op = opRaw .(* autoscaler .Operation )
242+ op = opRaw .(* compute .Operation )
242243 if op .Error != nil {
243244 // The resource didn't actually create
244245 d .SetId ("" )
245246
246247 // Return the error
247- return AutoscalerOperationError (* op .Error )
248+ return OperationError (* op .Error )
248249 }
249250
250- return resourceAutoscalerRead (d , meta )
251+ return resourceComputeAutoscalerRead (d , meta )
251252}
252253
253- func resourceAutoscalerRead (d * schema.ResourceData , meta interface {}) error {
254+ func resourceComputeAutoscalerRead (d * schema.ResourceData , meta interface {}) error {
254255 config := meta .(* Config )
255256
256257 zone := d .Get ("zone" ).(string )
257- scaler , err := config .clientAutoscaler .Autoscalers .Get (
258+ scaler , err := config .clientCompute .Autoscalers .Get (
258259 config .Project , zone , d .Id ()).Do ()
259260 if err != nil {
260261 if gerr , ok := err .(* googleapi.Error ); ok && gerr .Code == 404 {
@@ -272,7 +273,7 @@ func resourceAutoscalerRead(d *schema.ResourceData, meta interface{}) error {
272273 return nil
273274}
274275
275- func resourceAutoscalerUpdate (d * schema.ResourceData , meta interface {}) error {
276+ func resourceComputeAutoscalerUpdate (d * schema.ResourceData , meta interface {}) error {
276277 config := meta .(* Config )
277278
278279 zone := d .Get ("zone" ).(string )
@@ -282,7 +283,7 @@ func resourceAutoscalerUpdate(d *schema.ResourceData, meta interface{}) error {
282283 return err
283284 }
284285
285- op , err := config .clientAutoscaler .Autoscalers .Patch (
286+ op , err := config .clientCompute .Autoscalers .Patch (
286287 config .Project , zone , d .Id (), scaler ).Do ()
287288 if err != nil {
288289 return fmt .Errorf ("Error updating Autoscaler: %s" , err )
@@ -292,10 +293,11 @@ func resourceAutoscalerUpdate(d *schema.ResourceData, meta interface{}) error {
292293 d .SetId (scaler .Name )
293294
294295 // Wait for the operation to complete
295- w := & AutoscalerOperationWaiter {
296- Service : config .clientAutoscaler ,
296+ w := & OperationWaiter {
297+ Service : config .clientCompute ,
297298 Op : op ,
298299 Project : config .Project ,
300+ Type : OperationWaitZone ,
299301 Zone : zone ,
300302 }
301303 state := w .Conf ()
@@ -305,30 +307,31 @@ func resourceAutoscalerUpdate(d *schema.ResourceData, meta interface{}) error {
305307 if err != nil {
306308 return fmt .Errorf ("Error waiting for Autoscaler to update: %s" , err )
307309 }
308- op = opRaw .(* autoscaler .Operation )
310+ op = opRaw .(* compute .Operation )
309311 if op .Error != nil {
310312 // Return the error
311- return AutoscalerOperationError (* op .Error )
313+ return OperationError (* op .Error )
312314 }
313315
314- return resourceAutoscalerRead (d , meta )
316+ return resourceComputeAutoscalerRead (d , meta )
315317}
316318
317- func resourceAutoscalerDelete (d * schema.ResourceData , meta interface {}) error {
319+ func resourceComputeAutoscalerDelete (d * schema.ResourceData , meta interface {}) error {
318320 config := meta .(* Config )
319321
320322 zone := d .Get ("zone" ).(string )
321- op , err := config .clientAutoscaler .Autoscalers .Delete (
323+ op , err := config .clientCompute .Autoscalers .Delete (
322324 config .Project , zone , d .Id ()).Do ()
323325 if err != nil {
324326 return fmt .Errorf ("Error deleting autoscaler: %s" , err )
325327 }
326328
327329 // Wait for the operation to complete
328- w := & AutoscalerOperationWaiter {
329- Service : config .clientAutoscaler ,
330+ w := & OperationWaiter {
331+ Service : config .clientCompute ,
330332 Op : op ,
331333 Project : config .Project ,
334+ Type : OperationWaitZone ,
332335 Zone : zone ,
333336 }
334337 state := w .Conf ()
@@ -338,10 +341,10 @@ func resourceAutoscalerDelete(d *schema.ResourceData, meta interface{}) error {
338341 if err != nil {
339342 return fmt .Errorf ("Error waiting for Autoscaler to delete: %s" , err )
340343 }
341- op = opRaw .(* autoscaler .Operation )
344+ op = opRaw .(* compute .Operation )
342345 if op .Error != nil {
343346 // Return the error
344- return AutoscalerOperationError (* op .Error )
347+ return OperationError (* op .Error )
345348 }
346349
347350 d .SetId ("" )
0 commit comments