@@ -18,6 +18,7 @@ import (
1818 "fmt"
1919 "log"
2020 "reflect"
21+ "strconv"
2122 "time"
2223
2324 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -73,6 +74,14 @@ the user can explicitly connect subnetwork resources.`,
7374 ForceNew : true ,
7475 Description : `An optional description of this resource. The resource must be
7576recreated to modify this field.` ,
77+ },
78+ "mtu" : {
79+ Type : schema .TypeInt ,
80+ Computed : true ,
81+ Optional : true ,
82+ ForceNew : true ,
83+ Description : `Maximum Transmission Unit in bytes. The minimum value for this field is 1460
84+ and the maximum value is 1500 bytes.` ,
7685 },
7786 "routing_mode" : {
7887 Type : schema .TypeString ,
@@ -143,6 +152,12 @@ func resourceComputeNetworkCreate(d *schema.ResourceData, meta interface{}) erro
143152 } else if ! isEmptyValue (reflect .ValueOf (routingConfigProp )) {
144153 obj ["routingConfig" ] = routingConfigProp
145154 }
155+ mtuProp , err := expandComputeNetworkMtu (d .Get ("mtu" ), d , config )
156+ if err != nil {
157+ return err
158+ } else if v , ok := d .GetOkExists ("mtu" ); ! isEmptyValue (reflect .ValueOf (mtuProp )) && (ok || ! reflect .DeepEqual (v , mtuProp )) {
159+ obj ["mtu" ] = mtuProp
160+ }
146161
147162 url , err := replaceVars (d , config , "{{ComputeBasePath}}projects/{{project}}/global/networks" )
148163 if err != nil {
@@ -289,6 +304,9 @@ func resourceComputeNetworkRead(d *schema.ResourceData, meta interface{}) error
289304 }
290305 }
291306 }
307+ if err := d .Set ("mtu" , flattenComputeNetworkMtu (res ["mtu" ], d , config )); err != nil {
308+ return fmt .Errorf ("Error reading Network: %s" , err )
309+ }
292310 if err := d .Set ("self_link" , ConvertSelfLinkToV1 (res ["selfLink" ].(string ))); err != nil {
293311 return fmt .Errorf ("Error reading Network: %s" , err )
294312 }
@@ -458,6 +476,23 @@ func flattenComputeNetworkRoutingConfigRoutingMode(v interface{}, d *schema.Reso
458476 return v
459477}
460478
479+ func flattenComputeNetworkMtu (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
480+ // Handles the string fixed64 format
481+ if strVal , ok := v .(string ); ok {
482+ if intVal , err := strconv .ParseInt (strVal , 10 , 64 ); err == nil {
483+ return intVal
484+ }
485+ }
486+
487+ // number values are represented as float64
488+ if floatVal , ok := v .(float64 ); ok {
489+ intVal := int (floatVal )
490+ return intVal
491+ }
492+
493+ return v // let terraform core handle it otherwise
494+ }
495+
461496func expandComputeNetworkDescription (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
462497 return v , nil
463498}
@@ -485,3 +520,7 @@ func expandComputeNetworkRoutingConfig(v interface{}, d TerraformResourceData, c
485520func expandComputeNetworkRoutingConfigRoutingMode (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
486521 return v , nil
487522}
523+
524+ func expandComputeNetworkMtu (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
525+ return v , nil
526+ }
0 commit comments