Skip to content

Commit

Permalink
Merge pull request dmacvicar#448 from MalloZup/docsmall
Browse files Browse the repository at this point in the history
Improve ubuntu example and some contributing doc
  • Loading branch information
MalloZup authored Oct 14, 2018
2 parents dc5fee5 + be093be commit 995435a
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 161 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ script:
- make gofmtcheck
- make vet
- golint -set_exit_status libvirt/
- travis/validate_terraform_files.sh
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@

* Use [commit.style](https://commit.style/) for git commit messages


## Some words about the design-architecture of this project:

Libvirt upstream use xml-schemas for defining the resources.

There is a common-pattern shared among the resources in this provider.

For example the `domain` resource, and others are organized like follow:

- the `domain_def` contains libvirt xml schemas and operation
- `resource_libvirt_domain.go` (contains terraform CRUD operations and call the libvirt_xml)
you can imagine the `resource` file as a sort of "main" file for each resource.
- `resource_libvirt_domain_test.go` ( contains testacc for resource)


## Running the tests (testacc)

```
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ Note: when using bridge network configurations you need to enable the `qemu_agen

Be aware that this variables may be subject to change again in future versions.

## Troubleshooting (aka you have a problem)

Have a look at [TROUBLESHOOTING](doc/TROUBLESHOOTING.md), and feel free to add a PR if you find out something is missing.

## Authors

* Duncan Mac-Vicar P. <dmacvicar@suse.de>
Expand Down
58 changes: 0 additions & 58 deletions doc/TROUBLESHOOTING.md

This file was deleted.

23 changes: 13 additions & 10 deletions examples/boot/libvirt.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,33 @@ provider "libvirt" {

// blank 10GB image for net install.
resource "libvirt_volume" "debian9-qcow2" {
name = "debian9-qcow2"
pool = "default"
name = "debian9-qcow2"
pool = "default"
format = "qcow2"
size = 10000000000
size = 10000000000
}

// set boot order hd, network
resource "libvirt_domain" "domain-debian9-qcow2" {
name = "debian9"
name = "debian9"
memory = "1024"
vcpu = 1
vcpu = 1

network_interface {
bridge = "br0"
mac = "52:54:00:b2:2f:86"
bridge = "br0"
mac = "52:54:00:b2:2f:86"
}

boot_device {
dev = [ "hd", "network"]
dev = ["hd", "network"]
}

disk {
volume_id = "${libvirt_volume.debian9-qcow2.id}"
volume_id = "${libvirt_volume.debian9-qcow2.id}"
}

graphics {
type = "vnc"
type = "vnc"
listen_type = "address"
}
}
12 changes: 7 additions & 5 deletions examples/count/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ provider "libvirt" {
}

resource "libvirt_volume" "os_image" {
name = "os_image"
name = "os_image"
source = "http://download.opensuse.org/repositories/Cloud:/Images:/Leap_42.3/images/openSUSE-Leap-42.3-OpenStack.x86_64.qcow2"
}

resource "libvirt_volume" "volume" {
name = "volume-${count.index}"
name = "volume-${count.index}"
base_volume_id = "${libvirt_volume.os_image.id}"
count = 4
count = 4
}

resource "libvirt_domain" "domain" {
name = "domain-${count.index}"

disk {
volume_id = "${element(libvirt_volume.volume.*.id, count.index)}"
volume_id = "${element(libvirt_volume.volume.*.id, count.index)}"
}

network_interface {
network_name = "default"
network_name = "default"
wait_for_lease = true
}

Expand Down
40 changes: 23 additions & 17 deletions examples/format/libvirt.tf
Original file line number Diff line number Diff line change
@@ -1,71 +1,77 @@
provider "libvirt" {
uri = "qemu:///system"
uri = "qemu:///system"
}

resource "libvirt_network" "tf" {
name = "tf"
domain = "tf.local"
mode = "nat"
addresses = ["10.0.100.0/24"]
name = "tf"
domain = "tf.local"
mode = "nat"
addresses = ["10.0.100.0/24"]
}

# raw image from file
resource "libvirt_volume" "debian8-raw" {
name = "debian8-raw"
name = "debian8-raw"
format = "raw"
source = "http://localhost:8000/debian8.img"
}

# qcow2 image from file
resource "libvirt_volume" "debian8-qcow2" {
name = "debian8-qcow2"
name = "debian8-qcow2"
source = "http://localhost:8000/debian8.qcow2"
}

# volume with raw backing storage
resource "libvirt_volume" "vol-debian8-raw" {
name = "vol-debian8-raw"
name = "vol-debian8-raw"
base_volume_id = "${libvirt_volume.debian8-raw.id}"
}

# volume with qcow2 backing storage
resource "libvirt_volume" "vol-debian8-qcow2" {
name = "vol-debian8-qcow2"
name = "vol-debian8-qcow2"
base_volume_id = "${libvirt_volume.debian8-qcow2.id}"
}

# domain using raw-backed volume
resource "libvirt_domain" "domain-debian8-raw" {
name = "domain-debian8-raw"
name = "domain-debian8-raw"
memory = "256"
vcpu = 1
vcpu = 1

network_interface {
network_name = "tf"
}

disk {
volume_id = "${libvirt_volume.vol-debian8-raw.id}"
}

graphics {
type = "spice"
type = "spice"
listen_type = "address"
autoport = true
autoport = true
}
}

# domain using qcow2-backed volume
resource "libvirt_domain" "domain-debian8-qcow2" {
name = "domain-debian8-qcow2"
name = "domain-debian8-qcow2"
memory = "256"
vcpu = 1
vcpu = 1

network_interface {
network_name = "tf"
}

disk {
volume_id = "${libvirt_volume.vol-debian8-qcow2.id}"
}

graphics {
type = "spice"
type = "spice"
listen_type = "address"
autoport = true
autoport = true
}
}
28 changes: 15 additions & 13 deletions examples/multiple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,40 @@ provider "libvirt" {

provider "libvirt" {
alias = "remotehost"
uri = "qemu+ssh://root@remotehost-p1.qa.suse.de/system"
uri = "qemu+ssh://root@remotehost-p1.qa.suse.de/system"
}

resource "libvirt_volume" "local-qcow2" {
name = "local-qcow2"
pool = "default"
name = "local-qcow2"
pool = "default"
format = "qcow2"
size = 100000
size = 100000
}

resource "libvirt_volume" "remotehost-qcow2" {
provider = "libvirt.remotehost"
name = "remotehost-qcow2"
pool = "default"
format = "qcow2"
size = 100000
name = "remotehost-qcow2"
pool = "default"
format = "qcow2"
size = 100000
}

resource "libvirt_domain" "local-domain" {
name = "local"
name = "local"
memory = "2048"
vcpu = 2
vcpu = 2

disk {
volume_id = "${libvirt_volume.local-qcow2.id}"
}
}

resource "libvirt_domain" "remotehost-domain" {
provider = "libvirt.remotehost"
name = "remotehost"
memory = "2048"
vcpu = 2
name = "remotehost"
memory = "2048"
vcpu = 2

disk {
volume_id = "${libvirt_volume.remotehost-qcow2.id}"
}
Expand Down
31 changes: 16 additions & 15 deletions examples/resize_base/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ provider "libvirt" {
}

resource "libvirt_volume" "os_image_ubuntu" {
name = "os_image_ubuntu"
pool = "default"
name = "os_image_ubuntu"
pool = "default"
source = "https://cloud-images.ubuntu.com/releases/xenial/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img"
}

resource "libvirt_volume" "disk_ubuntu_resized" {
name = "disk"
name = "disk"
base_volume_id = "${libvirt_volume.os_image_ubuntu.id}"
pool = "default"
size = 5361393152
pool = "default"
size = 5361393152
}

# Use CloudInit to add our ssh-key to the instance
resource "libvirt_cloudinit_disk" "cloudinit_ubuntu_resized" {
name = "cloudinit_ubuntu_resized.iso"
name = "cloudinit_ubuntu_resized.iso"
pool = "default"

user_data = <<EOF
#cloud-config
disable_root: 0
Expand All @@ -34,14 +35,14 @@ EOF
}

resource "libvirt_domain" "domain_ubuntu_resized" {
name = "doman_ubuntu_resized"
name = "doman_ubuntu_resized"
memory = "512"
vcpu = 1
vcpu = 1

cloudinit = "${libvirt_cloudinit_disk.cloudinit_ubuntu_resized.id}"

network_interface {
network_name = "default"
network_name = "default"
wait_for_lease = true
}

Expand All @@ -55,19 +56,19 @@ resource "libvirt_domain" "domain_ubuntu_resized" {
}

console {
type = "pty"
target_type = "virtio"
target_port = "1"
type = "pty"
target_type = "virtio"
target_port = "1"
}

disk {
volume_id = "${libvirt_volume.disk_ubuntu_resized.id}"
volume_id = "${libvirt_volume.disk_ubuntu_resized.id}"
}

graphics {
type = "spice"
type = "spice"
listen_type = "address"
autoport = true
autoport = true
}
}

Expand Down
Loading

0 comments on commit 995435a

Please sign in to comment.