Skip to content

Commit

Permalink
Network: add mtu setting
Browse files Browse the repository at this point in the history
  • Loading branch information
squeed committed Dec 7, 2018
1 parent 2ad0228 commit 1b6aafd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
13 changes: 13 additions & 0 deletions libvirt/resource_libvirt_network.go
Expand Up @@ -69,6 +69,11 @@ func resourceLibvirtNetwork() *schema.Resource {
Computed: true,
ForceNew: true,
},
"mtu": {
Type: schema.TypeInt,
Optional: true,
Required: false,
},
"addresses": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -320,6 +325,10 @@ func resourceLibvirtNetworkCreate(d *schema.ResourceData, meta interface{}) erro
STP: "on",
}

if mtu, ok := d.GetOk("mtu"); ok {
networkDef.MTU = &libvirtxml.NetworkMTU{Size: uint(mtu.(int))}
}

// check the network mode
networkDef.Forward = &libvirtxml.NetworkForward{
Mode: strings.ToLower(d.Get("mode").(string)),
Expand Down Expand Up @@ -530,6 +539,10 @@ func resourceLibvirtNetworkRead(d *schema.ResourceData, meta interface{}) error
d.Set("name", networkDef.Name)
d.Set("bridge", networkDef.Bridge.Name)

if networkDef.MTU != nil {
d.Set("mtu", networkDef.MTU.Size)
}

// Domain as won't be present for bridged networks
if networkDef.Domain != nil {
d.Set("domain", networkDef.Domain.Name)
Expand Down
28 changes: 28 additions & 0 deletions libvirt/resource_libvirt_network_test.go
Expand Up @@ -551,3 +551,31 @@ func testAccCheckLibvirtNetworkDestroy(s *terraform.State) error {
}
return nil
}

func TestAccLibvirtNetwork_MTU(t *testing.T) {
var network libvirt.Network
randomNetworkResource := acctest.RandString(10)
randomNetworkName := acctest.RandString(10)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLibvirtNetworkDestroy,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
resource "libvirt_network" "%s" {
name = "%s"
mode = "nat"
domain = "k8s.local"
addresses = ["10.17.3.0/24"]
autostart = true
mtu = 9999
}`, randomNetworkResource, randomNetworkName),
Check: resource.ComposeTestCheckFunc(
networkExists("libvirt_network."+randomNetworkResource, &network),
resource.TestCheckResourceAttr("libvirt_network."+randomNetworkResource, "mtu", "9999"),
),
},
},
})
}
6 changes: 6 additions & 0 deletions website/docs/r/network.markdown
Expand Up @@ -34,6 +34,10 @@ resource "libvirt_network" "kube_network" {
# (only necessary in "bridge" mode)
# bridge = "br7"
# (optional) the MTU for the network. If not supplied, the underlying device's
# default is used (usually 1500)
# mtu = 9000
# (Optional) DNS configuration
dns {
# (Optional, default false)
Expand Down Expand Up @@ -102,6 +106,8 @@ The following arguments are supported:
* `bridge` - (Optional) The bridge device defines the name of a bridge
device which will be used to construct the virtual network (when not provided,
it will be automatically obtained by libvirt in `none`, `nat` and `route` modes).
* `mtu` - (Optional) The MTU to set for the underlying network interfaces. When
not supplied, libvirt will use the default for the interface, usually 1500.
* `autostart` - (Optional) Set to `true` to start the network on host boot up.
If not specified `false` is assumed.
* `dns` - (Optional) configuration of DNS specific settings for the network
Expand Down

0 comments on commit 1b6aafd

Please sign in to comment.