Skip to content

Commit 9ea3f36

Browse files
Merge pull request #16 from chrodriguez/feature/runcmd
Add runcmd variable
2 parents 8eb2066 + 0fdfddc commit 9ea3f36

10 files changed

+29
-13
lines changed

.github/workflows/lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ jobs:
1010
- name: Check out code
1111
uses: actions/checkout@main
1212
- name: Terraform lint
13-
uses: devops-infra/action-tflint@master
13+
uses: devops-infra/action-tflint@master

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
tests
1+
tests

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ Do the changes in your own GitHub namespace.
2828
Please create a pull request into the `develop` branch. Here is [how to do it](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork).
2929

3030

31-
Please consider to [sponsor](https://github.com/sponsors/monolithprojects) me :smirk:
31+
Please consider to [sponsor](https://github.com/sponsors/monolithprojects) me :smirk:

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ No modules.
4747

4848
| Name | Description | Type | Default | Required |
4949
|------|-------------|------|---------|:--------:|
50+
| <a name="input_additional_disk_ids"></a> [additional\_disk\_ids](#input\_additional\_disk\_ids) | List of volume ids | `list` | `[]` | no |
5051
| <a name="input_autostart"></a> [autostart](#input\_autostart) | Autostart the domain | `bool` | `true` | no |
5152
| <a name="input_base_pool_name"></a> [base\_pool\_name](#input\_base\_pool\_name) | Name of base OS image | `any` | `null` | no |
5253
| <a name="input_base_volume_name"></a> [base\_volume\_name](#input\_base\_volume\_name) | Name of base OS image | `any` | `null` | no |
@@ -63,6 +64,7 @@ No modules.
6364
| <a name="input_memory"></a> [memory](#input\_memory) | RAM in MB | `string` | `"1024"` | no |
6465
| <a name="input_os_img_url"></a> [os\_img\_url](#input\_os\_img\_url) | URL to the OS image | `string` | `"https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img"` | no |
6566
| <a name="input_pool"></a> [pool](#input\_pool) | Storage pool name | `string` | `"default"` | no |
67+
| <a name="input_runcmd"></a> [runcmd](#input\_runcmd) | Extra commands to be run with cloud init | `list(string)` | <pre>[<br> "[ systemctl, daemon-reload ]",<br> "[ systemctl, enable, qemu-guest-agent ]",<br> "[ systemctl, start, qemu-guest-agent ]",<br> "[ systemctl, restart, systemd-networkd ]"<br>]</pre> | no |
6668
| <a name="input_share_filesystem"></a> [share\_filesystem](#input\_share\_filesystem) | n/a | <pre>object({<br> source = string<br> target = string<br> readonly = bool<br> mode = string<br> })</pre> | <pre>{<br> "mode": null,<br> "readonly": false,<br> "source": null,<br> "target": null<br>}</pre> | no |
6769
| <a name="input_ssh_admin"></a> [ssh\_admin](#input\_ssh\_admin) | Admin user with ssh access | `string` | `"ssh-admin"` | no |
6870
| <a name="input_ssh_keys"></a> [ssh\_keys](#input\_ssh\_keys) | List of public ssh keys | `list(string)` | `[]` | no |
@@ -228,7 +230,7 @@ module "vm" {
228230
additional_disk_ids = [ libvirt_volume.data_volume.id ]
229231
dhcp = true
230232
ssh_admin = "admin"
231-
ssh_keys = [
233+
ssh_keys = [
232234
chomp(file("~/.ssh/id_rsa.pub"))
233235
]
234236
time_zone = "America/Argentina/Buenos_Aires"

cloud_init.tf

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ data "template_file" "init_config" {
2020
local_admin_passwd = var.local_admin_passwd
2121
hostname = format("${var.vm_hostname_prefix}%02d", count.index + var.index_start)
2222
time_zone = var.time_zone
23+
runcmd = local.runcmd
2324
}
2425
}
2526

@@ -30,6 +31,11 @@ locals {
3031
"${keys}",
3132
%{~endfor~}
3233
]
34+
EOT
35+
runcmd = <<EOT
36+
%{for cmd in var.runcmd~}
37+
- ${cmd}
38+
%{endfor~}
3339
EOT
3440
}
3541

output.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ output "name" {
33
}
44
output "ip_address" {
55
value = libvirt_domain.virt-machine.*.network_interface.0.addresses.0
6-
}
6+
}

templates/cloud_init.tpl

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ packages:
88
- qemu-guest-agent
99

1010
runcmd:
11-
- [ systemctl, daemon-reload ]
12-
- [ systemctl, enable, qemu-guest-agent ]
13-
- [ systemctl, start, qemu-guest-agent ]
11+
${runcmd}
1412

1513
fqdn: ${hostname}
1614

@@ -73,4 +71,3 @@ growpart:
7371
resize_rootfs: true
7472

7573
timezone: ${time_zone}
76-

templates/network_config_dhcp.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
version: 2
22
ethernets:
33
${nic}:
4-
dhcp4: true
4+
dhcp4: true

templates/network_config_static.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ ethernets:
55
addresses: [${ip_address}/24]
66
gateway4: ${ip_gateway}
77
nameservers:
8-
addresses:
8+
addresses:
99
- ${ip_nameserver}
10-
- 8.8.8.8
10+
- 8.8.8.8

variables.tf

+12-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ variable "base_pool_name" {
1515

1616
variable "additional_disk_ids" {
1717
description = "List of volume ids"
18-
default = []
18+
default = []
1919
}
2020

2121

@@ -166,3 +166,14 @@ variable "ssh_private_key" {
166166
description = "Private key for SSH connection test"
167167
default = null
168168
}
169+
170+
variable "runcmd" {
171+
description = "Extra commands to be run with cloud init"
172+
type = list(string)
173+
default = [
174+
"[ systemctl, daemon-reload ]",
175+
"[ systemctl, enable, qemu-guest-agent ]",
176+
"[ systemctl, start, qemu-guest-agent ]",
177+
"[ systemctl, restart, systemd-networkd ]"
178+
]
179+
}

0 commit comments

Comments
 (0)