Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow network updates (vs. recreate) where possible #468

Closed
wking opened this issue Nov 5, 2018 · 2 comments
Closed

Allow network updates (vs. recreate) where possible #468

wking opened this issue Nov 5, 2018 · 2 comments

Comments

@wking
Copy link
Contributor

wking commented Nov 5, 2018

Version Reports:

Terraform Version Report

$ terraform -v
Terraform v0.11.8

Your version of Terraform is out of date! The latest version
is 0.11.10. You can update by downloading from www.terraform.io/downloads.html

Provider and libvirt versions

$ ~/.terraform.d/plugins/terraform-provider-libvirt -version
/home/trking/.terraform.d/plugins/terraform-provider-libvirt 07d7ab44a1e6056c063a70e94db9352c3f54aa70
Compiled against library: libvirt 3.9.0
Using library: libvirt 3.9.0
Running hypervisor: QEMU 2.9.0
Running against daemon: 3.9.0

Description of Issue/Question

Setup

provider "libvirt" {
  uri = "qemu+tcp:///system"
}

variable "bootstrap_dns" {
  default     = true
}

resource "libvirt_network" "tectonic_net" {
  name      = "wking"
  mode      = "nat"
  bridge    = "tt0"
  domain    = "installer.testing"
  addresses = ["192.168.126.0/24"]

  dns = [{
    local_only = true

    hosts = ["${flatten(list(
      data.libvirt_network_dns_host_template.bootstrap.*.rendered,
    ))}"]
  }]

  autostart = true
}

data "libvirt_network_dns_host_template" "bootstrap" {
  count    = "${var.bootstrap_dns ? 1 : 0}"
  ip       = "192.168.126.10"
  hostname = "wking-api"
}

Steps to Reproduce Issue

$ terraform init
$ terraform apply -input=false
$ terraform apply -var bootstrap_dns=0
libvirt_network.tectonic_net: Refreshing state... (ID: 08a83d14-9bca-466e-9a1f-d5f54f8a94a2)

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

-/+ libvirt_network.tectonic_net (new resource required)
      id:                     "08a83d14-9bca-466e-9a1f-d5f54f8a94a2" => <computed> (forces new resource)
      addresses.#:            "1" => "1"
      addresses.0:            "192.168.126.0/24" => "192.168.126.0/24"
      autostart:              "true" => "true"
      bridge:                 "tt0" => "tt0"
      dns.#:                  "1" => "1"
      dns.0.hosts.#:          "1" => "0" (forces new resource)
      dns.0.hosts.0.hostname: "wking-api" => "" (forces new resource)
      dns.0.hosts.0.ip:       "192.168.126.10" => "" (forces new resource)
      dns.0.local_only:       "true" => "true"
      domain:                 "installer.testing" => "installer.testing"
      mode:                   "nat" => "nat"
      name:                   "wking" => "wking"


Plan: 1 to add, 0 to change, 1 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: no


Error: Apply cancelled.

Additional Infos:

Recreating the nework detaches associated interfaces:

Sometimes, one needs to edit the network definition and apply the changes on the fly. The most common scenario for this is adding new static MAC+IP mappings for the network's DHCP server. If you edit the network with "virsh net-edit", any changes you make won't take effect until the network is destroyed and re-started, which unfortunately will cause a all guests to lose network connectivity with the host until their network interfaces are explicitly re-attached.

Ideally we'd be updating the network in-place to remove the hosts entry (like virsh net-update), instead of deleting and recreating the network:

$ virsh -c qemu+tcp:///system net-dumpxml wking
<network>
  <name>wking</name>
  <uuid>08a83d14-9bca-466e-9a1f-d5f54f8a94a2</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='tt0' stp='on' delay='0'/>
  <mac address='52:54:00:c9:32:9f'/>
  <domain name='installer.testing' localOnly='yes'/>
  <dns>
    <host ip='192.168.126.10'>
      <hostname>wking-api</hostname>
    </host>
  </dns>
  <ip family='ipv4' address='192.168.126.1' prefix='24'>
  </ip>
</network>

$ virsh -c qemu+tcp:///system net-update wking delete dns-host '<host ip="192.168.126.10"><hostname>wking-api</hostname></host>'
Updated network wking live state
$ virsh -c qemu+tcp:///system net-dumpxml wking
<network>
  <name>wking</name>
  <uuid>08a83d14-9bca-466e-9a1f-d5f54f8a94a2</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='tt0' stp='on' delay='0'/>
  <mac address='52:54:00:c9:32:9f'/>
  <domain name='installer.testing' localOnly='yes'/>
  <ip family='ipv4' address='192.168.126.1' prefix='24'>
  </ip>
</network>
@MalloZup
Copy link
Collaborator

MalloZup commented Nov 5, 2018

#389

@wking
Copy link
Contributor Author

wking commented Nov 5, 2018

Dup of #389.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants