Skip to content

feat(vm): add install_guest_agent to inject qemu-guest-agent via cloud-init#174

Open
jniedergang wants to merge 1 commit intoharvester:masterfrom
jniedergang:upstream-guest-agent
Open

feat(vm): add install_guest_agent to inject qemu-guest-agent via cloud-init#174
jniedergang wants to merge 1 commit intoharvester:masterfrom
jniedergang:upstream-guest-agent

Conversation

@jniedergang
Copy link

@jniedergang jniedergang commented Mar 5, 2026

Related Issue

harvester/harvester#10141

Description

Add install_guest_agent boolean field to the harvester_virtualmachine resource that injects the qemu-guest-agent package and service enablement into cloud-init user_data, matching the Harvester UI "Install Guest Agent" checkbox behavior.

Changes

  • Add install_guest_agent schema field (bool, default false)
  • Add InstallGuestAgent field to Constructor, processed before CloudInit
  • Inject cloud-init snippet (package_update, packages, runcmd) into user_data when:
    • install_guest_agent = true
    • user_data_base64 and user_data_secret_name are not set
    • qemu-guest-agent is not already present in user_data
  • Import by detecting qemu-guest-agent in cloud-init volume UserData
  • Regenerate docs with make generate

Example

resource "harvester_virtualmachine" "example" {
  # ...
  install_guest_agent = true

  cloudinit {
    user_data = "#cloud-config\nuser: sles\n"
  }
}

The guest agent snippet is appended to the existing user_data.

Test plan

  • Unit tests: go test ./pkg/importer/ -run TestInstallGuestAgent — pass
  • go build ./... — compilation passes
  • gofmt -l . — no formatting issues
  • go generate ./... — docs generated
  • Functional test on Harvester v1.7.1:
    • Created VM with install_guest_agent = true — verified cloud-init user_data contains qemu-guest-agent package and systemctl enable --now qemu-guest-agent runcmd
    • Idempotence: terraform plan shows 0 changes
    • Toggle to install_guest_agent = false — cloud-init snippet removed
    • terraform destroy — VM cleaned up

…d-init

Add `install_guest_agent` boolean field that injects the qemu-guest-agent
package and service enablement into cloud-init user_data. The snippet is
only injected when user_data_base64 and user_data_secret_name are not set,
and when qemu-guest-agent is not already present in user_data.

- Add `install_guest_agent` schema field (bool, default false)
- Inject cloud-init snippet: package_update, packages, runcmd
- Import by detecting qemu-guest-agent in cloud-init volumes
- Unit tests for all detection cases (present, absent, base64)

Signed-off-by: Terraform Provider Developer <terraform@harvester.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant