@@ -235,22 +235,73 @@ false, the specified subnetwork or network should have Private Google Access ena
235235 Optional : true ,
236236 ForceNew : true ,
237237 Description : `The name of the network for the TPU node. It must be a preexisting Google Compute Engine
238- network. If both network and subnetwork are specified, the given subnetwork must belong
239- to the given network. If network is not specified, it will be looked up from the
240- subnetwork if one is provided, or otherwise use "default".` ,
238+ network. If none is provided, "default" will be used.` ,
239+ },
240+ "queue_count" : {
241+ Type : schema .TypeInt ,
242+ Optional : true ,
243+ ForceNew : true ,
244+ Description : `Specifies networking queue count for TPU VM instance's network interface.` ,
245+ },
246+ "subnetwork" : {
247+ Type : schema .TypeString ,
248+ Computed : true ,
249+ Optional : true ,
250+ ForceNew : true ,
251+ Description : `The name of the subnetwork for the TPU node. It must be a preexisting Google Compute
252+ Engine subnetwork. If none is provided, "default" will be used.` ,
253+ },
254+ },
255+ },
256+ ConflictsWith : []string {"network_configs" },
257+ },
258+ "network_configs" : {
259+ Type : schema .TypeList ,
260+ Optional : true ,
261+ ForceNew : true ,
262+ Description : `Repeated network configurations for the TPU node. This field is used to specify multiple
263+ network configs for the TPU node.` ,
264+ Elem : & schema.Resource {
265+ Schema : map [string ]* schema.Schema {
266+ "can_ip_forward" : {
267+ Type : schema .TypeBool ,
268+ Optional : true ,
269+ ForceNew : true ,
270+ Description : `Allows the TPU node to send and receive packets with non-matching destination or source
271+ IPs. This is required if you plan to use the TPU workers to forward routes.` ,
272+ },
273+ "enable_external_ips" : {
274+ Type : schema .TypeBool ,
275+ Optional : true ,
276+ ForceNew : true ,
277+ Description : `Indicates that external IP addresses would be associated with the TPU workers. If set to
278+ false, the specified subnetwork or network should have Private Google Access enabled.` ,
279+ },
280+ "network" : {
281+ Type : schema .TypeString ,
282+ Computed : true ,
283+ Optional : true ,
284+ ForceNew : true ,
285+ Description : `The name of the network for the TPU node. It must be a preexisting Google Compute Engine
286+ network. If none is provided, "default" will be used.` ,
287+ },
288+ "queue_count" : {
289+ Type : schema .TypeInt ,
290+ Optional : true ,
291+ ForceNew : true ,
292+ Description : `Specifies networking queue count for TPU VM instance's network interface.` ,
241293 },
242294 "subnetwork" : {
243295 Type : schema .TypeString ,
244296 Computed : true ,
245297 Optional : true ,
246298 ForceNew : true ,
247299 Description : `The name of the subnetwork for the TPU node. It must be a preexisting Google Compute
248- Engine subnetwork. If both network and subnetwork are specified, the given subnetwork
249- must belong to the given network. If subnetwork is not specified, the subnetwork with the
250- same name as the network will be used.` ,
300+ Engine subnetwork. If none is provided, "default" will be used.` ,
251301 },
252302 },
253303 },
304+ ConflictsWith : []string {"network_config" },
254305 },
255306 "scheduling_config" : {
256307 Type : schema .TypeList ,
@@ -500,6 +551,12 @@ func resourceTpuV2VmCreate(d *schema.ResourceData, meta interface{}) error {
500551 } else if v , ok := d .GetOkExists ("network_config" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (networkConfigProp )) && (ok || ! reflect .DeepEqual (v , networkConfigProp )) {
501552 obj ["networkConfig" ] = networkConfigProp
502553 }
554+ networkConfigsProp , err := expandTpuV2VmNetworkConfigs (d .Get ("network_configs" ), d , config )
555+ if err != nil {
556+ return err
557+ } else if v , ok := d .GetOkExists ("network_configs" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (networkConfigsProp )) && (ok || ! reflect .DeepEqual (v , networkConfigsProp )) {
558+ obj ["networkConfigs" ] = networkConfigsProp
559+ }
503560 serviceAccountProp , err := expandTpuV2VmServiceAccount (d .Get ("service_account" ), d , config )
504561 if err != nil {
505562 return err
@@ -679,6 +736,9 @@ func resourceTpuV2VmRead(d *schema.ResourceData, meta interface{}) error {
679736 if err := d .Set ("network_config" , flattenTpuV2VmNetworkConfig (res ["networkConfig" ], d , config )); err != nil {
680737 return fmt .Errorf ("Error reading Vm: %s" , err )
681738 }
739+ if err := d .Set ("network_configs" , flattenTpuV2VmNetworkConfigs (res ["networkConfigs" ], d , config )); err != nil {
740+ return fmt .Errorf ("Error reading Vm: %s" , err )
741+ }
682742 if err := d .Set ("service_account" , flattenTpuV2VmServiceAccount (res ["serviceAccount" ], d , config )); err != nil {
683743 return fmt .Errorf ("Error reading Vm: %s" , err )
684744 }
@@ -972,6 +1032,8 @@ func flattenTpuV2VmNetworkConfig(v interface{}, d *schema.ResourceData, config *
9721032 flattenTpuV2VmNetworkConfigEnableExternalIps (original ["enableExternalIps" ], d , config )
9731033 transformed ["can_ip_forward" ] =
9741034 flattenTpuV2VmNetworkConfigCanIpForward (original ["canIpForward" ], d , config )
1035+ transformed ["queue_count" ] =
1036+ flattenTpuV2VmNetworkConfigQueueCount (original ["queueCount" ], d , config )
9751037 return []interface {}{transformed }
9761038}
9771039func flattenTpuV2VmNetworkConfigNetwork (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
@@ -990,6 +1052,78 @@ func flattenTpuV2VmNetworkConfigCanIpForward(v interface{}, d *schema.ResourceDa
9901052 return v
9911053}
9921054
1055+ func flattenTpuV2VmNetworkConfigQueueCount (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1056+ // Handles the string fixed64 format
1057+ if strVal , ok := v .(string ); ok {
1058+ if intVal , err := tpgresource .StringToFixed64 (strVal ); err == nil {
1059+ return intVal
1060+ }
1061+ }
1062+
1063+ // number values are represented as float64
1064+ if floatVal , ok := v .(float64 ); ok {
1065+ intVal := int (floatVal )
1066+ return intVal
1067+ }
1068+
1069+ return v // let terraform core handle it otherwise
1070+ }
1071+
1072+ func flattenTpuV2VmNetworkConfigs (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1073+ if v == nil {
1074+ return v
1075+ }
1076+ l := v .([]interface {})
1077+ transformed := make ([]interface {}, 0 , len (l ))
1078+ for _ , raw := range l {
1079+ original := raw .(map [string ]interface {})
1080+ if len (original ) < 1 {
1081+ // Do not include empty json objects coming back from the api
1082+ continue
1083+ }
1084+ transformed = append (transformed , map [string ]interface {}{
1085+ "network" : flattenTpuV2VmNetworkConfigsNetwork (original ["network" ], d , config ),
1086+ "subnetwork" : flattenTpuV2VmNetworkConfigsSubnetwork (original ["subnetwork" ], d , config ),
1087+ "enable_external_ips" : flattenTpuV2VmNetworkConfigsEnableExternalIps (original ["enableExternalIps" ], d , config ),
1088+ "can_ip_forward" : flattenTpuV2VmNetworkConfigsCanIpForward (original ["canIpForward" ], d , config ),
1089+ "queue_count" : flattenTpuV2VmNetworkConfigsQueueCount (original ["queueCount" ], d , config ),
1090+ })
1091+ }
1092+ return transformed
1093+ }
1094+ func flattenTpuV2VmNetworkConfigsNetwork (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1095+ return v
1096+ }
1097+
1098+ func flattenTpuV2VmNetworkConfigsSubnetwork (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1099+ return v
1100+ }
1101+
1102+ func flattenTpuV2VmNetworkConfigsEnableExternalIps (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1103+ return v
1104+ }
1105+
1106+ func flattenTpuV2VmNetworkConfigsCanIpForward (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1107+ return v
1108+ }
1109+
1110+ func flattenTpuV2VmNetworkConfigsQueueCount (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1111+ // Handles the string fixed64 format
1112+ if strVal , ok := v .(string ); ok {
1113+ if intVal , err := tpgresource .StringToFixed64 (strVal ); err == nil {
1114+ return intVal
1115+ }
1116+ }
1117+
1118+ // number values are represented as float64
1119+ if floatVal , ok := v .(float64 ); ok {
1120+ intVal := int (floatVal )
1121+ return intVal
1122+ }
1123+
1124+ return v // let terraform core handle it otherwise
1125+ }
1126+
9931127func flattenTpuV2VmServiceAccount (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
9941128 if v == nil {
9951129 return nil
@@ -1321,6 +1455,13 @@ func expandTpuV2VmNetworkConfig(v interface{}, d tpgresource.TerraformResourceDa
13211455 transformed ["canIpForward" ] = transformedCanIpForward
13221456 }
13231457
1458+ transformedQueueCount , err := expandTpuV2VmNetworkConfigQueueCount (original ["queue_count" ], d , config )
1459+ if err != nil {
1460+ return nil , err
1461+ } else if val := reflect .ValueOf (transformedQueueCount ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
1462+ transformed ["queueCount" ] = transformedQueueCount
1463+ }
1464+
13241465 return transformed , nil
13251466}
13261467
@@ -1340,6 +1481,80 @@ func expandTpuV2VmNetworkConfigCanIpForward(v interface{}, d tpgresource.Terrafo
13401481 return v , nil
13411482}
13421483
1484+ func expandTpuV2VmNetworkConfigQueueCount (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1485+ return v , nil
1486+ }
1487+
1488+ func expandTpuV2VmNetworkConfigs (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1489+ l := v .([]interface {})
1490+ req := make ([]interface {}, 0 , len (l ))
1491+ for _ , raw := range l {
1492+ if raw == nil {
1493+ continue
1494+ }
1495+ original := raw .(map [string ]interface {})
1496+ transformed := make (map [string ]interface {})
1497+
1498+ transformedNetwork , err := expandTpuV2VmNetworkConfigsNetwork (original ["network" ], d , config )
1499+ if err != nil {
1500+ return nil , err
1501+ } else if val := reflect .ValueOf (transformedNetwork ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
1502+ transformed ["network" ] = transformedNetwork
1503+ }
1504+
1505+ transformedSubnetwork , err := expandTpuV2VmNetworkConfigsSubnetwork (original ["subnetwork" ], d , config )
1506+ if err != nil {
1507+ return nil , err
1508+ } else if val := reflect .ValueOf (transformedSubnetwork ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
1509+ transformed ["subnetwork" ] = transformedSubnetwork
1510+ }
1511+
1512+ transformedEnableExternalIps , err := expandTpuV2VmNetworkConfigsEnableExternalIps (original ["enable_external_ips" ], d , config )
1513+ if err != nil {
1514+ return nil , err
1515+ } else {
1516+ transformed ["enableExternalIps" ] = transformedEnableExternalIps
1517+ }
1518+
1519+ transformedCanIpForward , err := expandTpuV2VmNetworkConfigsCanIpForward (original ["can_ip_forward" ], d , config )
1520+ if err != nil {
1521+ return nil , err
1522+ } else {
1523+ transformed ["canIpForward" ] = transformedCanIpForward
1524+ }
1525+
1526+ transformedQueueCount , err := expandTpuV2VmNetworkConfigsQueueCount (original ["queue_count" ], d , config )
1527+ if err != nil {
1528+ return nil , err
1529+ } else if val := reflect .ValueOf (transformedQueueCount ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
1530+ transformed ["queueCount" ] = transformedQueueCount
1531+ }
1532+
1533+ req = append (req , transformed )
1534+ }
1535+ return req , nil
1536+ }
1537+
1538+ func expandTpuV2VmNetworkConfigsNetwork (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1539+ return v , nil
1540+ }
1541+
1542+ func expandTpuV2VmNetworkConfigsSubnetwork (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1543+ return v , nil
1544+ }
1545+
1546+ func expandTpuV2VmNetworkConfigsEnableExternalIps (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1547+ return v , nil
1548+ }
1549+
1550+ func expandTpuV2VmNetworkConfigsCanIpForward (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1551+ return v , nil
1552+ }
1553+
1554+ func expandTpuV2VmNetworkConfigsQueueCount (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1555+ return v , nil
1556+ }
1557+
13431558func expandTpuV2VmServiceAccount (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
13441559 l := v .([]interface {})
13451560 if len (l ) == 0 || l [0 ] == nil {
0 commit comments