@@ -185,8 +185,10 @@ valid static external IPs that have been assigned to the NAT.`,
185
185
Computed : true ,
186
186
Optional : true ,
187
187
Description : `Enable Dynamic Port Allocation.
188
- If minPorts is set, minPortsPerVm must be set to a power of two greater than or equal to 32.
188
+ If minPortsPerVm is set, minPortsPerVm must be set to a power of two greater than or equal to 32.
189
189
If minPortsPerVm is not set, a minimum of 32 ports will be allocated to a VM from this NAT config.
190
+ If maxPortsPerVm is set, maxPortsPerVm must be set to a power of two greater than minPortsPerVm.
191
+ If maxPortsPerVm is not set, a maximum of 65536 ports will be allocated to a VM from this NAT config.
190
192
191
193
Mutually exclusive with enableEndpointIndependentMapping.` ,
192
194
},
@@ -224,6 +226,12 @@ see the [official documentation](https://cloud.google.com/nat/docs/overview#spec
224
226
},
225
227
},
226
228
},
229
+ "max_ports_per_vm" : {
230
+ Type : schema .TypeInt ,
231
+ Optional : true ,
232
+ Description : `Maximum number of ports allocated to a VM from this NAT.
233
+ This field can only be set when enableDynamicPortAllocation is enabled.` ,
234
+ },
227
235
"min_ports_per_vm" : {
228
236
Type : schema .TypeInt ,
229
237
Optional : true ,
@@ -375,6 +383,12 @@ func resourceComputeRouterNatCreate(d *schema.ResourceData, meta interface{}) er
375
383
} else if v , ok := d .GetOkExists ("min_ports_per_vm" ); ! isEmptyValue (reflect .ValueOf (minPortsPerVmProp )) && (ok || ! reflect .DeepEqual (v , minPortsPerVmProp )) {
376
384
obj ["minPortsPerVm" ] = minPortsPerVmProp
377
385
}
386
+ maxPortsPerVmProp , err := expandNestedComputeRouterNatMaxPortsPerVm (d .Get ("max_ports_per_vm" ), d , config )
387
+ if err != nil {
388
+ return err
389
+ } else if v , ok := d .GetOkExists ("max_ports_per_vm" ); ! isEmptyValue (reflect .ValueOf (maxPortsPerVmProp )) && (ok || ! reflect .DeepEqual (v , maxPortsPerVmProp )) {
390
+ obj ["maxPortsPerVm" ] = maxPortsPerVmProp
391
+ }
378
392
enableDynamicPortAllocationProp , err := expandNestedComputeRouterNatEnableDynamicPortAllocation (d .Get ("enable_dynamic_port_allocation" ), d , config )
379
393
if err != nil {
380
394
return err
@@ -543,6 +557,9 @@ func resourceComputeRouterNatRead(d *schema.ResourceData, meta interface{}) erro
543
557
if err := d .Set ("min_ports_per_vm" , flattenNestedComputeRouterNatMinPortsPerVm (res ["minPortsPerVm" ], d , config )); err != nil {
544
558
return fmt .Errorf ("Error reading RouterNat: %s" , err )
545
559
}
560
+ if err := d .Set ("max_ports_per_vm" , flattenNestedComputeRouterNatMaxPortsPerVm (res ["maxPortsPerVm" ], d , config )); err != nil {
561
+ return fmt .Errorf ("Error reading RouterNat: %s" , err )
562
+ }
546
563
if err := d .Set ("enable_dynamic_port_allocation" , flattenNestedComputeRouterNatEnableDynamicPortAllocation (res ["enableDynamicPortAllocation" ], d , config )); err != nil {
547
564
return fmt .Errorf ("Error reading RouterNat: %s" , err )
548
565
}
@@ -620,6 +637,12 @@ func resourceComputeRouterNatUpdate(d *schema.ResourceData, meta interface{}) er
620
637
} else if v , ok := d .GetOkExists ("min_ports_per_vm" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , minPortsPerVmProp )) {
621
638
obj ["minPortsPerVm" ] = minPortsPerVmProp
622
639
}
640
+ maxPortsPerVmProp , err := expandNestedComputeRouterNatMaxPortsPerVm (d .Get ("max_ports_per_vm" ), d , config )
641
+ if err != nil {
642
+ return err
643
+ } else if v , ok := d .GetOkExists ("max_ports_per_vm" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , maxPortsPerVmProp )) {
644
+ obj ["maxPortsPerVm" ] = maxPortsPerVmProp
645
+ }
623
646
enableDynamicPortAllocationProp , err := expandNestedComputeRouterNatEnableDynamicPortAllocation (d .Get ("enable_dynamic_port_allocation" ), d , config )
624
647
if err != nil {
625
648
return err
@@ -868,6 +891,23 @@ func flattenNestedComputeRouterNatMinPortsPerVm(v interface{}, d *schema.Resourc
868
891
return v // let terraform core handle it otherwise
869
892
}
870
893
894
+ func flattenNestedComputeRouterNatMaxPortsPerVm (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
895
+ // Handles the string fixed64 format
896
+ if strVal , ok := v .(string ); ok {
897
+ if intVal , err := stringToFixed64 (strVal ); err == nil {
898
+ return intVal
899
+ }
900
+ }
901
+
902
+ // number values are represented as float64
903
+ if floatVal , ok := v .(float64 ); ok {
904
+ intVal := int (floatVal )
905
+ return intVal
906
+ }
907
+
908
+ return v // let terraform core handle it otherwise
909
+ }
910
+
871
911
func flattenNestedComputeRouterNatEnableDynamicPortAllocation (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
872
912
return v
873
913
}
@@ -1060,6 +1100,10 @@ func expandNestedComputeRouterNatMinPortsPerVm(v interface{}, d TerraformResourc
1060
1100
return v , nil
1061
1101
}
1062
1102
1103
+ func expandNestedComputeRouterNatMaxPortsPerVm (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
1104
+ return v , nil
1105
+ }
1106
+
1063
1107
func expandNestedComputeRouterNatEnableDynamicPortAllocation (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
1064
1108
return v , nil
1065
1109
}
0 commit comments