@@ -90,6 +90,41 @@ func TestAccComputeNetwork_customSubnet(t *testing.T) {
90
90
})
91
91
}
92
92
93
+ func TestAccComputeNetwork_mtuAndUpdate (t * testing.T ) {
94
+ t .Parallel ()
95
+
96
+ var network compute.Network
97
+ suffixName := acctest .RandString (t , 10 )
98
+ networkName := fmt .Sprintf ("tf-test-network-routing-mode-%s" , suffixName )
99
+
100
+ acctest .VcrTest (t , resource.TestCase {
101
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
102
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
103
+ CheckDestroy : testAccCheckComputeNetworkDestroyProducer (t ),
104
+ Steps : []resource.TestStep {
105
+ {
106
+ Config : testAccComputeNetwork_mtu (networkName , 1460 ),
107
+ Check : resource .ComposeTestCheckFunc (
108
+ testAccCheckComputeNetworkExists (
109
+ t , "google_compute_network.acc_network_mtu" , & network ),
110
+ testAccCheckComputeNetworkHasMtu (
111
+ t , "google_compute_network.acc_network_mtu" , & network , 1460 ),
112
+ ),
113
+ },
114
+ // Test updating the mtu field from 1460 to 1500.
115
+ {
116
+ Config : testAccComputeNetwork_mtu (networkName , 1500 ),
117
+ Check : resource .ComposeTestCheckFunc (
118
+ testAccCheckComputeNetworkExists (
119
+ t , "google_compute_network.acc_network_mtu" , & network ),
120
+ testAccCheckComputeNetworkHasMtu (
121
+ t , "google_compute_network.acc_network_mtu" , & network , 1500 ),
122
+ ),
123
+ },
124
+ },
125
+ })
126
+ }
127
+
93
128
func TestAccComputeNetwork_routingModeAndUpdate (t * testing.T ) {
94
129
t .Parallel ()
95
130
@@ -537,6 +572,35 @@ func testAccCheckComputeNetworkIsCustomSubnet(t *testing.T, n string, network *c
537
572
}
538
573
}
539
574
575
+ func testAccCheckComputeNetworkHasMtu (t * testing.T , n string , network * compute.Network , mtu int32 ) resource.TestCheckFunc {
576
+ return func (s * terraform.State ) error {
577
+ config := acctest .GoogleProviderConfig (t )
578
+
579
+ rs , ok := s .RootModule ().Resources [n ]
580
+ if ! ok {
581
+ return fmt .Errorf ("Not found: %s" , n )
582
+ }
583
+
584
+ if rs .Primary .Attributes ["mtu" ] == "" {
585
+ return fmt .Errorf ("Routing mode not found on resource" )
586
+ }
587
+
588
+ found , err := config .NewComputeClient (config .UserAgent ).Networks .Get (
589
+ config .Project , network .Name ).Do ()
590
+ if err != nil {
591
+ return err
592
+ }
593
+
594
+ foundMtu := found .Mtu
595
+
596
+ if int64 (mtu ) != foundMtu {
597
+ return fmt .Errorf ("Expected mtu %d to match actual routing mode %d" , mtu , foundMtu )
598
+ }
599
+
600
+ return nil
601
+ }
602
+ }
603
+
540
604
func testAccCheckComputeNetworkHasRoutingMode (t * testing.T , n string , network * compute.Network , routingMode string ) resource.TestCheckFunc {
541
605
return func (s * terraform.State ) error {
542
606
config := acctest .GoogleProviderConfig (t )
@@ -651,6 +715,15 @@ resource "google_compute_network" "baz" {
651
715
` , networkName )
652
716
}
653
717
718
+ func testAccComputeNetwork_mtu (networkName string , mtu int32 ) string {
719
+ return fmt .Sprintf (`
720
+ resource "google_compute_network" "acc_network_mtu" {
721
+ name = "%s"
722
+ mtu = %d
723
+ }
724
+ ` , networkName , mtu )
725
+ }
726
+
654
727
func testAccComputeNetwork_routing_mode (networkName , routingMode string ) string {
655
728
return fmt .Sprintf (`
656
729
resource "google_compute_network" "acc_network_routing_mode" {
0 commit comments