@@ -53,6 +53,20 @@ func resourceVPCAccessConnector() *schema.Resource {
53
53
Description : `The range of internal addresses that follows RFC 4632 notation. Example: '10.132.0.0/28'.` ,
54
54
RequiredWith : []string {"network" },
55
55
},
56
+ "machine_type" : {
57
+ Type : schema .TypeString ,
58
+ Optional : true ,
59
+ ForceNew : true ,
60
+ Description : `Machine type of VM Instance underlying connector. Default is e2-micro` ,
61
+ Default : "e2-micro" ,
62
+ },
63
+ "max_instances" : {
64
+ Type : schema .TypeInt ,
65
+ Computed : true ,
66
+ Optional : true ,
67
+ ForceNew : true ,
68
+ Description : `Maximum value of instances in autoscaling group underlying the connector.` ,
69
+ },
56
70
"max_throughput" : {
57
71
Type : schema .TypeInt ,
58
72
Optional : true ,
@@ -61,6 +75,13 @@ func resourceVPCAccessConnector() *schema.Resource {
61
75
Description : `Maximum throughput of the connector in Mbps, must be greater than 'min_throughput'. Default is 300.` ,
62
76
Default : 300 ,
63
77
},
78
+ "min_instances" : {
79
+ Type : schema .TypeInt ,
80
+ Computed : true ,
81
+ Optional : true ,
82
+ ForceNew : true ,
83
+ Description : `Minimum value of instances in autoscaling group underlying the connector.` ,
84
+ },
64
85
"min_throughput" : {
65
86
Type : schema .TypeInt ,
66
87
Optional : true ,
@@ -76,7 +97,7 @@ func resourceVPCAccessConnector() *schema.Resource {
76
97
ForceNew : true ,
77
98
DiffSuppressFunc : compareResourceNames ,
78
99
Description : `Name or self_link of the VPC network. Required if 'ip_cidr_range' is set.` ,
79
- ExactlyOneOf : []string {"network" },
100
+ ExactlyOneOf : []string {"network" , "subnet.0.name" },
80
101
},
81
102
"region" : {
82
103
Type : schema .TypeString ,
@@ -85,6 +106,32 @@ func resourceVPCAccessConnector() *schema.Resource {
85
106
ForceNew : true ,
86
107
Description : `Region where the VPC Access connector resides. If it is not provided, the provider region is used.` ,
87
108
},
109
+ "subnet" : {
110
+ Type : schema .TypeList ,
111
+ Optional : true ,
112
+ ForceNew : true ,
113
+ Description : `The subnet in which to house the connector` ,
114
+ MaxItems : 1 ,
115
+ Elem : & schema.Resource {
116
+ Schema : map [string ]* schema.Schema {
117
+ "name" : {
118
+ Type : schema .TypeString ,
119
+ Optional : true ,
120
+ ForceNew : true ,
121
+ Description : `Subnet name (relative, not fully qualified). E.g. if the full subnet selfLink is
122
+ https://compute.googleapis.com/compute/v1/projects/{project}/regions/{region}/subnetworks/{subnetName} the correct input for this field would be {subnetName}"` ,
123
+ ExactlyOneOf : []string {"network" , "subnet.0.name" },
124
+ },
125
+ "project_id" : {
126
+ Type : schema .TypeString ,
127
+ Computed : true ,
128
+ Optional : true ,
129
+ ForceNew : true ,
130
+ Description : `Project in which the subnet exists. If not set, this project is assumed to be the project for which the connector create request was issued.` ,
131
+ },
132
+ },
133
+ },
134
+ },
88
135
"self_link" : {
89
136
Type : schema .TypeString ,
90
137
Computed : true ,
@@ -132,18 +179,42 @@ func resourceVPCAccessConnectorCreate(d *schema.ResourceData, meta interface{})
132
179
} else if v , ok := d .GetOkExists ("ip_cidr_range" ); ! isEmptyValue (reflect .ValueOf (ipCidrRangeProp )) && (ok || ! reflect .DeepEqual (v , ipCidrRangeProp )) {
133
180
obj ["ipCidrRange" ] = ipCidrRangeProp
134
181
}
182
+ machineTypeProp , err := expandVPCAccessConnectorMachineType (d .Get ("machine_type" ), d , config )
183
+ if err != nil {
184
+ return err
185
+ } else if v , ok := d .GetOkExists ("machine_type" ); ! isEmptyValue (reflect .ValueOf (machineTypeProp )) && (ok || ! reflect .DeepEqual (v , machineTypeProp )) {
186
+ obj ["machineType" ] = machineTypeProp
187
+ }
135
188
minThroughputProp , err := expandVPCAccessConnectorMinThroughput (d .Get ("min_throughput" ), d , config )
136
189
if err != nil {
137
190
return err
138
191
} else if v , ok := d .GetOkExists ("min_throughput" ); ! isEmptyValue (reflect .ValueOf (minThroughputProp )) && (ok || ! reflect .DeepEqual (v , minThroughputProp )) {
139
192
obj ["minThroughput" ] = minThroughputProp
140
193
}
194
+ minInstancesProp , err := expandVPCAccessConnectorMinInstances (d .Get ("min_instances" ), d , config )
195
+ if err != nil {
196
+ return err
197
+ } else if v , ok := d .GetOkExists ("min_instances" ); ! isEmptyValue (reflect .ValueOf (minInstancesProp )) && (ok || ! reflect .DeepEqual (v , minInstancesProp )) {
198
+ obj ["minInstances" ] = minInstancesProp
199
+ }
200
+ maxInstancesProp , err := expandVPCAccessConnectorMaxInstances (d .Get ("max_instances" ), d , config )
201
+ if err != nil {
202
+ return err
203
+ } else if v , ok := d .GetOkExists ("max_instances" ); ! isEmptyValue (reflect .ValueOf (maxInstancesProp )) && (ok || ! reflect .DeepEqual (v , maxInstancesProp )) {
204
+ obj ["maxInstances" ] = maxInstancesProp
205
+ }
141
206
maxThroughputProp , err := expandVPCAccessConnectorMaxThroughput (d .Get ("max_throughput" ), d , config )
142
207
if err != nil {
143
208
return err
144
209
} else if v , ok := d .GetOkExists ("max_throughput" ); ! isEmptyValue (reflect .ValueOf (maxThroughputProp )) && (ok || ! reflect .DeepEqual (v , maxThroughputProp )) {
145
210
obj ["maxThroughput" ] = maxThroughputProp
146
211
}
212
+ subnetProp , err := expandVPCAccessConnectorSubnet (d .Get ("subnet" ), d , config )
213
+ if err != nil {
214
+ return err
215
+ } else if v , ok := d .GetOkExists ("subnet" ); ! isEmptyValue (reflect .ValueOf (subnetProp )) && (ok || ! reflect .DeepEqual (v , subnetProp )) {
216
+ obj ["subnet" ] = subnetProp
217
+ }
147
218
148
219
obj , err = resourceVPCAccessConnectorEncoder (d , meta , obj )
149
220
if err != nil {
@@ -281,12 +352,24 @@ func resourceVPCAccessConnectorRead(d *schema.ResourceData, meta interface{}) er
281
352
if err := d .Set ("state" , flattenVPCAccessConnectorState (res ["state" ], d , config )); err != nil {
282
353
return fmt .Errorf ("Error reading Connector: %s" , err )
283
354
}
355
+ if err := d .Set ("machine_type" , flattenVPCAccessConnectorMachineType (res ["machineType" ], d , config )); err != nil {
356
+ return fmt .Errorf ("Error reading Connector: %s" , err )
357
+ }
284
358
if err := d .Set ("min_throughput" , flattenVPCAccessConnectorMinThroughput (res ["minThroughput" ], d , config )); err != nil {
285
359
return fmt .Errorf ("Error reading Connector: %s" , err )
286
360
}
361
+ if err := d .Set ("min_instances" , flattenVPCAccessConnectorMinInstances (res ["minInstances" ], d , config )); err != nil {
362
+ return fmt .Errorf ("Error reading Connector: %s" , err )
363
+ }
364
+ if err := d .Set ("max_instances" , flattenVPCAccessConnectorMaxInstances (res ["maxInstances" ], d , config )); err != nil {
365
+ return fmt .Errorf ("Error reading Connector: %s" , err )
366
+ }
287
367
if err := d .Set ("max_throughput" , flattenVPCAccessConnectorMaxThroughput (res ["maxThroughput" ], d , config )); err != nil {
288
368
return fmt .Errorf ("Error reading Connector: %s" , err )
289
369
}
370
+ if err := d .Set ("subnet" , flattenVPCAccessConnectorSubnet (res ["subnet" ], d , config )); err != nil {
371
+ return fmt .Errorf ("Error reading Connector: %s" , err )
372
+ }
290
373
291
374
return nil
292
375
}
@@ -379,6 +462,10 @@ func flattenVPCAccessConnectorState(v interface{}, d *schema.ResourceData, confi
379
462
return v
380
463
}
381
464
465
+ func flattenVPCAccessConnectorMachineType (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
466
+ return v
467
+ }
468
+
382
469
func flattenVPCAccessConnectorMinThroughput (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
383
470
// Handles the string fixed64 format
384
471
if strVal , ok := v .(string ); ok {
@@ -396,6 +483,40 @@ func flattenVPCAccessConnectorMinThroughput(v interface{}, d *schema.ResourceDat
396
483
return v // let terraform core handle it otherwise
397
484
}
398
485
486
+ func flattenVPCAccessConnectorMinInstances (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
487
+ // Handles the string fixed64 format
488
+ if strVal , ok := v .(string ); ok {
489
+ if intVal , err := stringToFixed64 (strVal ); err == nil {
490
+ return intVal
491
+ }
492
+ }
493
+
494
+ // number values are represented as float64
495
+ if floatVal , ok := v .(float64 ); ok {
496
+ intVal := int (floatVal )
497
+ return intVal
498
+ }
499
+
500
+ return v // let terraform core handle it otherwise
501
+ }
502
+
503
+ func flattenVPCAccessConnectorMaxInstances (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
504
+ // Handles the string fixed64 format
505
+ if strVal , ok := v .(string ); ok {
506
+ if intVal , err := stringToFixed64 (strVal ); err == nil {
507
+ return intVal
508
+ }
509
+ }
510
+
511
+ // number values are represented as float64
512
+ if floatVal , ok := v .(float64 ); ok {
513
+ intVal := int (floatVal )
514
+ return intVal
515
+ }
516
+
517
+ return v // let terraform core handle it otherwise
518
+ }
519
+
399
520
func flattenVPCAccessConnectorMaxThroughput (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
400
521
// Handles the string fixed64 format
401
522
if strVal , ok := v .(string ); ok {
@@ -413,6 +534,29 @@ func flattenVPCAccessConnectorMaxThroughput(v interface{}, d *schema.ResourceDat
413
534
return v // let terraform core handle it otherwise
414
535
}
415
536
537
+ func flattenVPCAccessConnectorSubnet (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
538
+ if v == nil {
539
+ return nil
540
+ }
541
+ original := v .(map [string ]interface {})
542
+ if len (original ) == 0 {
543
+ return nil
544
+ }
545
+ transformed := make (map [string ]interface {})
546
+ transformed ["name" ] =
547
+ flattenVPCAccessConnectorSubnetName (original ["name" ], d , config )
548
+ transformed ["project_id" ] =
549
+ flattenVPCAccessConnectorSubnetProjectId (original ["projectId" ], d , config )
550
+ return []interface {}{transformed }
551
+ }
552
+ func flattenVPCAccessConnectorSubnetName (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
553
+ return v
554
+ }
555
+
556
+ func flattenVPCAccessConnectorSubnetProjectId (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
557
+ return v
558
+ }
559
+
416
560
func expandVPCAccessConnectorName (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
417
561
return v , nil
418
562
}
@@ -425,14 +569,60 @@ func expandVPCAccessConnectorIpCidrRange(v interface{}, d TerraformResourceData,
425
569
return v , nil
426
570
}
427
571
572
+ func expandVPCAccessConnectorMachineType (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
573
+ return v , nil
574
+ }
575
+
428
576
func expandVPCAccessConnectorMinThroughput (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
429
577
return v , nil
430
578
}
431
579
580
+ func expandVPCAccessConnectorMinInstances (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
581
+ return v , nil
582
+ }
583
+
584
+ func expandVPCAccessConnectorMaxInstances (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
585
+ return v , nil
586
+ }
587
+
432
588
func expandVPCAccessConnectorMaxThroughput (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
433
589
return v , nil
434
590
}
435
591
592
+ func expandVPCAccessConnectorSubnet (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
593
+ l := v .([]interface {})
594
+ if len (l ) == 0 || l [0 ] == nil {
595
+ return nil , nil
596
+ }
597
+ raw := l [0 ]
598
+ original := raw .(map [string ]interface {})
599
+ transformed := make (map [string ]interface {})
600
+
601
+ transformedName , err := expandVPCAccessConnectorSubnetName (original ["name" ], d , config )
602
+ if err != nil {
603
+ return nil , err
604
+ } else if val := reflect .ValueOf (transformedName ); val .IsValid () && ! isEmptyValue (val ) {
605
+ transformed ["name" ] = transformedName
606
+ }
607
+
608
+ transformedProjectId , err := expandVPCAccessConnectorSubnetProjectId (original ["project_id" ], d , config )
609
+ if err != nil {
610
+ return nil , err
611
+ } else if val := reflect .ValueOf (transformedProjectId ); val .IsValid () && ! isEmptyValue (val ) {
612
+ transformed ["projectId" ] = transformedProjectId
613
+ }
614
+
615
+ return transformed , nil
616
+ }
617
+
618
+ func expandVPCAccessConnectorSubnetName (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
619
+ return v , nil
620
+ }
621
+
622
+ func expandVPCAccessConnectorSubnetProjectId (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
623
+ return v , nil
624
+ }
625
+
436
626
func resourceVPCAccessConnectorEncoder (d * schema.ResourceData , meta interface {}, obj map [string ]interface {}) (map [string ]interface {}, error ) {
437
627
delete (obj , "name" )
438
628
return obj , nil
0 commit comments