aboutsummaryrefslogtreecommitdiff
path: root/examples/ubuntu
diff options
context:
space:
mode:
authorAndrew Paxson <andrew@fx-mind.com>2018-01-11 03:23:51 -0800
committerFlavio Castelli <flavio@castelli.me>2018-01-14 14:43:06 +0100
commit21c507a4c44b510196b8a4a527aca921e9cd9b11 (patch)
tree386a475ae25716bf4cc5e1af70183db136c7837d /examples/ubuntu
parent06ff26e5992f6e74ddf7fcb21fee0c34db13e257 (diff)
downloadterraform-provider-libvirt-21c507a4c44b510196b8a4a527aca921e9cd9b11.tar
terraform-provider-libvirt-21c507a4c44b510196b8a4a527aca921e9cd9b11.tar.gz
add an example for ubuntu
The Serial Console bug on ubuntu can be tough to find for people not used to the setup this example is just a nice example of creating a simple ubuntu instance from cloud images and passing in the ssh key.
Diffstat (limited to 'examples/ubuntu')
-rw-r--r--examples/ubuntu/ubuntu-example.tf68
1 files changed, 68 insertions, 0 deletions
diff --git a/examples/ubuntu/ubuntu-example.tf b/examples/ubuntu/ubuntu-example.tf
new file mode 100644
index 00000000..6b3b87fb
--- /dev/null
+++ b/examples/ubuntu/ubuntu-example.tf
@@ -0,0 +1,68 @@
+# instance the provider
+provider "libvirt" {
+ uri = "qemu:///system"
+}
+
+# We fetch the latest ubuntu release image from their mirrors
+resource "libvirt_volume" "ubuntu-qcow2" {
+ name = "ubuntu-qcow2"
+ pool = "default"
+ source = "https://cloud-images.ubuntu.com/releases/xenial/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img"
+ format = "qcow2"
+}
+
+# Create a network for our VMs
+resource "libvirt_network" "vm_network" {
+ name = "vm_network"
+ addresses = ["10.0.1.0/24"]
+}
+
+# Use CloudInit to add our ssh-key to the instance
+resource "libvirt_cloudinit" "commoninit" {
+ name = "commoninit.iso"
+ ssh_authorized_key = "<ssh-key-here>"
+ }
+
+
+# Create the machine
+resource "libvirt_domain" "domain-ubuntu" {
+ name = "ubuntu-terraform"
+ memory = "512"
+ vcpu = 1
+
+ cloudinit = "${libvirt_cloudinit.commoninit.id}"
+
+ network_interface {
+ network_name = "vm_network"
+ }
+
+ # IMPORTANT
+ # Ubuntu can hang is a isa-serial is not present at boot time.
+ # If you find your CPU 100% and never is available this is why
+ console {
+ type = "pty"
+ target_port = "0"
+ target_type = "serial"
+ }
+
+ console {
+ type = "pty"
+ target_type = "virtio"
+ target_port = "1"
+ }
+
+ disk {
+ volume_id = "${libvirt_volume.ubuntu-qcow2.id}"
+ }
+ graphics {
+ type = "spice"
+ listen_type = "address"
+ autoport = "yes"
+ }
+}
+
+# Print the Boxes IP
+# Note: you can use `virsh domifaddr <vm_name> <interface>` to get the ip later
+output "ip" {
+ value = "${libvirt_domain.domain-ubuntu.network_interface.0.addresses.0}"
+}