1818package vpcaccess
1919
2020import (
21- "context"
2221 "fmt"
2322 "log"
2423 "reflect"
25- "strings"
2624 "time"
2725
28- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
2926 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
3027 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
3128
3229 "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
3330 transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
3431)
3532
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-
4133func ResourceVPCAccessConnector () * schema.Resource {
4234 return & schema.Resource {
4335 Create : resourceVPCAccessConnectorCreate ,
4436 Read : resourceVPCAccessConnectorRead ,
45- Update : resourceVPCAccessConnectorUpdate ,
4637 Delete : resourceVPCAccessConnectorDelete ,
4738
4839 Importer : & schema.ResourceImporter {
@@ -51,14 +42,9 @@ func ResourceVPCAccessConnector() *schema.Resource {
5142
5243 Timeouts : & schema.ResourceTimeout {
5344 Create : schema .DefaultTimeout (20 * time .Minute ),
54- Update : schema .DefaultTimeout (20 * time .Minute ),
5545 Delete : schema .DefaultTimeout (20 * time .Minute ),
5646 },
5747
58- CustomizeDiff : customdiff .All (
59- customdiff .ForceNewIfChange ("min_instances" , AreInstancesReduced ),
60- customdiff .ForceNewIfChange ("max_instances" , AreInstancesReduced )),
61-
6248 Schema : map [string ]* schema.Schema {
6349 "name" : {
6450 Type : schema .TypeString ,
@@ -76,36 +62,39 @@ func ResourceVPCAccessConnector() *schema.Resource {
7662 "machine_type" : {
7763 Type : schema .TypeString ,
7864 Optional : true ,
65+ ForceNew : true ,
7966 Description : `Machine type of VM Instance underlying connector. Default is e2-micro` ,
8067 Default : "e2-micro" ,
8168 },
8269 "max_instances" : {
8370 Type : schema .TypeInt ,
8471 Computed : true ,
8572 Optional : true ,
73+ ForceNew : true ,
8674 Description : `Maximum value of instances in autoscaling group underlying the connector.` ,
8775 },
8876 "max_throughput" : {
8977 Type : schema .TypeInt ,
90- Computed : true ,
9178 Optional : true ,
9279 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 ,
9583 },
9684 "min_instances" : {
9785 Type : schema .TypeInt ,
9886 Computed : true ,
9987 Optional : true ,
88+ ForceNew : true ,
10089 Description : `Minimum value of instances in autoscaling group underlying the connector.` ,
10190 },
10291 "min_throughput" : {
10392 Type : schema .TypeInt ,
104- Computed : true ,
10593 Optional : true ,
10694 ForceNew : true ,
107- ValidateFunc : validation .IntBetween (200 , 900 ),
95+ ValidateFunc : validation .IntBetween (200 , 1000 ),
10896 Description : `Minimum throughput of the connector in Mbps. Default and min is 200.` ,
97+ Default : 200 ,
10998 },
11099 "network" : {
111100 Type : schema .TypeString ,
@@ -416,104 +405,6 @@ func resourceVPCAccessConnectorRead(d *schema.ResourceData, meta interface{}) er
416405 return nil
417406}
418407
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-
517408func resourceVPCAccessConnectorDelete (d * schema.ResourceData , meta interface {}) error {
518409 config := meta .(* transport_tpg.Config )
519410 userAgent , err := tpgresource .GenerateUserAgentString (d , config .UserAgent )
0 commit comments