@@ -18,6 +18,7 @@ import (
18
18
"fmt"
19
19
"log"
20
20
"reflect"
21
+ "strconv"
21
22
"time"
22
23
23
24
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -73,6 +74,14 @@ the user can explicitly connect subnetwork resources.`,
73
74
ForceNew : true ,
74
75
Description : `An optional description of this resource. The resource must be
75
76
recreated 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.` ,
76
85
},
77
86
"routing_mode" : {
78
87
Type : schema .TypeString ,
@@ -143,6 +152,12 @@ func resourceComputeNetworkCreate(d *schema.ResourceData, meta interface{}) erro
143
152
} else if ! isEmptyValue (reflect .ValueOf (routingConfigProp )) {
144
153
obj ["routingConfig" ] = routingConfigProp
145
154
}
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
+ }
146
161
147
162
url , err := replaceVars (d , config , "{{ComputeBasePath}}projects/{{project}}/global/networks" )
148
163
if err != nil {
@@ -289,6 +304,9 @@ func resourceComputeNetworkRead(d *schema.ResourceData, meta interface{}) error
289
304
}
290
305
}
291
306
}
307
+ if err := d .Set ("mtu" , flattenComputeNetworkMtu (res ["mtu" ], d , config )); err != nil {
308
+ return fmt .Errorf ("Error reading Network: %s" , err )
309
+ }
292
310
if err := d .Set ("self_link" , ConvertSelfLinkToV1 (res ["selfLink" ].(string ))); err != nil {
293
311
return fmt .Errorf ("Error reading Network: %s" , err )
294
312
}
@@ -458,6 +476,23 @@ func flattenComputeNetworkRoutingConfigRoutingMode(v interface{}, d *schema.Reso
458
476
return v
459
477
}
460
478
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
+
461
496
func expandComputeNetworkDescription (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
462
497
return v , nil
463
498
}
@@ -485,3 +520,7 @@ func expandComputeNetworkRoutingConfig(v interface{}, d TerraformResourceData, c
485
520
func expandComputeNetworkRoutingConfigRoutingMode (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
486
521
return v , nil
487
522
}
523
+
524
+ func expandComputeNetworkMtu (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
525
+ return v , nil
526
+ }
0 commit comments