@@ -255,6 +255,7 @@ project-level default tier is used. Possible values: ["PREMIUM", "STANDARD"]`,
255
255
},
256
256
"drain_nat_ips" : {
257
257
Type : schema .TypeSet ,
258
+ Computed : true ,
258
259
Optional : true ,
259
260
Description : `A list of URLs of the IP resources to be drained. These IPs must be
260
261
valid static external IPs that have been assigned to the NAT.` ,
@@ -303,6 +304,19 @@ Supported values include:
303
304
Description : `Timeout (in seconds) for ICMP connections. Defaults to 30s if not set.` ,
304
305
Default : 30 ,
305
306
},
307
+ "initial_nat_ips" : {
308
+ Type : schema .TypeSet ,
309
+ Optional : true ,
310
+ ForceNew : true ,
311
+ Description : `Self-links of NAT IPs to be used as initial value for creation alongside a RouterNatAddress resource.
312
+ Conflicts with natIps and drainNatIps. Only valid if natIpAllocateOption is set to MANUAL_ONLY.` ,
313
+ Elem : & schema.Schema {
314
+ Type : schema .TypeString ,
315
+ DiffSuppressFunc : tpgresource .CompareSelfLinkOrResourceName ,
316
+ },
317
+ Set : computeRouterNatIPsHash ,
318
+ ConflictsWith : []string {"nat_ips" , "drain_nat_ips" },
319
+ },
306
320
"log_config" : {
307
321
Type : schema .TypeList ,
308
322
Optional : true ,
@@ -346,6 +360,7 @@ Platform, or 'MANUAL_ONLY' for only user-allocated NAT IP addresses. Possible va
346
360
},
347
361
"nat_ips" : {
348
362
Type : schema .TypeSet ,
363
+ Computed : true ,
349
364
Optional : true ,
350
365
Description : `Self-links of NAT IPs. Only valid if natIpAllocateOption
351
366
is set to MANUAL_ONLY.
@@ -583,6 +598,12 @@ func resourceComputeRouterNatCreate(d *schema.ResourceData, meta interface{}) er
583
598
} else if v , ok := d .GetOkExists ("nat_ip_allocate_option" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (natIpAllocateOptionProp )) && (ok || ! reflect .DeepEqual (v , natIpAllocateOptionProp )) {
584
599
obj ["natIpAllocateOption" ] = natIpAllocateOptionProp
585
600
}
601
+ initialNatIpsProp , err := expandNestedComputeRouterNatInitialNatIps (d .Get ("initial_nat_ips" ), d , config )
602
+ if err != nil {
603
+ return err
604
+ } else if v , ok := d .GetOkExists ("initial_nat_ips" ); ok || ! reflect .DeepEqual (v , initialNatIpsProp ) {
605
+ obj ["initialNatIps" ] = initialNatIpsProp
606
+ }
586
607
natIpsProp , err := expandNestedComputeRouterNatNatIps (d .Get ("nat_ips" ), d , config )
587
608
if err != nil {
588
609
return err
@@ -692,6 +713,11 @@ func resourceComputeRouterNatCreate(d *schema.ResourceData, meta interface{}) er
692
713
obj ["autoNetworkTier" ] = autoNetworkTierProp
693
714
}
694
715
716
+ obj , err = resourceComputeRouterNatEncoder (d , meta , obj )
717
+ if err != nil {
718
+ return err
719
+ }
720
+
695
721
lockName , err := tpgresource .ReplaceVars (d , config , "router/{{region}}/{{router}}" )
696
722
if err != nil {
697
723
return err
@@ -1023,6 +1049,11 @@ func resourceComputeRouterNatUpdate(d *schema.ResourceData, meta interface{}) er
1023
1049
obj ["autoNetworkTier" ] = autoNetworkTierProp
1024
1050
}
1025
1051
1052
+ obj , err = resourceComputeRouterNatEncoder (d , meta , obj )
1053
+ if err != nil {
1054
+ return err
1055
+ }
1056
+
1026
1057
lockName , err := tpgresource .ReplaceVars (d , config , "router/{{region}}/{{router}}" )
1027
1058
if err != nil {
1028
1059
return err
@@ -1506,6 +1537,23 @@ func expandNestedComputeRouterNatNatIpAllocateOption(v interface{}, d tpgresourc
1506
1537
return v , nil
1507
1538
}
1508
1539
1540
+ func expandNestedComputeRouterNatInitialNatIps (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1541
+ v = v .(* schema.Set ).List ()
1542
+ l := v .([]interface {})
1543
+ req := make ([]interface {}, 0 , len (l ))
1544
+ for _ , raw := range l {
1545
+ if raw == nil {
1546
+ return nil , fmt .Errorf ("Invalid value for initial_nat_ips: nil" )
1547
+ }
1548
+ f , err := tpgresource .ParseRegionalFieldValue ("addresses" , raw .(string ), "project" , "region" , "zone" , d , config , true )
1549
+ if err != nil {
1550
+ return nil , fmt .Errorf ("Invalid value for initial_nat_ips: %s" , err )
1551
+ }
1552
+ req = append (req , f .RelativeLink ())
1553
+ }
1554
+ return req , nil
1555
+ }
1556
+
1509
1557
func expandNestedComputeRouterNatNatIps (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1510
1558
v = v .(* schema.Set ).List ()
1511
1559
l := v .([]interface {})
@@ -1845,6 +1893,24 @@ func expandNestedComputeRouterNatAutoNetworkTier(v interface{}, d tpgresource.Te
1845
1893
return v , nil
1846
1894
}
1847
1895
1896
+ func resourceComputeRouterNatEncoder (d * schema.ResourceData , meta interface {}, obj map [string ]interface {}) (map [string ]interface {}, error ) {
1897
+ // initial_nat_ips uses the same api_name as nat_ips
1898
+ if tpgresource .IsEmptyValue (reflect .ValueOf (obj ["initialNatIps" ])) {
1899
+ return obj , nil
1900
+ }
1901
+
1902
+ newObj := make (map [string ]interface {})
1903
+ for key , value := range obj {
1904
+ newObj [key ] = value
1905
+ }
1906
+
1907
+ newObj ["natIps" ] = obj ["initialNatIps" ]
1908
+ delete (newObj , "initialNatIps" )
1909
+
1910
+ log .Printf ("[DEBUG] Replacing initialNatIps value \n oldObj: %+v \n newObj: %+v" , obj , newObj )
1911
+ return newObj , nil
1912
+ }
1913
+
1848
1914
func flattenNestedComputeRouterNat (d * schema.ResourceData , meta interface {}, res map [string ]interface {}) (map [string ]interface {}, error ) {
1849
1915
var v interface {}
1850
1916
var ok bool
0 commit comments