Skip to content

Race condition when creating machines? #402

Closed
@abhinavdahiya

Description

@abhinavdahiya

Version Reports:

Distro version of host:

Fedora 28

Terraform Version Report

Terraform v0.11.8

Libvirt version

4.1.0

terraform-provider-libvirt plugin version (git-hash)

6c9b294


Description of Issue/Question

Setup

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

resource "libvirt_network" "tectonic_net" {
  name = "tectonic"

  mode   = "nat"
  bridge = "tt0"

  domain = "tt.testing"

  addresses = ["192.168.124.0/24"]

  dns = [{
    local_only = true
  }]

  autostart = true
}

locals {
  master_ips = ["192.168.124.11", "192.168.124.12"]
  worker_ips = ["192.168.124.51", "192.168.124.52"]
}

resource "libvirt_domain" "master" {
  count = "2"

  name = "master${count.index}"

  memory = "2048"
  vcpu   = "2"

  console {
    type        = "pty"
    target_port = 0
  }

  network_interface {
    network_id = "${libvirt_network.tectonic_net.id}"
    hostname   = "adahiya-master-${count.index}"
    addresses  = ["${local.master_ips[count.index]}"]
  }
}

resource "libvirt_domain" "worker" {
  count = "2"

  name   = "worker${count.index}"
  memory = "1024"
  vcpu   = "2"

  network_interface {
    network_id = "${libvirt_network.tectonic_net.id}"
    hostname   = "adahiya-worker-${count.index}"
    addresses  = ["${local.worker_ips[count.index]}"]
  }
}

Steps to Reproduce Issue

terraform init
terraform apply

Terraform should have created tectonic network, 2 master machines and 2 worker machines.

But terraform exists with error:

Error: Error applying plan:

2 error(s) occurred:

* libvirt_domain.worker[0]: 1 error(s) occurred:

* libvirt_domain.worker.0: Error creating libvirt domain: virError(Code=43, Domain=19, Message='Network not found: no network with matching name 'tectonic'')
* libvirt_domain.master[0]: 1 error(s) occurred:

* libvirt_domain.master.0: Error creating libvirt domain: virError(Code=43, Domain=19, Message='Network not found: no network with matching name 'tectonic'')

Complete output

Plan: 5 to add, 0 to change, 0 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: yes

libvirt_network.tectonic_net: Creating...
  addresses.#:      "" => "1"
  addresses.0:      "" => "192.168.124.0/24"
  autostart:        "" => "true"
  bridge:           "" => "tt0"
  dns.#:            "" => "1"
  dns.0.local_only: "" => "true"
  domain:           "" => "tt.testing"
  mode:             "" => "nat"
  name:             "" => "tectonic"
libvirt_network.tectonic_net: Creation complete after 5s (ID: 7bcaf736-3b2d-4509-ab1e-7680d6e17fbf)
libvirt_domain.worker[1]: Creating...
  arch:                             "" => "<computed>"
  emulator:                         "" => "<computed>"
  machine:                          "" => "<computed>"
  memory:                           "" => "1024"
  name:                             "" => "worker1"
  network_interface.#:              "" => "1"
  network_interface.0.addresses.#:  "" => "1"
  network_interface.0.addresses.0:  "" => "192.168.124.52"
  network_interface.0.hostname:     "" => "adahiya-worker-1"
  network_interface.0.mac:          "" => "<computed>"
  network_interface.0.network_id:   "" => "7bcaf736-3b2d-4509-ab1e-7680d6e17fbf"
  network_interface.0.network_name: "" => "<computed>"
  qemu_agent:                       "" => "false"
  running:                          "" => "true"
  vcpu:                             "" => "2"
libvirt_domain.worker[0]: Creating...
  arch:                             "" => "<computed>"
  emulator:                         "" => "<computed>"
  machine:                          "" => "<computed>"
  memory:                           "" => "1024"
  name:                             "" => "worker0"
  network_interface.#:              "" => "1"
  network_interface.0.addresses.#:  "" => "1"
  network_interface.0.addresses.0:  "" => "192.168.124.51"
  network_interface.0.hostname:     "" => "adahiya-worker-0"
  network_interface.0.mac:          "" => "<computed>"
  network_interface.0.network_id:   "" => "7bcaf736-3b2d-4509-ab1e-7680d6e17fbf"
  network_interface.0.network_name: "" => "<computed>"
  qemu_agent:                       "" => "false"
  running:                          "" => "true"
  vcpu:                             "" => "2"
libvirt_domain.master[1]: Creating...
  arch:                             "" => "<computed>"
  console.#:                        "" => "1"
  console.0.target_port:            "" => "0"
  console.0.type:                   "" => "pty"
  emulator:                         "" => "<computed>"
  machine:                          "" => "<computed>"
  memory:                           "" => "2048"
  name:                             "" => "master1"
  network_interface.#:              "" => "1"
  network_interface.0.addresses.#:  "" => "1"
  network_interface.0.addresses.0:  "" => "192.168.124.12"
  network_interface.0.hostname:     "" => "adahiya-master-1"
  network_interface.0.mac:          "" => "<computed>"
  network_interface.0.network_id:   "" => "7bcaf736-3b2d-4509-ab1e-7680d6e17fbf"
  network_interface.0.network_name: "" => "<computed>"
  qemu_agent:                       "" => "false"
  running:                          "" => "true"
  vcpu:                             "" => "2"
libvirt_domain.master[0]: Creating...
  arch:                             "" => "<computed>"
  console.#:                        "" => "1"
  console.0.target_port:            "" => "0"
  console.0.type:                   "" => "pty"
  emulator:                         "" => "<computed>"
  machine:                          "" => "<computed>"
  memory:                           "" => "2048"
  name:                             "" => "master0"
  network_interface.#:              "" => "1"
  network_interface.0.addresses.#:  "" => "1"
  network_interface.0.addresses.0:  "" => "192.168.124.11"
  network_interface.0.hostname:     "" => "adahiya-master-0"
  network_interface.0.mac:          "" => "<computed>"
  network_interface.0.network_id:   "" => "7bcaf736-3b2d-4509-ab1e-7680d6e17fbf"
  network_interface.0.network_name: "" => "<computed>"
  qemu_agent:                       "" => "false"
  running:                          "" => "true"
  vcpu:                             "" => "2"
libvirt_domain.worker[1]: Creation complete after 2s (ID: 72dae79b-dc84-4e3a-b6d0-65f478f53038)
libvirt_domain.master[1]: Creation complete after 2s (ID: ed8f694e-3c22-4d36-9e77-63187ee68ba1)

Error: Error applying plan:

2 error(s) occurred:

* libvirt_domain.worker[0]: 1 error(s) occurred:

* libvirt_domain.worker.0: Error creating libvirt domain: virError(Code=43, Domain=19, Message='Network not found: no network with matching name 'tectonic'')
* libvirt_domain.master[0]: 1 error(s) occurred:

* libvirt_domain.master.0: Error creating libvirt domain: virError(Code=43, Domain=19, Message='Network not found: no network with matching name 'tectonic'')

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    libvirt bugUpstream bugs in libvirt

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions