18
18
package vpcaccess
19
19
20
20
import (
21
- "context"
22
21
"fmt"
23
22
"log"
24
23
"reflect"
25
- "strings"
26
24
"time"
27
25
28
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
29
26
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
30
27
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
31
28
32
29
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
33
30
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
34
31
)
35
32
36
- // Are the number of min/max instances reduced?
37
- func AreInstancesReduced (_ context.Context , old , new , _ interface {}) bool {
38
- return new .(int ) < old .(int )
39
- }
40
-
41
33
func ResourceVPCAccessConnector () * schema.Resource {
42
34
return & schema.Resource {
43
35
Create : resourceVPCAccessConnectorCreate ,
44
36
Read : resourceVPCAccessConnectorRead ,
45
- Update : resourceVPCAccessConnectorUpdate ,
46
37
Delete : resourceVPCAccessConnectorDelete ,
47
38
48
39
Importer : & schema.ResourceImporter {
@@ -51,14 +42,9 @@ func ResourceVPCAccessConnector() *schema.Resource {
51
42
52
43
Timeouts : & schema.ResourceTimeout {
53
44
Create : schema .DefaultTimeout (20 * time .Minute ),
54
- Update : schema .DefaultTimeout (20 * time .Minute ),
55
45
Delete : schema .DefaultTimeout (20 * time .Minute ),
56
46
},
57
47
58
- CustomizeDiff : customdiff .All (
59
- customdiff .ForceNewIfChange ("min_instances" , AreInstancesReduced ),
60
- customdiff .ForceNewIfChange ("max_instances" , AreInstancesReduced )),
61
-
62
48
Schema : map [string ]* schema.Schema {
63
49
"name" : {
64
50
Type : schema .TypeString ,
@@ -76,36 +62,39 @@ func ResourceVPCAccessConnector() *schema.Resource {
76
62
"machine_type" : {
77
63
Type : schema .TypeString ,
78
64
Optional : true ,
65
+ ForceNew : true ,
79
66
Description : `Machine type of VM Instance underlying connector. Default is e2-micro` ,
80
67
Default : "e2-micro" ,
81
68
},
82
69
"max_instances" : {
83
70
Type : schema .TypeInt ,
84
71
Computed : true ,
85
72
Optional : true ,
73
+ ForceNew : true ,
86
74
Description : `Maximum value of instances in autoscaling group underlying the connector.` ,
87
75
},
88
76
"max_throughput" : {
89
77
Type : schema .TypeInt ,
90
- Computed : true ,
91
78
Optional : true ,
92
79
ForceNew : true ,
93
- ValidateFunc : validation .IntBetween (300 , 1000 ),
94
- Description : `Maximum throughput of the connector in Mbps, must be greater than 'min_throughput'. Default is 1000.` ,
80
+ ValidateFunc : validation .IntBetween (200 , 1000 ),
81
+ Description : `Maximum throughput of the connector in Mbps, must be greater than 'min_throughput'. Default is 300.` ,
82
+ Default : 300 ,
95
83
},
96
84
"min_instances" : {
97
85
Type : schema .TypeInt ,
98
86
Computed : true ,
99
87
Optional : true ,
88
+ ForceNew : true ,
100
89
Description : `Minimum value of instances in autoscaling group underlying the connector.` ,
101
90
},
102
91
"min_throughput" : {
103
92
Type : schema .TypeInt ,
104
- Computed : true ,
105
93
Optional : true ,
106
94
ForceNew : true ,
107
- ValidateFunc : validation .IntBetween (200 , 900 ),
95
+ ValidateFunc : validation .IntBetween (200 , 1000 ),
108
96
Description : `Minimum throughput of the connector in Mbps. Default and min is 200.` ,
97
+ Default : 200 ,
109
98
},
110
99
"network" : {
111
100
Type : schema .TypeString ,
@@ -416,104 +405,6 @@ func resourceVPCAccessConnectorRead(d *schema.ResourceData, meta interface{}) er
416
405
return nil
417
406
}
418
407
419
- func resourceVPCAccessConnectorUpdate (d * schema.ResourceData , meta interface {}) error {
420
- config := meta .(* transport_tpg.Config )
421
- userAgent , err := tpgresource .GenerateUserAgentString (d , config .UserAgent )
422
- if err != nil {
423
- return err
424
- }
425
-
426
- billingProject := ""
427
-
428
- project , err := tpgresource .GetProject (d , config )
429
- if err != nil {
430
- return fmt .Errorf ("Error fetching project for Connector: %s" , err )
431
- }
432
- billingProject = project
433
-
434
- obj := make (map [string ]interface {})
435
- machineTypeProp , err := expandVPCAccessConnectorMachineType (d .Get ("machine_type" ), d , config )
436
- if err != nil {
437
- return err
438
- } else if v , ok := d .GetOkExists ("machine_type" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , machineTypeProp )) {
439
- obj ["machineType" ] = machineTypeProp
440
- }
441
- minInstancesProp , err := expandVPCAccessConnectorMinInstances (d .Get ("min_instances" ), d , config )
442
- if err != nil {
443
- return err
444
- } else if v , ok := d .GetOkExists ("min_instances" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , minInstancesProp )) {
445
- obj ["minInstances" ] = minInstancesProp
446
- }
447
- maxInstancesProp , err := expandVPCAccessConnectorMaxInstances (d .Get ("max_instances" ), d , config )
448
- if err != nil {
449
- return err
450
- } else if v , ok := d .GetOkExists ("max_instances" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , maxInstancesProp )) {
451
- obj ["maxInstances" ] = maxInstancesProp
452
- }
453
-
454
- obj , err = resourceVPCAccessConnectorEncoder (d , meta , obj )
455
- if err != nil {
456
- return err
457
- }
458
-
459
- url , err := tpgresource .ReplaceVars (d , config , "{{VPCAccessBasePath}}projects/{{project}}/locations/{{region}}/connectors/{{name}}" )
460
- if err != nil {
461
- return err
462
- }
463
-
464
- log .Printf ("[DEBUG] Updating Connector %q: %#v" , d .Id (), obj )
465
- updateMask := []string {}
466
-
467
- if d .HasChange ("machine_type" ) {
468
- updateMask = append (updateMask , "machineType" )
469
- }
470
-
471
- if d .HasChange ("min_instances" ) {
472
- updateMask = append (updateMask , "minInstances" )
473
- }
474
-
475
- if d .HasChange ("max_instances" ) {
476
- updateMask = append (updateMask , "maxInstances" )
477
- }
478
- // updateMask is a URL parameter but not present in the schema, so ReplaceVars
479
- // won't set it
480
- url , err = transport_tpg .AddQueryParams (url , map [string ]string {"updateMask" : strings .Join (updateMask , "," )})
481
- if err != nil {
482
- return err
483
- }
484
-
485
- // err == nil indicates that the billing_project value was found
486
- if bp , err := tpgresource .GetBillingProject (d , config ); err == nil {
487
- billingProject = bp
488
- }
489
-
490
- res , err := transport_tpg .SendRequest (transport_tpg.SendRequestOptions {
491
- Config : config ,
492
- Method : "PATCH" ,
493
- Project : billingProject ,
494
- RawURL : url ,
495
- UserAgent : userAgent ,
496
- Body : obj ,
497
- Timeout : d .Timeout (schema .TimeoutUpdate ),
498
- })
499
-
500
- if err != nil {
501
- return fmt .Errorf ("Error updating Connector %q: %s" , d .Id (), err )
502
- } else {
503
- log .Printf ("[DEBUG] Finished updating Connector %q: %#v" , d .Id (), res )
504
- }
505
-
506
- err = VPCAccessOperationWaitTime (
507
- config , res , project , "Updating Connector" , userAgent ,
508
- d .Timeout (schema .TimeoutUpdate ))
509
-
510
- if err != nil {
511
- return err
512
- }
513
-
514
- return resourceVPCAccessConnectorRead (d , meta )
515
- }
516
-
517
408
func resourceVPCAccessConnectorDelete (d * schema.ResourceData , meta interface {}) error {
518
409
config := meta .(* transport_tpg.Config )
519
410
userAgent , err := tpgresource .GenerateUserAgentString (d , config .UserAgent )
0 commit comments