Ubuntu 18.04.2 LTS
Terraform v0.11.14
+ provider.libvirt (unversioned)
+ provider.template v2.1.2
./terraform-provider-libvirt 0.5.2
Compiled against library: libvirt 4.0.0
Using library: libvirt 4.0.0
virsh --version
5.1.0
[ ] Is your issue/contribution related with enabling some setting/option exposed by libvirt that the plugin does not yet support, or requires changing/extending the provider terraform schema?
[x] Is it a bug or something that does not work as expected? Please make sure you fill the version information below:
I am unable to create a terraform managed bridged network using an existing bridge. This is same issue as #364 which was fixed by #531.
main.tf
provider "libvirt" {
uri = "qemu+ssh://${var.kvm_host_user}@${var.kvm_hostname}/system"
}
resource "libvirt_network" "ovs_bridge_network" {
name = "ovs-vlan${var.vlan_id}-net"
mode = "bridge"
bridge = "${var.ovs_bridge_name}"
autostart = false
xml {
xslt = "${data.template_file.domain_xml_override.rendered}"
}
}
data "template_file" "domain_xml_override" {
template = "${file("${path.module}/ovsvlan.xsl")}"
vars = {
vlan_id = "${var.vlan_id}"
bridge_name = "${var.ovs_bridge_name}"
}
}
variables.tf
variable "kvm_hostname" {
description = "Hostname or IP of the provisioning system"
default = "myhost"
}
variable "kvm_host_user" {
description = "User for the provisioning system"
default = "myuser"
}
variable "ovs_bridge_name" {
description = "Name of the Open vSwitch bridge device on the host"
default = "ovsbr0"
}
variable "vlan_id" {
description = "VLAN_ID associated with this network"
default = "1234"
}
ovsvlan.xsl
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/domain/devices/interface[@type='bridge']/source[@bridge='${bridge_name}']">
<xsl:copy-of select="."/>
<xsl:element name="virtualport">
<xsl:attribute name="type">openvswitch</xsl:attribute>
</xsl:element>
<xsl:element name="vlan">
<tag id='${vlan_id}'/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
terraform init
terraform plan
terraform apply
Error:
Error: Error applying plan:
1 error occurred:
* libvirt_network.ovs_bridge_network: 1 error occurred:
* libvirt_network.ovs_bridge_network: Error clearing libvirt network: virError(Code=38, Domain=0, Message='error creating bridge interface ovsbr0: File exists')
The network is in fact created on the host:
virsh net-list --all
Name State Autostart Persistent
-------------------------------------------------------
default inactive no yes
ovs-vlan1234-net inactive no yes
As far as I can tell, I am running the latest supported plugin version (0.5.2) for terraform 0.11.
hi @muroj thx for issue.
the error you are facing, is a Libvirt error, not dependent of terraform-libvirt.
r(Code=38, Domain=0, Message='error creating bridge interface ovsbr0: File exists')
This might need investigation, on your host. You could try to remove/cleanup and retry.
You can think of the terraform-libvirt as a way to delegate action to libvirts but if these fails, we aren't responable ( for some of them yes).
Regarding this issue. I'm thinking that you are facing a host/issue regarding the bridge interface, for moment.
I might be wrong for sure. but we need to dive more on the error.
@MalloZup Thanks for quick response.
I can create the bridged network manually via virsh + xml and it works as expected.
<network>
<name>ovs-102-net</name>
<uuid>d5225cdc-0624-404b-a80e-5d6320079b91</uuid>
<forward mode='bridge'/>
<bridge name='ovsbr0'/>
<vlan>
<tag id='1299'/>
</vlan>
<virtualport type='openvswitch'/>
</network>
virsh net-define --file ovs-102-net.xml.bak
Network ovs-102-net defined from ovs-102-net.xml.bak
virsh net-start ovs-102-net
Network ovs-102-net started
virsh net-info ovs-102-net
Name: ovs-102-net
UUID: d5225cdc-0624-404b-a80e-5d6320079b91
Active: yes
Persistent: yes
Autostart: no
Bridge: ovsbr0
md5-61dd9c4eee7a1d810ab5f15e981388b6
2019-07-25 12:02:01.022+0000: 53527: debug : virThreadJobClear:119 : Thread 53527 (virNetServerHandleJob) finished job remoteDispatchConnectOpen with ret=0
2019-07-25 12:02:01.035+0000: 53526: debug : virThreadJobSet:94 : Thread 53526 (virNetServerHandleJob) is now running job remoteDispatchConnectSupportsFeature
2019-07-25 12:02:01.035+0000: 53526: debug : virThreadJobClear:119 : Thread 53526 (virNetServerHandleJob) finished job remoteDispatchConnectSupportsFeature with ret=0
2019-07-25 12:02:01.045+0000: 53528: debug : virThreadJobSet:94 : Thread 53528 (virNetServerHandleJob) is now running job remoteDispatchConnectSupportsFeature
2019-07-25 12:02:01.045+0000: 53528: debug : virThreadJobClear:119 : Thread 53528 (virNetServerHandleJob) finished job remoteDispatchConnectSupportsFeature with ret=0
2019-07-25 12:02:03.431+0000: 53524: debug : virThreadJobSet:94 : Thread 53524 (virNetServerHandleJob) is now running job remoteDispatchNetworkDefineXML
2019-07-25 12:02:03.431+0000: 53524: debug : virNetworkDefineXML:443 : conn=0x3ff90003240, xml=<network>
<name>ovs-vlan1299-net</name>
<bridge name="ovsbr0" stp="on"/>
</network>
2019-07-25 12:02:03.431+0000: 53524: debug : virFileMakePathHelper:3048 : path=/etc/libvirt/qemu/networks mode=0777
2019-07-25 12:02:03.432+0000: 53524: debug : virFileClose:113 : Closed fd 18
2019-07-25 12:02:03.432+0000: 53524: debug : virThreadJobClear:119 : Thread 53524 (virNetServerHandleJob) finished job remoteDispatchNetworkDefineXML with ret=0
2019-07-25 12:02:03.446+0000: 53525: debug : virThreadJobSet:94 : Thread 53525 (virNetServerHandleJob) is now running job remoteDispatchNetworkCreate
2019-07-25 12:02:03.446+0000: 53525: debug : virNetworkCreate:573 : network=0x3ff940031b0
2019-07-25 12:02:03.446+0000: 53525: debug : virFileClose:113 : Closed fd 18
2019-07-25 12:02:03.446+0000: 53525: debug : virNetlinkNewLink:514 : Creating bridge interface 'ovsbr0'
2019-07-25 12:02:03.446+0000: 53525: error : virNetDevBridgeCreate:415 : error creating bridge interface ovsbr0: File exists
2019-07-25 12:02:03.446+0000: 53525: debug : virThreadJobClear:119 : Thread 53525 (virNetServerHandleJob) finished job remoteDispatchNetworkCreate with ret=-1
2019-07-25 12:02:03.471+0000: 53523: error : virNetSocketReadWire:1803 : End of file while reading data: Input/output error
2019-07-25 12:02:03.471+0000: 53523: debug : virIdentitySetAttr:241 : ident=0x2aa3eab8670 attribute=4 value=53523
2019-07-25 12:02:03.471+0000: 53523: debug : virFileClose:113 : Closed fd 18
2019-07-25 12:02:03.471+0000: 53523: debug : virIdentitySetAttr:241 : ident=0x2aa3eab8670 attribute=5 value=136945684
2019-07-25 12:02:03.471+0000: 53523: debug : virIdentitySetAttr:241 : ident=0x2aa3eab8670 attribute=0 value=root
2019-07-25 12:02:03.471+0000: 53523: debug : virIdentitySetAttr:241 : ident=0x2aa3eab8670 attribute=1 value=0
2019-07-25 12:02:03.471+0000: 53523: debug : virIdentitySetAttr:241 : ident=0x2aa3eab8670 attribute=2 value=root
2019-07-25 12:02:03.471+0000: 53523: debug : virIdentitySetAttr:241 : ident=0x2aa3eab8670 attribute=3 value=0
2019-07-25 12:02:03.471+0000: 53523: debug : virConnectClose:1239 : conn=0x3ff90003240
2019-07-25 12:02:03.471+0000: 53523: debug : virConnectClose:1239 : conn=0x3ff90003240
I am experiencing the same issue. I can replicate it directly using virsh by running virsh net-create [path to xml]. If instead I run virsh net-define [path to xml] it works as expected.
Most helpful comment
@MalloZup Thanks for quick response.
I can create the bridged network manually via virsh + xml and it works as expected.