Skip to content

Commit

Permalink
Merge pull request #19 from tuxillo/Remove-template-provider-usage
Browse files Browse the repository at this point in the history
Remove references to the now deprecated template provider
  • Loading branch information
MonolithProjects authored Jan 29, 2023
2 parents cf01932 + ac6554d commit 9124946
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 34 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ No modules.
| [libvirt_domain.virt-machine](https://registry.terraform.io/providers/dmacvicar/libvirt/latest/docs/resources/domain) | resource |
| [libvirt_volume.base-volume-qcow2](https://registry.terraform.io/providers/dmacvicar/libvirt/latest/docs/resources/volume) | resource |
| [libvirt_volume.volume-qcow2](https://registry.terraform.io/providers/dmacvicar/libvirt/latest/docs/resources/volume) | resource |
| [template_cloudinit_config.init_config](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/cloudinit_config) | data source |
| [template_file.init_config](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file) | data source |
| [template_file.network_config](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file) | data source |
| [cloudinit_config.init_config](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/cloudinit_config) | data source |

## Inputs

Expand Down
41 changes: 13 additions & 28 deletions cloud_init.tf
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
data "template_file" "network_config" {
count = var.vm_count
template = file("${path.module}/templates/network_config_${var.dhcp == true ? "dhcp" : "static"}.tpl")
vars = {
ip_address = element(var.ip_address, count.index)
ip_gateway = var.ip_gateway
ip_nameserver = var.ip_nameserver
nic = (var.share_filesystem.source == null ? "ens3" : "ens4")
# WA: If the shared filesystem is used, Libvirt connects Unclassified device to the 3rd position of PCI bus
}
}

data "template_file" "init_config" {
count = var.vm_count
template = file("${path.module}/templates/cloud_init.tpl")
vars = {
ssh_admin = var.ssh_admin
ssh_keys = local.all_keys
local_admin = var.local_admin
local_admin_passwd = var.local_admin_passwd
hostname = format("${var.vm_hostname_prefix}%02d", count.index + var.index_start)
time_zone = var.time_zone
runcmd = local.runcmd
}
}

locals {
all_keys = <<EOT
[
Expand All @@ -39,14 +13,25 @@ EOT
EOT
}

data "template_cloudinit_config" "init_config" {
data "cloudinit_config" "init_config" {
count = var.vm_count
gzip = false
base64_encode = false

part {
filename = format("init%02d.cfg", count.index + var.index_start)
content_type = "text/cloud-config"
content = data.template_file.init_config[count.index].rendered
content = templatefile(
"${path.module}/templates/cloud_init.tpl",
{
ssh_admin = var.ssh_admin
ssh_keys = local.all_keys
local_admin = var.local_admin
local_admin_passwd = var.local_admin_passwd
hostname = format("${var.vm_hostname_prefix}%02d", count.index + var.index_start)
time_zone = var.time_zone
runcmd = local.runcmd
}
)
}
}
1 change: 0 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

terraform {
required_version = ">= 0.13"
required_providers {
Expand Down
24 changes: 22 additions & 2 deletions storage.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,27 @@ resource "libvirt_volume" "volume-qcow2" {
resource "libvirt_cloudinit_disk" "commoninit" {
count = var.vm_count
name = format("${var.vm_hostname_prefix}_init%02d.iso", count.index + 1)
user_data = data.template_cloudinit_config.init_config[count.index].rendered
network_config = data.template_file.network_config[count.index].rendered
user_data = templatefile(
"${path.module}/templates/cloud_init.tpl",
{
ssh_admin = var.ssh_admin
ssh_keys = local.all_keys
local_admin = var.local_admin
local_admin_passwd = var.local_admin_passwd
hostname = format("${var.vm_hostname_prefix}%02d", count.index + var.index_start)
time_zone = var.time_zone
runcmd = local.runcmd
}
)
network_config = templatefile(
"${path.module}/templates/network_config_${var.dhcp == true ? "dhcp" : "static"}.tpl",
{
ip_address = element(var.ip_address, count.index)
ip_gateway = var.ip_gateway
ip_nameserver = var.ip_nameserver
nic = (var.share_filesystem.source == null ? "ens3" : "ens4")
# WA: If the shared filesystem is used, Libvirt connects Unclassified device to the 3rd position of PCI bus
}
)
pool = var.pool
}

0 comments on commit 9124946

Please sign in to comment.