-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.tf
91 lines (82 loc) · 2.33 KB
/
example.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# see https://github.com/hashicorp/terraform
terraform {
required_version = "1.2.5"
required_providers {
# see https://registry.terraform.io/providers/hashicorp/random
random = {
source = "hashicorp/random"
version = "3.3.2"
}
# see https://registry.terraform.io/providers/dmacvicar/libvirt
# see https://github.com/dmacvicar/terraform-provider-libvirt
libvirt = {
source = "dmacvicar/libvirt"
version = "0.6.14"
}
# see https://registry.terraform.io/providers/rgl/sushy-vbmc
# see https://github.com/rgl/terraform-provider-sushy-vbmc
vbmc = {
source = "rgl/sushy-vbmc"
version = "0.2.0"
}
}
}
provider "libvirt" {
uri = "qemu:///system"
}
variable "prefix" {
default = "terraform_vbmc_example"
}
output "vm_ip" {
value = length(libvirt_domain.example.network_interface[0].addresses) > 0 ? libvirt_domain.example.network_interface[0].addresses[0] : ""
}
output "vbmc_port" {
value = vbmc_vbmc.example.port
}
output "vbmc_address" {
value = vbmc_vbmc.example.address
}
resource "vbmc_vbmc" "example" {
domain_id = libvirt_domain.example.id
port = 8000 # NB when port is unset, the port will be automatically allocated.
}
# see https://github.com/dmacvicar/terraform-provider-libvirt/blob/v0.6.14/website/docs/r/domain.html.markdown
resource "libvirt_domain" "example" {
name = var.prefix
cpu {
mode = "host-passthrough"
}
vcpu = 2
memory = 1024
qemu_agent = true
disk {
volume_id = libvirt_volume.example_root.id
scsi = true
}
network_interface {
network_id = libvirt_network.example.id
wait_for_lease = true
addresses = ["10.17.3.2"]
}
}
# this uses the vagrant ubuntu image imported from https://github.com/rgl/ubuntu-vagrant.
# see https://github.com/dmacvicar/terraform-provider-libvirt/blob/v0.6.14/website/docs/r/volume.html.markdown
resource "libvirt_volume" "example_root" {
name = "${var.prefix}_root.img"
base_volume_name = "ubuntu-20.04-amd64_vagrant_box_image_0_box.img"
format = "qcow2"
}
# see https://github.com/dmacvicar/terraform-provider-libvirt/blob/v0.6.14/website/docs/r/network.markdown
resource "libvirt_network" "example" {
name = var.prefix
mode = "nat"
domain = "example.test"
addresses = ["10.17.3.0/24"]
dhcp {
enabled = false
}
dns {
enabled = true
local_only = false
}
}