Skip to content

Commit 9124946

Browse files
Merge pull request #19 from tuxillo/Remove-template-provider-usage
Remove references to the now deprecated template provider
2 parents cf01932 + ac6554d commit 9124946

File tree

4 files changed

+36
-34
lines changed

4 files changed

+36
-34
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ No modules.
3939
| [libvirt_domain.virt-machine](https://registry.terraform.io/providers/dmacvicar/libvirt/latest/docs/resources/domain) | resource |
4040
| [libvirt_volume.base-volume-qcow2](https://registry.terraform.io/providers/dmacvicar/libvirt/latest/docs/resources/volume) | resource |
4141
| [libvirt_volume.volume-qcow2](https://registry.terraform.io/providers/dmacvicar/libvirt/latest/docs/resources/volume) | resource |
42-
| [template_cloudinit_config.init_config](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/cloudinit_config) | data source |
43-
| [template_file.init_config](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file) | data source |
44-
| [template_file.network_config](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file) | data source |
42+
| [cloudinit_config.init_config](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/cloudinit_config) | data source |
4543

4644
## Inputs
4745

cloud_init.tf

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
1-
data "template_file" "network_config" {
2-
count = var.vm_count
3-
template = file("${path.module}/templates/network_config_${var.dhcp == true ? "dhcp" : "static"}.tpl")
4-
vars = {
5-
ip_address = element(var.ip_address, count.index)
6-
ip_gateway = var.ip_gateway
7-
ip_nameserver = var.ip_nameserver
8-
nic = (var.share_filesystem.source == null ? "ens3" : "ens4")
9-
# WA: If the shared filesystem is used, Libvirt connects Unclassified device to the 3rd position of PCI bus
10-
}
11-
}
12-
13-
data "template_file" "init_config" {
14-
count = var.vm_count
15-
template = file("${path.module}/templates/cloud_init.tpl")
16-
vars = {
17-
ssh_admin = var.ssh_admin
18-
ssh_keys = local.all_keys
19-
local_admin = var.local_admin
20-
local_admin_passwd = var.local_admin_passwd
21-
hostname = format("${var.vm_hostname_prefix}%02d", count.index + var.index_start)
22-
time_zone = var.time_zone
23-
runcmd = local.runcmd
24-
}
25-
}
26-
271
locals {
282
all_keys = <<EOT
293
[
@@ -39,14 +13,25 @@ EOT
3913
EOT
4014
}
4115

42-
data "template_cloudinit_config" "init_config" {
16+
data "cloudinit_config" "init_config" {
4317
count = var.vm_count
4418
gzip = false
4519
base64_encode = false
4620

4721
part {
4822
filename = format("init%02d.cfg", count.index + var.index_start)
4923
content_type = "text/cloud-config"
50-
content = data.template_file.init_config[count.index].rendered
24+
content = templatefile(
25+
"${path.module}/templates/cloud_init.tpl",
26+
{
27+
ssh_admin = var.ssh_admin
28+
ssh_keys = local.all_keys
29+
local_admin = var.local_admin
30+
local_admin_passwd = var.local_admin_passwd
31+
hostname = format("${var.vm_hostname_prefix}%02d", count.index + var.index_start)
32+
time_zone = var.time_zone
33+
runcmd = local.runcmd
34+
}
35+
)
5136
}
5237
}

main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
terraform {
32
required_version = ">= 0.13"
43
required_providers {

storage.tf

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,27 @@ resource "libvirt_volume" "volume-qcow2" {
2121
resource "libvirt_cloudinit_disk" "commoninit" {
2222
count = var.vm_count
2323
name = format("${var.vm_hostname_prefix}_init%02d.iso", count.index + 1)
24-
user_data = data.template_cloudinit_config.init_config[count.index].rendered
25-
network_config = data.template_file.network_config[count.index].rendered
24+
user_data = templatefile(
25+
"${path.module}/templates/cloud_init.tpl",
26+
{
27+
ssh_admin = var.ssh_admin
28+
ssh_keys = local.all_keys
29+
local_admin = var.local_admin
30+
local_admin_passwd = var.local_admin_passwd
31+
hostname = format("${var.vm_hostname_prefix}%02d", count.index + var.index_start)
32+
time_zone = var.time_zone
33+
runcmd = local.runcmd
34+
}
35+
)
36+
network_config = templatefile(
37+
"${path.module}/templates/network_config_${var.dhcp == true ? "dhcp" : "static"}.tpl",
38+
{
39+
ip_address = element(var.ip_address, count.index)
40+
ip_gateway = var.ip_gateway
41+
ip_nameserver = var.ip_nameserver
42+
nic = (var.share_filesystem.source == null ? "ens3" : "ens4")
43+
# WA: If the shared filesystem is used, Libvirt connects Unclassified device to the 3rd position of PCI bus
44+
}
45+
)
2646
pool = var.pool
2747
}

0 commit comments

Comments
 (0)