Skip to content

Commit

Permalink
Merge pull request #1 from Parsaloi/parsal
Browse files Browse the repository at this point in the history
separating configuration concerns
  • Loading branch information
parsaloian authored Jan 6, 2025
2 parents 4fc9245 + e0fae2f commit 5a36643
Show file tree
Hide file tree
Showing 19 changed files with 281 additions and 263 deletions.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
3 changes: 2 additions & 1 deletion provision-vm/kvm/using-terraform/src/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions provision-vm/kvm/using-terraform/src/compute.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
resource "libvirt_domain" "node0" {
name = var.domain_name
memory = var.memory_size

cpu {
mode = "host-passthrough"
}

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

firmware = "/usr/share/edk2/x64/OVMF_CODE.4m.fd"
nvram {
file = "/var/lib/libvirt/qemu/nvram/${var.domain_name}_VARS.fd"
template = "/usr/share/edk2/x64/OVMF_VARS.4m.fd"
}

machine = "q35"

disk {
volume_id = libvirt_volume.node0_disk.id
}

disk {
volume_id = libvirt_volume.arch_iso.id
}

network_interface {
network_id = libvirt_network.devsecops2.id
wait_for_lease = true
}

graphics {
type = "vnc"
listen_type = "address"
listen_address = "0.0.0.0"
autoport = true
}

video {
type = "virtio"
}

xml {
xslt = file("${path.module}/templates/ovmf_loader.xsl")
}

lifecycle {
ignore_changes = [
disk[1],
]
}
}
118 changes: 0 additions & 118 deletions provision-vm/kvm/using-terraform/src/libvirt.tf

This file was deleted.

10 changes: 1 addition & 9 deletions provision-vm/kvm/using-terraform/src/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
terraform {
required_providers {
libvirt = {
source = "dmacvicar/libvirt"
}
}
}

provider "libvirt" {
uri = "qemu:///system"
uri = var.libvirt_uri
}
16 changes: 16 additions & 0 deletions provision-vm/kvm/using-terraform/src/network.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
resource "libvirt_network" "devsecops2" {
name = "devsecops2"
mode = "nat"
domain = "devsecops2.local"
addresses = var.network_cidr
autostart = true

dhcp {
enabled = true
}

dns {
enabled = true
local_only = true
}
}
Empty file.
20 changes: 20 additions & 0 deletions provision-vm/kvm/using-terraform/src/storage.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "libvirt_pool" "sysimg" {
name = "sysimg"
type = "dir"
target {
path = "/var/lib/libvirt/images/more"
}
}

resource "libvirt_volume" "arch_iso" {
name = "archlinux-2024.08.01-x86_64.iso"
pool = libvirt_pool.sysimg.name
source = "/var/lib/libvirt/images/archlinux-2024.08.01-x86_64.iso"
}

resource "libvirt_volume" "node0_disk" {
name = "${var.domain_name}.qcow2"
pool = libvirt_pool.sysimg.name
size = var.disk_size * 1024 * 1024 * 1024
format = "qcow2"
}
15 changes: 15 additions & 0 deletions provision-vm/kvm/using-terraform/src/templates/ovmf_loader.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/domain/os">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<loader readonly="yes" type="pflash">/usr/share/ovmf/x64/OVMF_CODE.fd</loader>
<nvram>/var/lib/libvirt/qemu/nvram/node0_VARS.fd</nvram>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
135 changes: 3 additions & 132 deletions provision-vm/kvm/using-terraform/src/terraform.tfstate
Original file line number Diff line number Diff line change
@@ -1,138 +1,9 @@
{
"version": 4,
"terraform_version": "1.10.2",
"serial": 48,
"lineage": "00117a19-014b-c74c-b713-b6236d9670bf",
"serial": 56,
"lineage": "c6da0a51-4628-6462-35ee-3e2611ac5d35",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "libvirt_network",
"name": "devsecops2",
"provider": "provider[\"registry.terraform.io/dmacvicar/libvirt\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"addresses": [
"192.168.123.0/24",
"2001:db8:ca2:2::/64"
],
"autostart": true,
"bridge": "virbr1",
"dhcp": [
{
"enabled": true
}
],
"dns": [
{
"enabled": true,
"forwarders": [],
"hosts": [],
"local_only": true,
"srvs": []
}
],
"dnsmasq_options": [],
"domain": "devsecops2.local",
"id": "c9a5e234-a1d1-4f06-a9d4-7f32e2049fda",
"mode": "nat",
"mtu": null,
"name": "devsecops2",
"routes": [],
"xml": []
},
"sensitive_attributes": [],
"private": "bnVsbA=="
}
]
},
{
"mode": "managed",
"type": "libvirt_pool",
"name": "sysimg",
"provider": "provider[\"registry.terraform.io/dmacvicar/libvirt\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"allocation": 146588712960,
"available": 103257247744,
"capacity": 249845960704,
"id": "cd786730-9874-4a74-913c-cec7fe3b48d9",
"name": "sysimg",
"path": null,
"source": [],
"target": [
{
"path": "/var/lib/libvirt/images/more"
}
],
"type": "dir",
"xml": []
},
"sensitive_attributes": [],
"private": "bnVsbA=="
}
]
},
{
"mode": "managed",
"type": "libvirt_volume",
"name": "arch_iso",
"provider": "provider[\"registry.terraform.io/dmacvicar/libvirt\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"base_volume_id": null,
"base_volume_name": null,
"base_volume_pool": null,
"format": "iso",
"id": "/var/lib/libvirt/images/more/archlinux-2024.08.01-x86_64.iso",
"name": "archlinux-2024.08.01-x86_64.iso",
"pool": "sysimg",
"size": 1182826496,
"source": "/var/lib/libvirt/images/archlinux-2024.08.01-x86_64.iso",
"xml": []
},
"sensitive_attributes": [],
"private": "bnVsbA==",
"dependencies": [
"libvirt_pool.sysimg"
]
}
]
},
{
"mode": "managed",
"type": "libvirt_volume",
"name": "node0_disk",
"provider": "provider[\"registry.terraform.io/dmacvicar/libvirt\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"base_volume_id": null,
"base_volume_name": null,
"base_volume_pool": null,
"format": "qcow2",
"id": "/var/lib/libvirt/images/more/node0.qcow2",
"name": "node0.qcow2",
"pool": "sysimg",
"size": 32212254720,
"source": null,
"xml": []
},
"sensitive_attributes": [],
"private": "bnVsbA==",
"dependencies": [
"libvirt_pool.sysimg"
]
}
]
}
],
"resources": [],
"check_results": null
}
Loading

0 comments on commit 5a36643

Please sign in to comment.