@@ -181,6 +181,16 @@ valid static external IPs that have been assigned to the NAT.`,
181
181
},
182
182
// Default schema.HashSchema is used.
183
183
},
184
+ "enable_dynamic_port_allocation" : {
185
+ Type : schema .TypeBool ,
186
+ Optional : true ,
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.
189
+ If minPortsPerVm is not set, a minimum of 32 ports will be allocated to a VM from this NAT config.
190
+
191
+ Mutually exclusive with enableEndpointIndependentMapping.` ,
192
+ Default : false ,
193
+ },
184
194
"enable_endpoint_independent_mapping" : {
185
195
Type : schema .TypeBool ,
186
196
Optional : true ,
@@ -366,6 +376,12 @@ func resourceComputeRouterNatCreate(d *schema.ResourceData, meta interface{}) er
366
376
} else if v , ok := d .GetOkExists ("min_ports_per_vm" ); ! isEmptyValue (reflect .ValueOf (minPortsPerVmProp )) && (ok || ! reflect .DeepEqual (v , minPortsPerVmProp )) {
367
377
obj ["minPortsPerVm" ] = minPortsPerVmProp
368
378
}
379
+ enableDynamicPortAllocationProp , err := expandNestedComputeRouterNatEnableDynamicPortAllocation (d .Get ("enable_dynamic_port_allocation" ), d , config )
380
+ if err != nil {
381
+ return err
382
+ } else if v , ok := d .GetOkExists ("enable_dynamic_port_allocation" ); ! isEmptyValue (reflect .ValueOf (enableDynamicPortAllocationProp )) && (ok || ! reflect .DeepEqual (v , enableDynamicPortAllocationProp )) {
383
+ obj ["enableDynamicPortAllocation" ] = enableDynamicPortAllocationProp
384
+ }
369
385
udpIdleTimeoutSecProp , err := expandNestedComputeRouterNatUdpIdleTimeoutSec (d .Get ("udp_idle_timeout_sec" ), d , config )
370
386
if err != nil {
371
387
return err
@@ -528,6 +544,9 @@ func resourceComputeRouterNatRead(d *schema.ResourceData, meta interface{}) erro
528
544
if err := d .Set ("min_ports_per_vm" , flattenNestedComputeRouterNatMinPortsPerVm (res ["minPortsPerVm" ], d , config )); err != nil {
529
545
return fmt .Errorf ("Error reading RouterNat: %s" , err )
530
546
}
547
+ if err := d .Set ("enable_dynamic_port_allocation" , flattenNestedComputeRouterNatEnableDynamicPortAllocation (res ["enableDynamicPortAllocation" ], d , config )); err != nil {
548
+ return fmt .Errorf ("Error reading RouterNat: %s" , err )
549
+ }
531
550
if err := d .Set ("udp_idle_timeout_sec" , flattenNestedComputeRouterNatUdpIdleTimeoutSec (res ["udpIdleTimeoutSec" ], d , config )); err != nil {
532
551
return fmt .Errorf ("Error reading RouterNat: %s" , err )
533
552
}
@@ -602,6 +621,12 @@ func resourceComputeRouterNatUpdate(d *schema.ResourceData, meta interface{}) er
602
621
} else if v , ok := d .GetOkExists ("min_ports_per_vm" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , minPortsPerVmProp )) {
603
622
obj ["minPortsPerVm" ] = minPortsPerVmProp
604
623
}
624
+ enableDynamicPortAllocationProp , err := expandNestedComputeRouterNatEnableDynamicPortAllocation (d .Get ("enable_dynamic_port_allocation" ), d , config )
625
+ if err != nil {
626
+ return err
627
+ } else if v , ok := d .GetOkExists ("enable_dynamic_port_allocation" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , enableDynamicPortAllocationProp )) {
628
+ obj ["enableDynamicPortAllocation" ] = enableDynamicPortAllocationProp
629
+ }
605
630
udpIdleTimeoutSecProp , err := expandNestedComputeRouterNatUdpIdleTimeoutSec (d .Get ("udp_idle_timeout_sec" ), d , config )
606
631
if err != nil {
607
632
return err
@@ -844,6 +869,10 @@ func flattenNestedComputeRouterNatMinPortsPerVm(v interface{}, d *schema.Resourc
844
869
return v // let terraform core handle it otherwise
845
870
}
846
871
872
+ func flattenNestedComputeRouterNatEnableDynamicPortAllocation (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
873
+ return v
874
+ }
875
+
847
876
func flattenNestedComputeRouterNatUdpIdleTimeoutSec (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
848
877
if v == nil || isEmptyValue (reflect .ValueOf (v )) {
849
878
return 30
@@ -1032,6 +1061,10 @@ func expandNestedComputeRouterNatMinPortsPerVm(v interface{}, d TerraformResourc
1032
1061
return v , nil
1033
1062
}
1034
1063
1064
+ func expandNestedComputeRouterNatEnableDynamicPortAllocation (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
1065
+ return v , nil
1066
+ }
1067
+
1035
1068
func expandNestedComputeRouterNatUdpIdleTimeoutSec (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
1036
1069
return v , nil
1037
1070
}
0 commit comments